-
1. Re: Showing/Hiding controls using a radio button
liuliu Sep 16, 2009 3:12 AM (in response to nbhatia)
i think your need use reRender and ajaxsingle attribute for a4j:support. dont rerender your outputpanel. -
2. Re: Showing/Hiding controls using a radio button
nbhatia Sep 16, 2009 5:52 PM (in response to nbhatia)Thanks liuliu. Based on your suggestion, I have added reRender and ajaxSingle to my a4j:support element. I did not change anything on the ouputPanel, it still has the render condition because it should be rendered only when it is a cash transfer. This is also the approach taken by the example at http://livedemo.exadel.com/richfaces-demo/richfaces/support.jsf?tab=selects&cid=81881. Unfortunately, my outputPanel is still always present, it does not hide when I toggle the radio button. My code is shown below.
<h:form id="transferForm"> <h:selectOneRadio id="transferKind" value="#{transferController.transferKind}"> <s:selectItems value="#{transferKinds}" var="transferKind" label="#{transferKind}" /> <s:convertEnum /> <a4j:support id="onchange" event="onchange" reRender="transferFields" ajaxSingle="true" /> </h:selectOneRadio> <a4j:outputPanel id="transferFields" layout="block" rendered="#{transferController.cashTransfer}"> <h:inputText id="amount" required="true" styleClass="wideText" value="#{transferController.amount}"> </h:inputText> </a4j:outputPanel> </h:form>
Can someone please point me in the right direction?
Thanks
Naresh -
3. Re: Showing/Hiding controls using a radio button
nbelaevski Sep 17, 2009 5:18 AM (in response to nbhatia)Hi Naresh,
Check this: http://www.jboss.org/community/wiki/CommonAjaxRequestsProblems#conditionalRendering -
4. Re: Showing/Hiding controls using a radio button
nbhatia Sep 17, 2009 7:37 AM (in response to nbhatia)Thanks, that's a great link and I was able to get show/hide working as required.
As a follow up question, how do people handle validation in such situations? In my use case, if it is a cash transfer, then I need to show the Amount field and the field is required. In case of bank transfer, I also need to show the account number field which is also required. But if I specify the account number field as required, validation is failing when I try to input a cash transfer (where account number doesn't have to e filled). The only thing I can think of is to make the fields as not required and do the validation manually during form submit. Any thoughts? -
5. Re: Showing/Hiding controls using a radio button
nbelaevski Sep 17, 2009 7:58 AM (in response to nbhatia)Non-rendered fields are not validated.
-
6. Re: Showing/Hiding controls using a radio button
nbhatia Sep 17, 2009 8:45 AM (in response to nbhatia)You are absolutely right! I checked this again and indeed non-rendered fields are not being validated. Thanks so much for your help.