JSF - Select RadioButton and Invisible Output Text

I have a switch and the output text on my xhtml page.

I want the outputText to be visible when I select the switch, and the OutputText will be invisible when I deselect the switch.

What is a visible / invisible tag? and how to use it?

Somebody knows?

thank

+3
source share
1 answer

You can check the value of the switch in the renderedparent attribute of the output text. You can use the <f:ajax>switch group inside to update the parent text of the output each time the switch is changed.

Kickoff example:

<h:form id="form">
    <h:selectOneRadio value="#{bean.radio}">
        <f:selectItem itemValue="one" itemLabel="This should hide output text" />
        <f:selectItem itemValue="two" itemLabel="This should show output text" />
        <f:ajax render="output" />
    </h:selectOneRadio>
    <h:panelGroup id="output">
        <h:outputText value="output text" rendered="#{bean.radio == 'two'}" />
    </h:panelGroup>
</h:form>

, id , ajax render , .


, , -, , , . JavaScript.

<h:form id="form">
    <h:selectOneRadio value="#{bean.radio}" onclick="document.getElementById('form:output').style.display = (value == 'two' ? 'block' : 'none')">
        <f:selectItem itemValue="one" itemLabel="This should hide output text" />
        <f:selectItem itemValue="two" itemLabel="This should show output text" />
    </h:selectOneRadio>
    <h:outputText id="output" value="output text" style="display: #{bean.radio == 'two' ? 'block' : 'none'}" />
</h:form>
+2

All Articles