aspose file tools*
The moose likes JSF and the fly likes dynamic changing of h:inputText value based on change value in other h:inputText Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "dynamic changing of h:inputText value based on change value in other h:inputText" Watch "dynamic changing of h:inputText value based on change value in other h:inputText" New topic
Author

dynamic changing of h:inputText value based on change value in other h:inputText

Joe Shannow
Ranch Hand

Joined: Dec 01, 2010
Posts: 35
hi,

is possible to solve this problem?
- I have one h:inputText in a form - user add here for example ID of person
- and beside is the disabled h:inputText where will be shown a NAME of person (from data table ID,NAME)
- immediately after filling the first input but WITHOUT submitting a form

do you have some experience? thanks
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 443
    
    1


Make an AJAX request using the XMLHttpRequest object.
Joe Shannow
Ranch Hand

Joined: Dec 01, 2010
Posts: 35
Thanks for tip. But i know nothing about ajax for now :-)
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15661
    
  15

Joe Shannow wrote:Thanks for tip. But i know nothing about ajax for now :-)


Well, I guess it's time to get educated, then!

In order to obtain data from the server, a form does have to be submitted. However, AJAX allows the "form" to be a minumum of data and allows you to avoid reloading the entire displayed webpage.

There are a number of ways to do AJAX:

1. Brute forces, using handwritten JavaScript code

2. Using a JavaScript assistance package such as jQuery

3. Using an AJAX-aware JSF extension tagset such as RichFaces or IceFaces

4. Using the JSF2 AJAX enhancements (if your app uses JSF Version 2)

I've been using option #3 with good results for some time now.


Customer surveys are for companies who didn't pay proper attention to begin with.
Joe Shannow
Ranch Hand

Joined: Dec 01, 2010
Posts: 35
Thank you very much, Tim.

So I'll try to explore third (other faces) and second option (using jQuery, onkeypress event and call servlet by get method..?).


Cesar Loachamin
Ranch Hand

Joined: Dec 25, 2010
Posts: 90

In case anyone is interested, I'll leave an example of the fourth option proposed by Tim.
Using the JSF2 AJAX enhancements (if your app uses JSF Version 2).
First the view

In the <f:ajax> the event attribute is a DHTML events whithout the on prefix, can also be valueChange and action, in the example we make the ajax request in the onkeyup event.
The render is a space-separated list of components that JSF renders on the client after the Ajax call returns from the server and,
The execute is a space-separated list of components that JSF executes on the server during the Ajax call, you can use @this for the current component, or @form,@all,@none

And the code for the Managed Bean

Regards
Cesar


When a dream is ending because to come true - OCPJP 6,7. OCE JPA EE6. MCTS
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15661
    
  15

Couple of notes on JSF2:

There's a default action on the JSF input controls, so you can omit that part if you want.

I wouldn't normally hook this particular item to the (on)keyup event, since that generates a lot of traffic. The blur or change events are more common. Keyup is good for suggestion lists, however.

At the moment, I think that the approach used by RichFaces is more straightforward than the new JSF2 method, but we'll see...
Joe Shannow
Ranch Hand

Joined: Dec 01, 2010
Posts: 35
Thank you Cesar, it's very nice and simple working solution!!!
Thank you Tim for BLUR event, it's enough for me now
 
jQuery in Action, 2nd edition
 
subject: dynamic changing of h:inputText value based on change value in other h:inputText
 
Similar Threads
problem javascript
how to use selectOneRadio with javascript?
JSF + Tomahawk + subform
Html generated by JSF TAG <h:inputText/>
Passing parameters with h: link