I’ve got the following h:commandButton:
<h:commandButton action="#{myBean.myAction}" value="Send">
<f:param name="myFlag" value="true" />
</h:commandButton>
I want to gain access to myFlag insinde a Validator, that’s attached to another element with f:validator.
Unfortunately, when I want to retrieve the parameter through the FacesContext, I only get null returned.
Is it that the parameters are only sent once all validators have been invoked?
The
<f:param>inside<h:commandButton>is only supported since JSF 2.0, but you’re using JSF 1.2. The<f:param>is then only supported in<h:commandLink>.There are alternatives, such as a
<h:inputHidden>or<f:setPropertyActionListener>or<f:attribute>or in this case perhaps just plain<input type="hidden">(the hidden input component and the action listener will only set their value during update model values which is later than validations phase; the attribute tag has better to be set on the component which invokes the validator). As the functional requirement is unclear, it’s not possible to suggest the best alternative.Update as per the comments, apparently all you need to know is if the particular button is pressed or not; in that case just give it and the parent form a fixed ID
this way it will have a fixed request parameter name of
form:sendand you could check on that in the validator:You can by the way also check for that in the
requiredvalidators as follows:See also: