Skip to main content

Automatic Bean Validation with JSF 2 and Ajax

1 reply [Last post]
klee1703
Offline
Joined: 2005-08-03
Points: 0

I have a simple JSF 2 facelet that includes automatic bean validation, attached is the pseudo-code:
<h:form>
Job List URL:
<h:inputText
id="infoset"
required="true"
requiredMessage=" Job List URL required!"
validator="#{adminBean.validateURL}"
value="#{adminBean.infosetName}">
<f:validateBean disabled="false"/>
</h:inputText>
<h:commandButton id="submit"
value="Submit"
action="#{adminBean.submitJobList}">
</h:commandButton>
<h:message for="infoset" styleClass="error"/>
</h:form>

When I run this code it works fine (displays an error message if the required form inputs aren't provided); however t if I use the f:ajax tag to render the response as shown below:
<h:form>
Job List URL:
<h:inputText
id="infoset"
required="true"
requiredMessage=" Job List URL required!"
validator="#{adminBean.validateURL}"
value="#{adminBean.infosetName}">
<f:validateBean disabled="false"/>
</h:inputText>
<h:commandButton id="submit"
value="Submit"
action="#{adminBean.submitJobList}">
<f:ajax execute="infoset" render=":response" />
</h:commandButton>
<h:message for="infoset" styleClass="error"/>
</h:form>

The validation is no longer being performed for erroneous inputs. Any ideas on why this is so and what I should change to be able to perform automatic bean validation while using the JSF 2 f:ajax tags?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
healeyb
Offline
Joined: 2010-01-26
Points: 0

Possibly a typo but the id="response" component doesn't exist, add this to h:message. Then I think
you want the f:ajax tag to be a child of h:inputText instead of commandButton. Unless you use
h:form prependId="false" you may need to add an id= to h:form and use render="formid:response".
I don't think the f:validateBean is doing anything for you there, remove. There's a few things to try.
Regards,
Brendan.