【发布时间】:2015-01-04 14:25:51
【问题描述】:
我有两个输入 - 一个在“正常”h:dataTable 中,一个在 rich:dataTable 中它。见以下代码 sn-ps(输入任意值并按下按钮):
托管豆
@ManagedBean
@ViewScoped
public class TestController implements Serializable {
private static final long serialVersionUID = -484022507596298941L;
private String[] stringArray1 = {"Element 1", "Element 2"}; // + Getter
private String[] stringArray2 = {"Element A", "Element B"}; // + Getter
private Map<String, String> inputValues = new HashMap<String, String>(4); // + Getter
public TestController() {
inputValues.put(stringArray1[0], "");
inputValues.put(stringArray1[1], "");
inputValues.put(stringArray2[0], "");
inputValues.put(stringArray2[1], "");
}
public void doSomething() {
System.out.println("Did something");
}
public void validate(FacesContext facesContext, UIComponent uiComponent, Object value) {
throw new ValidatorException(new FacesMessage("This can never be valid."));
}
}
查看
<h:form>
<h1>h:dataTable</h1>
<h:dataTable id="table1" value="#{testController.stringArray1}" var="string" columnClasses="inactive">
<h:column>
<h:outputText value="#{string}:"/>
<h:inputText id="someInput" value="#{testController.inputValues[string]}" validator="#{testController.validate}"/>
<h:message for="someInput" id="msg" style="color: red;"/>
</h:column>
</h:dataTable>
<h1>rich:dataTable</h1>
<rich:dataTable id="table2" value="#{testController.stringArray2}" var="string">
<rich:column>
<h:outputText value="#{string}:"/>
<h:inputText id="someInput" value="#{testController.inputValues[string]}" validator="#{testController.validate}"/>
<h:message for="someInput" id="msg" style="color: red;"/>
</rich:column>
</rich:dataTable>
<h:commandButton id="button" action="#{testController.doSomething}" value="do something"/>
</h:form>
这是已知的 Richfaces 行为还是某种错误?有没有办法让它的行为与普通的 JSF-DataTable 一样?改用 h:dataTable 并不总是一种选择,而且丢失“我只是想更正它”的输入是相当烦人的。
补充: 我刚刚检查了 ui:repeat 和 a4j:repeat 的行为,它是一样的:ui:repeat 保留提交的值,而 a4j:repeat 没有。
更新:重新编写示例代码以排除 cmets 中提到的一些可能的问题(输入字段现在指向不同的值;只有一个表单元素)。
在 Mojarra 2.1.21 上使用 RichFaces 4.3.7 和 JBoss AS 7 以及在 Mojarra 2.2.7 上使用 RichFaces 4.5.0 Alpha3 和 JBoss Wildlfy 进行测试 - 结果相同。
【问题讨论】:
-
你是这样用的吗?同一页面中有两个表单?
-
是的,一个用于一般导航,一个用于用户提供的输入。
标签: validation jsf datatable richfaces