2

A has many required inputs and validations. A couple of command buttons control different inputs.

I can change required attibrute with the value of <f:param>. For instance when a button is clicked,it sets a value.This value changes if an input is required or not. Like this:

<p:commandButton>
        <f:param name="button1" value="1"></f:param>
        </p:commandButton>

        <h:inputText required="#{param['button1'] == 1}"></h:inputText>

This actually works.However i also want to add some valitations like max length.I want to temporarily change this validation too.

I tried to disable valitadion,but i did not work:

<f:validateLength  disabled="true" maximum="10"></f:validateLength>
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
user1171708
  • 87
  • 2
  • 6
  • 13
  • The `validateLength` facet essentially uses a pre-built Validator class in the JSF implementation, which JSF implementation are you using? It also typically runs validation during the Validation phase. Does putting the attribute `immediate="true"` on the commandButton change the results at all? Try implementing the [BalusC Debug Phase LifeCycle Listener](http://balusc.blogspot.com/2006/09/debug-jsf-lifecycle.html) and at each of the phases check the properties of the length validator on your InputText UIComponent. This may lead to some interesting clues. – maple_shaft Feb 15 '12 at 12:21
  • Another suggestion would be to set the `maximum` attribute to some inordinately large number and see if that works. I would do that as a last resort though as it seems like a hack. – maple_shaft Feb 15 '12 at 12:25

1 Answers1

2

You seem to be using JSF 2.x already. So just use <f:ajax execute> or <p:commandButton process> to specify client IDs of components which are to be executed/processed when the button is pressed. All components which are not included in this will just be ignored and not converted/validated.

E.g.

<h:inputText id="input1" ... required="true" />
<h:inputText id="input2" ... required="true" />
<h:inputText id="input3" ... required="true" />
<h:inputText id="input4" ... required="true" />

<p:commandButton value="Submit inputs 1 and 2" process="input1 input2" ... />
<p:commandButton value="Submit inputs 3 and 4" process="input3 input4" ... />

In case of <p:commandButton> it defaults to @form (i.e. the entire current form).

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555