wood burning stoves 2.0*
The moose likes JSF and the fly likes Need to capture xhtml input data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Need to capture xhtml input data" Watch "Need to capture xhtml input data" New topic
Author

Need to capture xhtml input data

harish shankar
Greenhorn

Joined: Jul 13, 2008
Posts: 18
I need to capture all the field value(input fields) information for any xhtml in a Map,one way is i can get the values from the UI bean via reflection .Are there any other ways of doing this?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

I'm afraid I don't know what you mean. I'm not even sure if you mean xhtml in the HTML-standard way or the "xhtml" that servers as the JSF View Template Language.

As far as JSF goes, whenever you submit a form (as defined in a VTL template), JSF automatically receives all of the input control properties for the controls in that form. JSF then validates them, and if each and every one of them is determined to be valid, JSF itself will update the backing bean properties automatically. No user code is required.


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

Joined: Jul 13, 2008
Posts: 18
Yes its the xhml for jsf.
I was looking some way to capture the data other than from backing bean.one approach I tried was reading all the child components of a form.but this does not give what values are assaigned for each component id
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Harish

What are your reasons for trying to avoid using backing beans?
harish shankar
Greenhorn

Joined: Jul 13, 2008
Posts: 18
I need to check whether of mandatory fields in the form at the business layer,for example the XHTML has name,age,address,occupation fields I need to check if name and age details are entered but at the same point I do not want hard code the check for the mandatory fields in code instead It will be configurable.one way I can think of is to covert the managed bean into a map and pass it to business layer this I would have use reflection or JSON , I am thinking of not using reflection ,so trying to explore other options.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

Use "required=" attribute on the control elements to require data entry for that control. This can be configured dynamically on the backing bean as a POJO boolean property value, although it's usually not a good idea to make that sort of stuff too dynamic, as it can confuse users.

Always remember that JSF is designed to provide POJO-based solutions. If you are writing compicated code that digs into JSF's internals, you are usually doing it wrong.
harish shankar
Greenhorn

Joined: Jul 13, 2008
Posts: 18
Thanks. But we have to change the mandatory fields like add one would require code change. .
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

Soooo... It's OK to build a complex and fragile mechanism to play around with the internals of JSF, but it's NOT OK to add a single simple binary property to the UI model object? An object whose sole reason for existence is to support the UI? Not even considering that you could reference a supporting parallel UI model object if it is unacceptable to modify the primary UI model object?

James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1030
    
    5

Harish

Sounds like an unreasonable requirement to me. A field is either mandatory or it isn't.

The best solution I see is to hold the values of the required attribute (as suggested by Tim) in a resource bundle properties file. That way, when you need to 'switch' a field from mandatory to optional (or vice versa), you simply change the value in this file and re-start the app server.
harish shankar
Greenhorn

Joined: Jul 13, 2008
Posts: 18
I also need to check on the field value also...like name should be only 'xyz' address is 'asd'.i tried reading the child components but I could not see values associated with the components
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16250
    
  21

Attempting to read data by reading the child components is (again) doing it the hard way.

I'm going to assume that the name isn't ALWAYS going to be "xyz", since that would be pointless. But perhaps it can always only be "xyz" if the city is "Chennai".

The simple way to handle context-sensitive validation is to do it in the action method:



JSFUtils is a class that I create for my webapps to make interactions with JSF more abstract and less framework-dependent. The JSFUtils addErrorMessage() is simply a method that obtains the JSF messages object from the FacesContext, constructs a new Message and adds it the the JSF messages. It's about 5 lines long, but it keeps my mainline code from having to know about FacesContext and JSF's internal message management.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Need to capture xhtml input data