1

我在 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% 的请求大小。

这个问题有好的解决方案吗?

4

1 回答 1

1

render属性接受由空格分隔的多个组件 ID 字符串。您可以在属性中指定所需输入的组件 ID,render而不是整个@form.

您的视图标记无效(看起来您将 labelfor与 input混淆了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>     

Note that it accepts an EL expression as well. If this is a dynamically generated form and/or the ID and number of checkboxes are known beforehand in the bean, then you should be able to use something like:

    <f:ajax execute="@form" render="#{bean.allCheckboxIds}" />
于 2011-10-18T14:29:33.423 回答