Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
152
rated 0 times [  154] [ 2]  / answers: 1 / hits: 24421  / 14 Years ago, mon, september 13, 2010, 12:00:00

I am using JSF2 and Java to build a web application. I want to build a form like the one at the picture below:



alt



When somebody unchecks the checkbox the form should disappear:
alt



Here is an example with gwt.






So far,
I tried some stuff with the <f:ajax> tag and an PropertyActionListener in the managedBean but it didn't work. Can somebody give me an example or at least some hints to accomplish my goal. I would be really thankfull


More From » jsf

 Answers
63

Use <f:ajax render=idOfPanelContainingInputFields> in the checkbox and give the component containing the input fields a rendered attribute which depends on the checkbox's state. No need for another JS code clutter.



<h:form>
<fieldset>
<legend>
<h:selectBooleanCheckbox binding=#{showUserInfo}>
<f:ajax render=idOfPanelContainingTextBox />
</h:selectBooleanCheckbox>
<h:outputText value=User information />
</legend>
<h:panelGroup id=idOfPanelContainingTextBox layout=block>
<ui:fragment rendered=#{not empty showUserInfo.value and showUserInfo.value}>
<p>
<h:outputLabel for=firstName value=First name: />
<h:inputText id=firstName value=#{bean.user.firstName} />
</p>
</ui:fragment>
</h:panelGroup>
</fieldset>
</h:form>


The above example binds the checkbox to the view, you can of course also bind it to a boolean bean property, you can then remove the not empty check from the rendered attribute.



            <h:selectBooleanCheckbox value=#{bean.showUserInfo}>

...

<ui:fragment rendered=#{bean.showUserInfo}>


See also:




[#95646] Thursday, September 9, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
adriannemyiag

Total Points: 504
Total Questions: 105
Total Answers: 99

Location: Ecuador
Member since Thu, Apr 22, 2021
3 Years ago
;