Hi Heath

Thanks for the solution... it does sound complicated, but I am trying it.

I am using version 1.0.7 of my-faces. 

 I have changed the onclick event of the checkbox to call the click event of 
the command button, nothing happened. Here is part my page....

                         <h:panelGrid id="remarriedOption" columns="2" >
                                <seniorfaces:outputLabel for="remarried"
                                    value="some text here ?" />
                                <h:selectBooleanCheckbox id="remarried"
                                    immediate="true"
                                    
onclick="document.getElementById('hiddenBtn').click();"
                                    
value="#{manageProfileFace.spouseHelper.remarried}" />
                                <h:commandButton id="hiddenBtn" 
style="display:none;"
                                    
action="#{manageProfileFace.spouseHelper.flagRemarried}" />
                            </h:panelGrid>

                            <h:panelGrid id="remarriageInfo" columns="2"
                                
rendered="#{manageProfileFace.spouseHelper.remarried}"
                                styleClass="dataTableBorderAlt"
                                rowClasses="dataCellEven,dataCellOdd"
                                
columnClasses="cellAlignLeftFullWidth,cellAlignLeftFullWidth"
                                cellpadding="0"
                                cellspacing="1">
        
                                <seniorfaces:outputLabel for="firstName" 
value="First Name" />
                                <h:inputText id="firstName" 
required="#{manageProfileFace.spouseHelper.remarried}"
                                    
value="#{manageProfileFace.spouseHelper.newSpouse.firstName}">
                                    <f:validateLength maximum="20"/>
                                </h:inputText>
        
                                <seniorfaces:outputLabel for="middleName" 
value="Middle Name" />
                                <h:inputText id="middleName" 
value="#{manageProfileFace.spouseHelper.newSpouse.middleName}">
                                    <f:validateLength maximum="20"/>
                                </h:inputText>
        
                                <seniorfaces:outputLabel for="Last Name" 
value="Last Name" />
                                <h:inputText id="Last Name" 
required="#{manageProfileFace.spouseHelper.remarried}"
                                    
value="#{manageProfileFace.spouseHelper.newSpouse.lastName}">
                                    <f:validateLength maximum="30"/>
                                </h:inputText>
                        ....
                        ....
                              
                            </h:panelGrid>


the method "flagRemarried" will toggle the flag in the backing bean. Will the 
getElementById work with version 1.0.7 ?  What am I missing here ?  When the 
checkbox is clicked nothing is happening.

Please reply at your convenience. I am off for the day.

Thanks
Srikanth


-----Original Message-----
From: Heath Borders [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 22, 2005 5:02 PM
To: MyFaces Discussion
Subject: Re: handling the required attributes


Just to preface, this solution is a bit complicated.

First, you shouldn't do a form submit when the user clicks the
checkbox.  You should create an immediate commandButton and set its
style to "display: none;".  This will hide it from the user, but still
allow you to use it to generate ActionEvents.

When the user clicks the checkbox, you do a
"document.getElementById('myCommandButton').click();", which will
submit the form using your commandButton.

This will allow the user to uncheck the checkbox without having validation run.

However, now you will have other problems:
All UIInputs on the form will not be validated, so none of their
values will get push to the models.  You can solve this problem by
making the UIInputs you want to go through to the models (probably
just your checkbox) immediate as well.  This will get them through
their process validators phase.  Additionally, you have to register a
ValueChangeListener on those UIInputs that will call the UIInput's
updateModelValues() method.

Finally, you have to traverse the JSF tree and clean all the
submittedValues/values from all UIInputs, or else they will not
properly pull from their models on the fresh request.

I said it would be complicated :-)


On Tue, 22 Mar 2005 16:13:50 -0500, Srikanth Madarapu
<[EMAIL PROTECTED]> wrote:
> Hi
> 
>  I have a page with a check box and few input fields in a panelGrid. The 
> panelGrid is rendered based on whether the checkbox is selected or not. 
> Initially when the page is rendered the checkbox is not selected and the 
> panel is not rendered, when the checkbox is selected,  the form will be 
> submitted with onclick="submit();" , and the panel is rendered.
> 
> The panel has couple of required fields. After the panel is rendered, the 
> user may want to uncheck the checkbox, in which case the form will be 
> submitted again. If the user unchecks the checkbox without entering any data 
> in the required fields, the validation errors are generated, but the user 
> want to turn off the panel and the user need not enter any data in the 
> required fields.
> 
> But because whenever the form is submitted the frame work will check for 
> required fields and throw validation errors. How can I bypass this 
> validation, I want to allow the user to uncheck the checkbox without entering 
> any values in the required fields.
> 
> The only way I can think of enforcing the required fields is to validate the 
> data when the form is submitted and not use the required attribute for those 
> required fields.
> 
> TIA.
> -Srikanth Madarapu
> 
> 


-- 
-Heath Borders-Wing
[EMAIL PROTECTED]

Reply via email to