Sorry for my english. When you update a record by ID is not working the validator. If I make the validator via ajax:
<h:inputText id="name" value="#{testMB.instance.name}" required="true">
<f:validator binding="#{nameValidator}" />
<f:ajax event="blur" render="nameMessage"/>
</h:inputText>
When I once click on the Save
button:
<h:commandButton type="submit" action="#{testMB.save}" value="Save"/>
The validator works on the blur
event. If I click on the "save" button second time, then print out the error:
Error Rendering View[/pages/test.xhtml]: java.lang.NullPointerException
And redirects to URL without ID
. If I remove the ajax blur
in the field, then this error will occur when I once click on the button.
If the validator via actionListener:
<p:commandButton update="@form" actionListener="#{testMB.save}" value="Save"/>
Then it is working. Validator not working when I update a record by ID. Wnen I use the form for create a record, then this also works.
My testMB
:
public Entity getInstance() {
if (instance == null) {
if (id != null) {
instance = loadInstance();
} else {
instance = createInstance();
}
}
return instance;
}
public Entity loadInstance() {
return (Entity) getDao().findOne(getId());
}
public Entity createInstance() {
try {
return entityType.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
And f:metadata
:
<f:metadata>
<f:viewParam name="testId" value="#{testMB.id}"/>
</f:metadata>
Why not work validation with a regular button and ID?