Hello,
Can anyone tell me how to use model-based constraints defined using Hibernate Validator for Primefaces?
Thanks
Sam
model-based constraints defined using Hibernate Validator
If you are talking about Bean Validation (JSR 303) this can be applied using <f:validateBean />
Examples:
This also works with validation groups:
Examples:
Code: Select all
<p:inputText value="#{managedBean.firstName}">
<f:validateBean />
</p:inputText>
Code: Select all
<f:validateBean>
<p:inputText value="#{managedBean.firstName}" />
<p:inputText value="#{managedBean.middleName}" />
<p:inputText value="#{managedBean.lastName}" />
</f:validateBean>
Code: Select all
<f:validateBean validationGroups="com.example.jsf.TextValidationGroup">
<p:inputText value="#{managedBean.firstName}" />
<p:inputText value="#{managedBean.middleName}" />
<p:inputText value="#{managedBean.lastName}" />
</f:validateBean>
-
- Posts: 69
- Joined: 22 Jan 2011, 11:04
Thank you for the response with examples.
How to apply constraint with primedaces?
Eg.
@TeadingRuleConstraints()
private StockTrades storkTrades;
I want its validation message to be printed out in the jsf message tag eg. <p: messages />
Thanks a lot
Sam
How to apply constraint with primedaces?
Eg.
@TeadingRuleConstraints()
private StockTrades storkTrades;
I want its validation message to be printed out in the jsf message tag eg. <p: messages />
Thanks a lot
Sam
Primefaces 2.2.1, JBOSS 6.0.0.Final, JDK1.6
I don't exactly know what you want, but I guess you need to define your own Constraints:
http://musingsofaprogrammingaddict.blog ... -bean.html
In your validator-class, you can generate new FacesMessages and add it to the FacesContext, then they get rendered by the p:messages component
Then you can still use the f:validateBean-Component to trigger the bean validation
http://musingsofaprogrammingaddict.blog ... -bean.html
In your validator-class, you can generate new FacesMessages and add it to the FacesContext, then they get rendered by the p:messages component
Then you can still use the f:validateBean-Component to trigger the bean validation
-
- Posts: 69
- Joined: 22 Jan 2011, 11:04
Yes, this is exactly what I mean. Thank you for the reference link. I will try this out .
Thanks very much
Sam
Thanks very much
Sam
Primefaces 2.2.1, JBOSS 6.0.0.Final, JDK1.6
- bumble.bee
- Posts: 723
- Joined: 29 Sep 2010, 21:39
- Location: United States
If you annotate your entities I don't think you need to use the f:validateBean component at all.
-
- Posts: 69
- Joined: 22 Jan 2011, 11:04
Then how does constraint annotated validation work with PF?
Best regards
Sam
Best regards
Sam
Primefaces 2.2.1, JBOSS 6.0.0.Final, JDK1.6
-
- PrimeFaces Core Developer
- Posts: 3979
- Joined: 03 Dec 2010, 14:11
- Location: Bavaria, DE
- Contact:
It's not PF specific.
Add a BV implementation to your JSF2 project and it's working.
Add context param:
Bean:
Page:
Add a BV implementation to your JSF2 project and it's working.
Add context param:
Code: Select all
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
Code: Select all
public Class UserBean {
@NotNull
@Size(min = 5, max = 20)
private String name;
Code: Select all
<h:inputText id="username" value="#{userBean.name}" />
Thomas Andraschko
PrimeFaces | PrimeFaces Extensions
Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE
Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko
PrimeFaces | PrimeFaces Extensions
Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE
Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko
-
- Posts: 69
- Joined: 22 Jan 2011, 11:04
If not PF specific, I know how to use it.
It doesn;'t require ANY xml file in general. I am with EJB3 - dependancy injection.
In fact, I just feel a bit difficult to use Constraint validation with PF.
Thanks
Sam
It doesn;'t require ANY xml file in general. I am with EJB3 - dependancy injection.
In fact, I just feel a bit difficult to use Constraint validation with PF.
Thanks
Sam
Primefaces 2.2.1, JBOSS 6.0.0.Final, JDK1.6
-
- Information
-
Who is online
Users browsing this forum: No registered users and 23 guests