我是JSF的新手。
我的标签问题我的.jsp页面是这样的:
<h:form id="form1">
<t:inputHidden id="primaryKey"
value="#{EditConfigurationBean.primaryKey}" forceId="true" />
<t:inputHidden id="beanName"
value="#{EditConfigurationBean.beanName}" forceId="true" />
<t:dataTable id="datatable" value="#{EditConfigurationBean.config}" rowIndexVar="rowIndex" var="rowvar"
rowClasses="standardTable_Row1,standardTable_Row2"
columnClasses="standardTable_Column1,standardTable_Column2,standardTable_Column3">
<h:column>
<f:facet name="header">
<h:panelGroup>
<f:verbatim>
<object width="0px" height="0px"></object>
</f:verbatim>
<h:outputText
value="Entry Name" />
</h:panelGroup>
</f:facet>
<h:outputLabel value="#{rowvar.bean.name}"></h:outputLabel>
</h:column>
<t:column>
<f:facet name="header">
<h:panelGroup>
<f:verbatim>
<object width="0px" height="0px"></object>
</f:verbatim>
<h:outputText
value="Entry Value" />
</h:panelGroup>
</f:facet>
<h:inputText styleClass="inputText" value="#{rowvar.value}"></h:inputText>
</t:column>
</t:dataTable>
<t:htmlTag value="div" styleClass="commandBar">
<h:commandButton onmouseover="over(this)" onmouseout="out(this)" action="#{EditConfigurationBean.back}" id="navigation" immediate="true" value="back" styleClass="commandButton" />
<h:commandButton onmouseover="over(this)" onmouseout="out(this)" action="#{EditConfigurationBean.update}" value="Update" styleClass="commandButton" />
</t:htmlTag>
</h:form>
我的backbean代码是:
public class ConfigurationEditBean{
public String getInit(){
try {
config = loadConfig();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (config != null)
this.entriesCount =this.config.size();
return "";
}
private int primaryKey;
private java.lang.String beanName;
private int entriesCount;
private List<ConfigurationFullEntry> config;
public int getEntriesCount() {
return entriesCount;
}
public void setEntriesCount(int entriesCount) {
this.entriesCount = entriesCount;
}
public void setConfig(List<ConfigurationFullEntry> config) {
this.config = config;
}
public int getPrimaryKey() {
return primaryKey;
}
public void setPrimaryKey(int primaryKey) {
this.primaryKey = primaryKey;
}
public java.lang.String getBeanName() {
return beanName;
}
public void setBeanName(java.lang.String beanName) {
this.beanName = beanName;
}
private List<ConfigurationFullEntry> loadConfig() throws Exception{
List<ConfigurationFullEntry> entriesList = new ArrayList<ConfigurationFullEntry>();
//do load from DB
return entriesList;
}
public List<ConfigurationFullEntry> getConfig() {
return config;
}
public String update(){
return "";
}
public String back(){
return "";
}
}
问题是页面显示正确,但当我更改值为
时标记并提交表单,不调用backbean的相应setXXX。
当我在外面尝试了一个inputtext标签时
我的代码错了吗? 提前谢谢
更新:这是我生成的HTML,其中没有嵌套表单。:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><base href="http://localhost:7001"><title>My JSF 'ConfigurationEditor.jsp' starting page</title></head><body><form id="j_id_id2" name="j_id_id2" method="post" action="/HealthMonitorConsole/ConfigurationEditor.jsf" enctype="application/x-www-form-urlencoded"><input type="hidden" id="primaryKey" name="primaryKey" value="0"><input type="hidden" id="beanName" name="beanName" value="com.pardis.healthMonitor.dm.service.ServiceBean"> <table><thead><tr><th scope="col">Name</th><th scope="col">Value</th></tr></thead><tbody id="j_id_id2:j_id_id5:tbody_element"><tr><td>Server</td><td><input id="j_id_id2:j_id_id5:0:j_id_id13" name="j_id_id2:j_id_id5:0:j_id_id13" type="text" value=""></td></tr><tr><td>arash</td><td><input id="j_id_id2:j_id_id5:1:j_id_id13" name="j_id_id2:j_id_id5:1:j_id_id13" type="text" value=""></td></tr></tbody></table><br>
<input id="j_id_id2:j_id_id14" name="j_id_id2:j_id_id14" type="submit" value="Save" onclick="if(typeof window.getScrolling!='undefined'){oamSetHiddenInput('j_id_id2','autoScroll',getScrolling());}"> <input type="hidden" name="autoScroll"> <input type="hidden" name="j_id_id2_SUBMIT" value="1"><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="8EgC7hvJoXWgMHaUZxk5rx66APlnNueyP32ajDxbvc/i5akMf2jX5SQ5BLInRDoWgWvcMUADuXlYwCWVxYrNWghZBdlolM+1zLfQTh4aUm4="></form>
<script type="text/javascript"><!--
function getScrolling()
{
var x = 0; var y = 0;if (self.pageXOffset || self.pageYOffset)
{
x = self.pageXOffset;
y = self.pageYOffset;
}
else if ((document.documentElement && document.documentElement.scrollLeft)||(document.documentElement && document.documentElement.scrollTop))
{
x = document.documentElement.scrollLeft;
y = document.documentElement.scrollTop;
}
else if (document.body)
{
x = document.body.scrollLeft;
y = document.body.scrollTop;
}
return x + "," + y;
}
//--></script>
</body></html>
我正在编写教程示例等所有内容,但它不起作用!
答案 0 :(得分:0)
您需要确保在表单提交的应用请求值阶段保留与初始页面显示的呈现响应阶段期间完全相同的数据模型。一个正常的地方是预加载是辅助bean的构造函数。
public class Bean {
private List<Item> items;
public Bean() {
items = itemDAO.list();
}
// ...
}
另一种方法是将bean放在会话范围内,但这会对用户体验产生更大的影响。
由于您使用的是战斧,您也可以将preserveDataModel
的{{1}}属性设置为t:dataTable
,如下所示:
true
这将把数据模型存储在视图的组件树中(而后者又存储在会话范围中),以便在后续请求中提供完全相同的数据模型。