题
我在JSF 2.0中有很多文本(标签)和复选框的表格。文本在提交时永远不会更新,但是复选框值确实如此。
例如:
<h:form>
<h:outputLabel value="bla bla bla bla .. X 1000" id="lab1">
<h:selectBooleanCheckbox for="lab1">
<h:outputLabel value="bla bla bla bla .. X 1000" id="lab2">
<h:selectBooleanCheckbox for="lab2">
.... many more labels and checkboxes ...
<h:commandButton>
<f:ajax render="@form" execute="@form" />
</h:commandButton>
</h:form>
问题是,每当我提交时,整个表单内容都会被重新渲染。我只想重新渲染复选框值。这可以节省要求大小的90%。
有一个很好的解决方案解决这个问题吗?
解决方案
这 render
属性接受多个组件ID的空间分离字符串。您可以指定所需输入的组件ID render
属性而不是整体 @form
.
您的视图标记无效(看起来像您混淆的标签 for
使用输入 id
),但是到了,应该看起来像这样:
<h:outputLabel value="bla bla bla bla .. X 1000" for="lab1">
<h:selectBooleanCheckbox id="lab1">
<h:outputLabel value="bla bla bla bla .. X 1000" for="lab2">
<h:selectBooleanCheckbox id="lab2">
.... many more labels and checkboxes ...
<h:commandButton>
<f:ajax execute="@form" render="lab1 lab2 lab3 lab4 ..." />
</h:commandButton>
请注意,它也接受EL表达。如果这是一个动态生成的表单和/或复选框的ID和数量,则在BEAN中已知,则应该能够使用以下内容:
<f:ajax execute="@form" render="#{bean.allCheckboxIds}" />
不隶属于 StackOverflow