我想在用户选择特定单选按钮时切换隐藏面板。使用最新版本的素数。
例如:
<p:panel id="panel1" visible="false" widgetVar="firePanel" closable="true" toggleable="true">
hello
</p:panel>
<p:selectOneRadio value="#{formBean.selectedOptions}" layout="pageDirection">
<f:selectItem itemLabel="Option 1" itemValue="opt1" />
<f:selectItem itemLabel="Option 2" itemValue="opt2" />
<f:selectItem itemLabel="Option 3" itemValue="opt"/>
</p:selectOneRadio>
我想实现这样的事情,但是当单击单选按钮3时,不使用命令按钮
<p:commandButton id="but" value="Show" onclick="firePanel.show();"/>
这可能吗?谢谢!
执行以下步骤:
-
在后备 Bean 中声明一个
boolean
变量来管理面板的状态,并将其绑定到面板的visible
属性boolean panelIsVisible; //getter and setter
<p:panel id="panel1" visible="#{formBean.panelIsVisible}" widgetVar="firePanel" closable="true" toggleable="true">
-
定义一个方法,以根据
selectedOptions
的值切换可见性布尔值public void changePanelState(){ //set panelIsVisible to true or false based on whatever conditions you choose }
-
将
<p:ajax/>
事件添加到<p:selectOneRadio/>
,以在该菜单上的任何选择上触发 ajax 事件<p:selectOneRadio value="#{formBean.selectedOptions}" layout="pageDirection"> <f:selectItem itemLabel="Option 1" itemValue="opt1" /> <f:selectItem itemLabel="Option 2" itemValue="opt2" /> <f:selectItem itemLabel="Option 3" itemValue="opt"/> <p:ajax listener="#{formBean.changePanelState}" update="panel1"/> </p:selectOneRadio>
这是假设
panel1
与selectOneRadio处于同一<h:form/>
。