ui中的复选框:重复不被Ajax刷新

时间:2011-11-13 13:06:08

标签: jsf-2 facelets composite-component uirepeat

我使用Mojarra 2.1.3。

当用户点击“刷新不工作”按钮时,它会刷新ui:repeat的内容。我希望检查复选框,就像在初始化时一样。

我发现了什么:如果我删除h:head in 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>

onlyCheckbox和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>

和支持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 个答案:

答案 0 :(得分:5)

即使是最新的Mojarra 2.1.4,我也能重现你的问题。如果复选框不在复合内,它可以正常工作。这是Mojarra的<ui:repeat>中的一个错误。在Mojarra是totally broken。它在MyFaces 2.1.3上完全正常。

您有两个选择:

  • 用MyFaces取代Mojarra。
  • 使用UIData组件代替<ui:repeat>,例如<h:dataTable><t:dataList><p:dataList>