• 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

Adding components dynamically

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Setter method will be called when the container encounter this tag in JSP

 
joe black
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I can rely on the ordering of the components in the jsp?
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, give it a try
 
reply
    Bookmark Topic Watch Topic
  • New Topic