Checkbox inside ui:repeat not refreshed by Ajax

雨燕双飞 提交于 2019-12-08 01:26:17

问题


I work with Mojarra 2.1.3.

When the user click on button "refresh don't work", it refresh the content of the ui:repeat.I expect the checkbox to be checked, just as at the initialization.

What I've found: If I remove h:head in the facelet "refresh don't work" works... Any idea ?

The facelet:

<h:head></h:head>
<h:body>
<h:form id="myForm" >
<h:panelGroup id="panelToRefreshOutsideRepeat">
  <ui:repeat value="#{sandbox.columns}" var="column">
     <h:panelGroup id="panelToRefreshInsideRepeat">
     <h2>composite onlyCheckbox:</h2>
     <trc:onlyCheckbox value="#{column.value}" />
     <br />
     <h2>composite onlyInputText:</h2>
     <trc:onlyInputText value="#{column.value}" />
     <br />
     <br/>
     <h:commandButton  value="Refresh don't work" >
        <f:ajax render="panelToRefreshInsideRepeat" />
     </h:commandButton>
     <h:commandButton  value="Refresh work" >
        <f:ajax render=":myForm:panelToRefreshOutsideRepeat" />
     </h:commandButton>
     </h:panelGroup>
     <br/> 
  </ui:repeat>
</h:panelGroup>

The composite for onlyCheckbox and onlyInputText:

<composite:interface>
<composite:attribute name="value" 
                     type="boolean"/> 
</composite:interface>
<composite:implementation>
boolean: <h:selectBooleanCheckbox value="#{cc.attrs.value}" />
<!-- for onlyInputText h:inputText instead of h:selectBooleanCheckbox -->
boolean value: #{cc.attrs.value}
</composite:implementation>

and the backing bean:

@ManagedBean
@RequestScoped
public class Sandbox {
    public List<Column> columns = Arrays.asList(new Column(true));

    public List<Column> getColumns() {
      return columns;
    }        
    public void setColumns(List<Column> columns) {
    this.columns = columns;
    }

    public class Column {
       private boolean value;
       public Column(boolean value) {
          this.value = value;
       }
       public void setValue(boolean value) {
          this.value = value;
       }
       public boolean getValue() {
          return this.value;
       }
    }
}

回答1:


I can reproduce your problem even on latest Mojarra 2.1.4. It works fine if the checkbox is not inside a composite. This is a bug in Mojarra's <ui:repeat>. It is totally broken in Mojarra. It works perfectly fine on MyFaces 2.1.3.

You have 2 options:

  • Replace Mojarra by MyFaces.
  • Use an UIData component instead of <ui:repeat>, e.g. <h:dataTable>, <t:dataList>, <p:dataList>, etc.


来源:https://stackoverflow.com/questions/8111723/checkbox-inside-uirepeat-not-refreshed-by-ajax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!