| Author |
little jsf bean validation problem
|
Adnan Gondal
Ranch Hand
Joined: Apr 30, 2011
Posts: 32
|
|
For converting String values in JSF bean validation, which converter will be used? Like for numeric values we use <f:convertNumber> and for date we use <f:convertDataTime>. My code snipest are as follows:
JSF page:
Bean class:
|
 |
Guy deLyonesse
Ranch Hand
Joined: Apr 12, 2011
Posts: 189
|
|
|
Not really sure what you're asking here. Why would a String need to be converted? What do you intend to validate? (required value, string format, etc?)
|
 |
Adnan Gondal
Ranch Hand
Joined: Apr 30, 2011
Posts: 32
|
|
|
i want to validate that entered string is not null and its size is within the specified range defined in annotations.
|
 |
B Nirvan
Ranch Hand
Joined: Oct 20, 2010
Posts: 82
|
|
kajel rani wrote:i want to validate that entered string is not null and its size is within the specified range defined in annotations.
Use a validator
regards,
Nirvan.
|
 |
Guy deLyonesse
Ranch Hand
Joined: Apr 12, 2011
Posts: 189
|
|
Yeah not sure why you're using annotations but JSF has built in required field validation. It also has built in min/max validators as well as length validators.
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14491
|
|
The purpose of converters is to transform non-string objects to and from string form because HTML is a text-only format but that isn't supposed to limit what kinds of objects users can work with. So there is no converter for strings,
Validation annotations are useful things. They can be set on the primary definition of a data object to ensure that data will be conformant to basic edit requirements regardless of who sets it. However, they're not the only solution to that problem, and sometimes there's even a benefit to having multiple solutions.
For example, the "required="true"" JSF attribute can be used as a front-end check for required data. That will allow JSF to pre-screen the value early in the lifecycle, which allows the twin benefits of short-circuiting around useless work as well as benefiting from the JSF-standard error mechanisms.
For input text controls, things can go even further. By using the maxlength attribute, the generated HTML control will possess the ability to block entry of values longer than that limit at the user data-entry level. In other words, the client software itself (web browser) enforces the restriction.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
 |
|
|
subject: little jsf bean validation problem
|
|
|