我是 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>
我正在编写教程示例之类的所有内容,但它不起作用!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web
技术交流群。
我是 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>
我正在编写教程示例之类的所有内容,但它不起作用!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要确保在表单提交的应用请求值阶段保留与初始页面显示的渲染响应阶段完全相同的数据模型。一个正常的地方是在 backing bean 的构造函数中进行预加载。
另一种方法是将bean放在会话范围内,但这对用户体验影响更大。
由于您使用的是 Tomahawk,您还可以将
t:dataTable
的preserveDataModel
属性设置为true
,如下所示:这将存储视图组件树中的数据模型(又存储在会话范围中),以便在后续请求中可以使用完全相同的数据模型。
另请参阅:
You need to ensure that exactly the same datamodel is preserved during the apply request values phase of the form submit as it was during the render response phase of the initial page display. A normal place is to do the preloading is the constructor of the backing bean.
An alternative is to put the bean in the session scope, but this has more impact on user experience.
Since you're using Tomahawk, you can also just set the
preserveDataModel
attribute of thet:dataTable
totrue
like so:This will store the datamodel in the view's component tree (which in turn is stored in the session scope) so that exactly the same datamodel is available in the subsequent request.
See also: