• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 479
1
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Make an AJAX request using the XMLHttpRequest object.
 
Joe Shannow
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for tip. But i know nothing about ajax for now :-)
 
Saloon Keeper
Posts: 27762
196
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

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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..?).


 
Ranch Hand
Posts: 90
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 27762
196
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
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
"To do good, you actually have to do something." -- Yvon Chouinard
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic