This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSF and the fly likes AJAX Conditionally Render Components Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "AJAX Conditionally Render Components" Watch "AJAX Conditionally Render Components" New topic
Author

AJAX Conditionally Render Components

Andy Holm
Ranch Hand

Joined: Jul 03, 2008
Posts: 86
I am trying to use the RichFaces AJAX library with a JSF application. I want to conditionally render a couple <h:inputText> entries based on the value of a drop down menu. How do I do that? Here's my code so far:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Please be sure to ask JSF questions in the JSF forum. I have moved this post there for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Andy Holm
Ranch Hand

Joined: Jul 03, 2008
Posts: 86
I got this to work by using the code at the bottom of this post. The problem I now have is that when the reRender happens, the browser scrolls to the top of the page rather than remembering where it was before the reRender. Any ideas on how I can prevent that from happening? I tried following this example, but it didn't work for me in IE 7: http://blogs.x2line.com/al/articles/156.aspx

Andy Holm
Ranch Hand

Joined: Jul 03, 2008
Posts: 86
Anyone able to help on this?
Andy Holm
Ranch Hand

Joined: Jul 03, 2008
Posts: 86
Well, after some tinkering, I was able to remember the scroll position via a cookie. Now, the last remaining question I have is how do I save inputted data to my beans before the AJAX reRender completes. Whenever the AJAX reRender happens, I lose all data that has already been input into the form. The backing beans don't seem to be updated when an AJAX reRender happens like they would be on a normal page submit...
Shivaji Byrapaneni
Greenhorn

Joined: Oct 20, 2008
Posts: 22
no other go other than submitting the page....
Andy Holm
Ranch Hand

Joined: Jul 03, 2008
Posts: 86
I find it hard to believe that an AJAX reRender would force the entire form to lose its inputted values without a workaround. There must be a way around this; otherwise, no developer would ever use an AJAX reRender unless it is updating the entire page when any inputted data is involved.
Kavita Tipnis
Ranch Hand

Joined: Sep 21, 2008
Posts: 177
Andy Holm wrote:I find it hard to believe that an AJAX reRender would force the entire form to lose its inputted values without a workaround. There must be a way around this; otherwise, no developer would ever use an AJAX reRender unless it is updating the entire page when any inputted data is involved.


Ajax rerender does not and should not cause you to lose any form data, think logically, you are sending the request to the server and the server only refreshes/rerenders output for only those elements specified in reRender , it does not touch the other output/data

Debug to see what is causing the form to lose data
Andy Holm
Ranch Hand

Joined: Jul 03, 2008
Posts: 86
Any idea on how to debug this?
Andy Holm
Ranch Hand

Joined: Jul 03, 2008
Posts: 86
Here's a simplied full example that should allow you to duplicate the problem. What am I doing wrong?



Bean:
Andy Holm
Ranch Hand

Joined: Jul 03, 2008
Posts: 86
I was able to get most of the values to save on the reRender by extending the a4j region. The one exception is this value:



Any ideas on how to store this value on an AJAX reRender? Sometimes I think I am talking to myself on this forum... lol
Kavita Tipnis
Ranch Hand

Joined: Sep 21, 2008
Posts: 177
This post should answer that last question
Problem with t:inputFileUpload
 
 
subject: AJAX Conditionally Render Components
 
Similar Threads
Seam/RichFaces - extendedDataTable, datascroller, and changeable page size
javax.xml.rpc.soap.SOAPFaultException: System.Web.Services.Protocols.SoapException:
How to set Default selection in h:selectOneMenu
How to set default selection for selectOneMenu?
can anybody help ??