Reputation:
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?
Upvotes: 0
Views: 832
Reputation: 1108632
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>
.
<h:commandLink action="#{myBean.myAction}" value="Send">
<f:param name="myFlag" value="true" />
</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
<h:form id="form">
<h:commandButton id="send" ...>
this way it will have a fixed request parameter name of form:send
and you could check on that in the validator:
if (externalContext.getRequestParameterMap().containsKey("form:send")) {
// Send button is pressed.
}
You can by the way also check for that in the required
validators as follows:
<h:inputText ... required="#{not empty param['form:send']}" />
Upvotes: 2