• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Backing Bean in JSF 1.2

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Saloon Keeper
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 200
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic