You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Srikanth Madarapu <sr...@senior-systems.com> on 2005/03/22 22:13:50 UTC

handling the required attributes

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


Re: handling the required attributes

Posted by Heath Borders <he...@gmail.com>.
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
<sr...@senior-systems.com> 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
hborders@mail.win.org

Re: handling the required attributes

Posted by Enrique Medina <e....@gmail.com>.
Why don't you simply use the immediate attribute? 

It will make JSF lifecycle to jump from the Apply Request Values phase
to the Render phase.


On Tue, 22 Mar 2005 16:13:50 -0500, Srikanth Madarapu
<sr...@senior-systems.com> 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
> 
>