File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Joe Shannow
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 445
1
Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Make an AJAX request using the XMLHttpRequest object.
 
Joe Shannow
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for tip. But i know nothing about ajax for now :-)
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17645
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Shannow
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 90
Chrome Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17645
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Cesar, it's very nice and simple working solution!!!
Thank you Tim for BLUR event, it's enough for me now
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic