validation - JSF custom validator not invoked when submitted input value is null -
i created custom validator not getting called when input null.
my validator code:
@facesvalidator("requiredvalidator") public class requredvalidation implements validator { public void validate(facescontext context, uicomponent component, object value) throws validatorexception { system.out.println("in valid gggggggg"); }
my xhtml page code:
<p:message for="urlinput" /> <p:inputtext id="urlinputv" value="#{coveragebean.firstname}" label="url" maxlength="2" > <f:validator validatorid="requiredvalidator"></f:validator> </p:inputtext> <p:message for="urlinputv" /> <p:commandbutton value="submit" action="#{loginbean.validatetext}" />
now working when entering value in text box, not working when inputtext null.
the server using
- tomcat
- primefaces 3.5
- jsf2.0
please tell problem is?
by default, jsf not validate empty submitted value if bean validation (jsr303) not available in environment. behavior can controlled context parameter javax.faces.validate_empty_fields
.
the default value javax.faces.validate_empty_fields
auto
, meaning empty fields validated if bean validation (jsr303) available in class path.
if want validate empty fields anyway without bean validation, explicitly set context parameter in web.xml
true
this:
<context-param> <param-name>javax.faces.validate_empty_fields</param-name> <param-value>true</param-value> </context-param>
it must said use required="true"
in case want validate input field required. don't need perform job in custom validator then.
<p:inputtext ... required="true" requiredmessage="please enter value" />
or, more abstract <f:validaterequired>
:
<p:inputtext ... requiredmessage="please enter value"> <f:validaterequired /> </p:inputtext>
do note can safely use multiple validators on same input component.
Comments
Post a Comment