2013-05-22 38 views
0

我有两个复选框。有条件地呈现p:selectOneRadio根据选中的值p:selectManyCheckbox

<h:panelGrid id="userActivationGridcheckbox"> 
    <p:selectManyCheckbox value="#{user.activationModecheckbox}" layout="pageDirection"> 
     <f:selectItem itemLabel="Account Expiration(in days)" itemValue="byEmailcheckbox" /> 
     <f:selectItem itemLabel="Reset User Password" itemValue="byAdmincheckbox" /> 
     <f:ajax event="change" render="userActivationGridcheckbox" /> 
    </p:selectManyCheckbox> 

    <h:panelGrid id="manualActivationGridcheckbox" rendered="#{user.manualActivationcheckbox}" columns="2"> 
     <p:selectOneRadio value="#{user.activationModecheckbox}" layout="pageDirection"> 
      <f:selectItem itemLabel="label1" itemValue="value1" /> 
      <f:selectItem itemLabel="label2" itemValue="value2" /> 
      <h:outputLabel>label</h:outputLabel> 
      <h:inputText value="" /> 
     </p:selectOneRadio> 
    </h:panelGrid> 
</h:panelGrid> 

当第一个复选框被选中时,则会出现2个单选按钮。当第二个复选框没有被选中时,单选按钮不应该出现。我怎样才能做到这一点?

+0

需要看到你的bean的代码,以帮助您 –

+0

这不是有效的把标签和输入字段作为'的孩子'。你究竟在那里尝试什么?在未来的问题中,请自行消除代码噪声,以便在完全空白的游乐场项目中以尽可能最小的代码来代码,这些代码仍然可以为您(也就是我们)解决问题。 – BalusC

回答

0

你需要一些监听方法来决定是否将无线电集团展示给用户,例如,通过保持一个布尔值在后台bean。然后通过AJAX渲染组件。

用法示例:

的观点:

<h:form> 
    <p:selectManyCheckbox id="check" value="#{bean.options}"> 
     <p:ajax process="@this" update="radio" listener="#{bean.listener}" /> 
     <f:selectItem itemLabel="Option 1" itemValue="Option 1" /> 
     <f:selectItem itemLabel="Option 2" itemValue="Option 2" /> 
    </p:selectManyCheckbox> 
    <h:panelGroup id="radio" layout="block"> 
     <h:panelGrid rendered="#{bean.needsSuboptions}" columns="2"> 
      <p:selectOneRadio value="#{bean.suboption1}" layout="pageDirection" > 
       <f:selectItem itemLabel="Select ---" itemValue="" /> 
       <f:selectItem itemLabel="Suboption 1-1" itemValue="Suboption 1-1" /> 
       <f:selectItem itemLabel="Suboption 1-2" itemValue="Suboption 1-2" /> 
      </p:selectOneRadio> 
      <p:selectOneRadio value="#{bean.suboption2}" layout="pageDirection" > 
       <f:selectItem itemLabel="Select ---" itemValue="" /> 
       <f:selectItem itemLabel="Suboption 2-1" itemValue="Suboption 2-1" /> 
       <f:selectItem itemLabel="Suboption 2-2" itemValue="Suboption 2-2" /> 
      </p:selectOneRadio> 
     </h:panelGrid> 
    </h:panelGroup> 
</h:form> 

和bean:

List<String> options;//getter+setter 
String suboption1;//getter+setter 
String suboption2;//getter+setter 
boolean needsSuboptions = false;//getter 

public void listener() { 
    needsSuboptions = options.contains("Option 1"); 
} 
0

你也可以做F:阿贾克斯skuntsel提供的代码。

<f:ajax render="" execute="" listener=""/> 

映射到:

<p:ajax update="" process="" listener=""/> 


<p:selectManyCheckbox id="check" value="#{displayPanel.options}"> 
      <f:ajax event="change" render="radio" listener="#{displayPanel.listener}" /> 
      <f:selectItem itemLabel="Option 1" itemValue="Option 1" /> 
      <f:selectItem itemLabel="Option 2" itemValue="Option 2" /> 
     </p:selectManyCheckbox> 
     <h:panelGroup id="radio" layout="block"> 
      <h:panelGrid rendered="#{displayPanel.n}" columns="2"> 
       <p:selectOneRadio value="#{displayPanel.a}" layout="pageDirection"> 
        <f:selectItem itemLabel="Select ---" itemValue="" /> 
        <f:selectItem itemLabel="Suboption 1-1" itemValue="Suboption 1-1" /> 
        <f:selectItem itemLabel="Suboption 1-2" itemValue="Suboption 1-2" /> 
       </p:selectOneRadio> 
       <p:selectOneRadio value="#{displayPanel.b}" layout="pageDirection"> 
        <f:selectItem itemLabel="Select ---" itemValue="" /> 
        <f:selectItem itemLabel="Suboption 2-1" itemValue="Suboption 2-1" /> 
        <f:selectItem itemLabel="Suboption 2-2" itemValue="Suboption 2-2" /> 
       </p:selectOneRadio> 
      </h:panelGrid> 

您忘记f的提供监听器:阿贾克斯。