• 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

Use the same facelet component with different parameters

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have a small facelet composition, which consists of a primefaces dialog which displays values from a backing bean. Now I want to use this component to display data from different items. How can I do it?

For example, I could have a backing bean looking like this:

class ItemHandler {
public Object getFirstItem() { ... }
public Object getSecondItem() { ... }
}

I could set a parameter when I include the component, e.g.:

<ui:include src="...">
<ui:param name="item" value="#{itemHandler.firstItem}" />
</ui:parameter>

But what can I do, if I want to have multiple buttons, that display the info dialog for different items from the handler?
 
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
You have 2 options.

If the property names will always be the same, regardless of which bean is referenced, you can simply code the bean name without property qualification as the parameter on the calling element.

If the property names vary, code a parameter for each property.
 
Michael Gor
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don´t understand exactly, what you mean... The dialog/facelet component can display properties of one bean, so there is no problem with property names. It cound be smth like this:



Now, I have several options objects on the same page. They all are properties of another bean and have different names. For example, getOptionsA, getOptionsB...

So, I want to include my dialog component only once, but call it with different parameters. But in my understandig, I can only pass parameters when I include a facelet, e.g. in the <ui:include> tag. But I want to have different beans for the same parameter, depending which button the users clicks - all on the same page.
Any ideas?
 
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
The dialog definition is static, but from what I'm understanding, you want to do is, in effect, to dynamically redefine it. The ui:include is not a function, it's a declaration, so it doesn't change at runtime.

The closest you could come, I think, would be nasty, ugly, and require both AJAX and backing-bean component tree manipulation.

Better would be to either simply declare multiple instances of the dialog, or normalize the dialog itself and have the referencing functions access the standard dialog backing bean and its properties.
 
Michael Gor
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don´t want to redefine the dialog structure, just the object that is displayed in the dialog.

Just imagine another example, a bean that represents a list of cars (other beans), and a dialog that displays car details. The dialog definition does not change, but I want to use the same dialog to show details of different cars.

Look at this show case:
Primefaces dialog ShowCase

Here, they use the property "selectedCar" of the list-bean to identify the bean they want to reference in the dialog. In my case, I don´t use a data table and I don´t have a property "selectedObject" or anything else to identify which object I want to use. In fact, I even want to be able to show multiple dialogs at the same time, but it´s not a must have atm.
Instean of a data table, I have multiple commandLinks or commandButtons, and each one of them should open the same dialog, but display the properties of different "cars". Each commandLink knows, which "car" it wants to display, but how can I pass this info to the dialog? I hope, I described the problem more obvious now...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic