-
1. Re: Setting required attribute condition dynamically.
niox.nikospara.yahoo.com May 26, 2009 2:47 PM (in response to ambrish_kumar)Hi,
The only possible way to achieve this through JSF is to do a postback. You see the required field is part of the state of the view, saved after rendering and restored at the beginning of the restore view JSF phase.
With RichFaces you can at least do an AJAX, partial postback as:
<h:form> <h:selectBooleanCheckbox value="#{backingBean.requiredFlag}"> <a:support event="onchange" reRender="xxx" ajaxSingle="true" /> </h:selectBooleanCheckbox> <h:inputText id="xxx" value="#{backingBean.xxx}" required="#{backingBean.requiredFlag}" /> </h:form>
I am not sure if ajaxSingle="true" will work; try both true and false. If it does work, keep it. It will limit the network traffic and server load.
The other way is to bypass JSF and use Javascript directly, to manipulate the input according to the value of the check box.
-
2. Re: Setting required attribute condition dynamically.
coralfe Jul 22, 2009 4:21 PM (in response to ambrish_kumar)Answered here in the comments section.
short answer:
<h:inputText value="#{userCRUD.selectedRow.username}" size="30" required="#{!empty param['user_addEditForm:fieldDecoration2:pw']}" maxlength="255" id="user_First"/>
-
3. Re: Setting required attribute condition dynamically.
niox.nikospara.yahoo.com Jul 22, 2009 4:54 PM (in response to ambrish_kumar)
coral featherstone wrote on Jul 22, 2009 16:21:
Answered here in the comments section.
short answer:<h:inputText value="#{userCRUD.selectedRow.username}" size="30" required="#{!empty param['user_addEditForm:fieldDecoration2:pw']}" maxlength="255" id="user_First"/>
That's right, if you also want to couple your logic to the structure of the view AND the parameters of the view (ids) AND force yourself to define explicit ids for all the components in the hierarchy.