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

getSubmittedValue is coming as null

Haneef Nb
Greenhorn

Joined: Mar 02, 2013
Posts: 3

Hi All,

I facing one problem in jsf, when i attached <a4j:support> to my <h:inputText>, as shown below

<h:inputText id="" value="" binding="">
<a4j:support
actionListener="Action_Class.validateUserName"
event="onblur" />
</h:inputText>

As shown in above, when i am tabbing out from <input> field, validateUserName has to call.it is calling,but when i am trying to get my submitted value as shown below,
null is coming.

UIInput input = actionEvent.getParent();
String userName = input.getSubmittedValue();

username is coming as null.(The submitted value is coming only in IE browser, but in remaining browsers i am getting null as submitted value).

Kindly do needful.


Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16070
    
  21

Welcome to the JavaRanch, Haneef!

JSF is based on Inversion of Control. In the IoC paradigm, the Model (backing bean) does not "go out and get" data from the View (web page), the JSF Controller (FacesServlet) reads the submitted data and posts it to the backing bean automatically without any JSF-specific logic required.

In fact, my #1 rule for JSF is this:

If you are coding JSF-specific Java code, you are probably doing it wrong.


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

Joined: Mar 02, 2013
Posts: 3
Thanks for your prompt response.

100% i will agree with your comment, the jsf framework populate the data into backed bean automatically, but it will happens after the validation phase, but in my case i am attaching ajax support, so before performing the validations, i can retrieve the data from the view with the ActionEvent, as shown in the code above.
i was succeeded in the browser IE, but in mozilla / Chrome i am having problem, in these 2 browsers only i am getting null value.

And i will explain my exact requirement also, of course in jsf after page submission all the attached validators will fire, but for me on tabbing out of each field in the form, the corresponding validator needs to be fired, so as shown in above i am attaching one listener to text fields, and i getting the value by using getSubmittedValue(), i am checking this value is null or not, if it is not null then i am calling validator manually, So my case in IE value is coming, so i can call validator manually, but in mozilla/chrome value is not coming, so my validator is not getting fired.

So kindly help me.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16070
    
  21

JSF processes AJAX in exactly the same way it processes ordinary command actions. The only difference is that an ordinary commandlink/commandbutton submits all controls on its associated form and updates the entire page, but AJAX can be set to submit only parts of the form and update only parts of the page.

Listeners are not asynchronous event handlers, nor do they bypass parts of the JSF lifecycle. JSF listeners are simply methods that get invoked as part of a submit request when conditions warrant (for example, when a form control's value has been changed).

As I said before, JSF is designed to make simple things simple. If you don't want validation, you have to simply not set validation in the View Definition and validate manually in the action method. Or make the validation conditional on an EL expression. In any event, a JSF form will NEVER return null, because NULL is not a text value and JSF is communicating via a text-based protocol (HTML). Instead of NULL, you'd have an empty string being injected into your bean.
Haneef Nb
Greenhorn

Joined: Mar 02, 2013
Posts: 3
Thanks Tim,

I am not saying the listener will by pass the jsf life cycle, i wanted to know whether i can capture the value entered by the user from the the view or not, i wanted to capture it into a variable, not into backed bean, yes any how my jsf frame work will do that(populate the data into backed bean), i wanted to capture that value into a variable by using the listeners before jsf populating the data into backed bean, Kindly tell me is it possible?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16070
    
  21

It is not. As I said, the listeners are invoked by the Controller (FacesServlet) as part of the JSF lifecycle processing. They do not respond asynchronously.

You are attempting a complex solution for a simple problem.
 
jQuery in Action, 2nd edition
 
subject: getSubmittedValue is coming as null