aspose file tools*
The moose likes JSF and the fly likes Backing Bean in JSF 1.2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Backing Bean in JSF 1.2" Watch "Backing Bean in JSF 1.2" New topic
Author

Backing Bean in JSF 1.2

Debasree Saha
Greenhorn

Joined: Feb 13, 2009
Posts: 2
Hi,

As per my understanding in jsf Backing Bean java files gets created as per the we design the jsf page. I need to add my own validation methods in the bean file. Where to look for this customization in bean file. Could see <navigation-handler> in faces-config.xml but need in depth structure for the same. Please advice how to add my validation methods in Backing Bean file.

Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
I don't understand what you're all talking about. Are you using a visual editor ans seeing it as part of JSF or so? Please don't do that anymore.

Adding validation methods to the backing bean isn't that hard. It's just as every other simple Java class where you can add methods to. Open the class source file, add the method, save and recompile the class. That's all.
Debasree Saha
Greenhorn

Joined: Feb 13, 2009
Posts: 2
Bauke Scholtz wrote:I don't understand what you're all talking about. Are you using a visual editor ans seeing it as part of JSF or so? Please don't do that anymore.

Adding validation methods to the backing bean isn't that hard. It's just as every other simple Java class where you can add methods to. Open the class source file, add the method, save and recompile the class. That's all.






Hi, Thanks for your response.. I need to know the location of bean class file so that I can add my method.Thanks..
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
It's like as asking you here where I have left my pencil. Sorry, I don't know. You have it all in your hands. Just open the class file and add the method.
Rahul Santha
Greenhorn

Joined: Apr 17, 2008
Posts: 12
Debasree Saha - If you are using RAD right click on the JSP and click on "Edit page code" in the menu to edit your JAVA CLASS. Every IDE/tool has it own navigation to the class. Like BalusC said the pencil is in your hands, look again.


Thanks!<br />Rahul, IOWA
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

JSF was designed to support data validation as a discrete step in the JSF lifecycle. Validation done at this level ensures that no data is set in the backing bean unless all validators are satisfied - providing you don't bypass that phase by using an immediate action.

There are a small, but basically useful set of validators that come as part of the framework; for example, the RangeValidator. One validator is even built into selected JSF HTML tags themselves - the 'required="true"' validator.

Some of the third-party JSF tag libraries add additional validators, and there's a couple of efforts right now to extend validation even further by allowing annotation of the backing beans (the Myfaces Extensions Validator).

When none of the above will do, you can write your own validator. Implement a javax.faces.validator.Validator and code your validation in its validate() method. If validation fails, construct a FacesMessage object with the error message text in it and throw a ValidatorException. That's all there is to it.

Sometimes you have more complex validation issues such as when you have to cross-check properties against each other. The final line of defense is to code (or call) validation logic in your action processor and have it return a failure status. That's a last-resort method, since the backing bean has already been updates at that point, and most validators are intended to avoid setting improper values in the backing bean. The alternative is to create cross-checking validators that can lookup elements in the incoming update request tree, but that's wore work.


Customer surveys are for companies who didn't pay proper attention to begin with.
Laurent Wulser
Greenhorn

Joined: May 23, 2011
Posts: 2
In case of custom validator class, is it possible to use it directly in the backing bean, like jsf2 annotation ? Or do we need to call the validator in the xhtml file with the f:validator ?

I would like to simplify the view. Otherwise, is it possible to create new validator annotation ?

Has someone any example of backing bean like that ?

Thanks.
Guy deLyonesse
Ranch Hand

Joined: Apr 12, 2011
Posts: 200

Laurent Wulser wrote:In case of custom validator class, is it possible to use it directly in the backing bean, like jsf2 annotation ? Or do we need to call the validator in the xhtml file with the f:validator ?

I would like to simplify the view. Otherwise, is it possible to create new validator annotation ?

Has someone any example of backing bean like that ?

Thanks.


You may want to ask this question in a separate thread to get more attention.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Backing Bean in JSF 1.2