aspose file tools
The moose likes JSF and the fly likes Adding components dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Adding components dynamically" Watch "Adding components dynamically" New topic
Author

Adding components dynamically

joe black
Ranch Hand

Joined: Dec 03, 2003
Posts: 103
I have a criteria box at the top of my screen which holds various inputs such as text box, combo boxes, etc. The components I need to create for this screen are given to me by a webservice. In the response it tells me which components to add to the criteria box panel. This panel is defined in my jsp.

What I currently do is make a call to my web service in the constructor of my backing bean, then find the criteria box panel by id using findComponent, and then create and add the components. I use findComponent because if I try to bind the panel in the jsp to the backing bean, the reference is always NULL in the constructor. The backing bean is in request scope.

I have this logic in the constructor because these controls need to be in the panel before the page loads. Is there a more clean way of doing this? Anywhere else I can make the call to my web service and add the controls dynamically? I tried adding a phase listener but beforePhase() didn't get called on the first request, I guess because the listener was added, and then was called twice on subsequent requests.


[ February 25, 2007: Message edited by: joe black ]
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
In you JSP define the panel as



Now in your Backing bean define a panel object at class level



and provide its getter/setters, the setter method will be called by the container. Keep in mind that first it will create the bean object by calling constructor and then will call the setter method. In this setter method you can add your components dynamically.
joe black
Ranch Hand

Joined: Dec 03, 2003
Posts: 103
In what order are the setter methods called by the container?

The reason I ask is because I also have a combo box which is populated dynamically, and I need this to be created first, because before I create it, I lookn in the request for a parameter, which I then set as the value of an instance variable, and then the code which creates the panel would need to grab it.

So if the panel setter was called first, it would not have this value.
[ February 26, 2007: Message edited by: joe black ]
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
Setter method will be called when the container encounter this tag in JSP

joe black
Ranch Hand

Joined: Dec 03, 2003
Posts: 103
So I can rely on the ordering of the components in the jsp?
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
Yes, give it a try
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Adding components dynamically
 
Similar Threads
Adding custom javascript
Switching between panels in a GUI
Jsf Data table values are coming as null
PhaseListener problem
Initialize backing bean