aspose file tools*
The moose likes JSF and the fly likes Use the same facelet component with different parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Use the same facelet component with different parameters" Watch "Use the same facelet component with different parameters" New topic
Author

Use the same facelet component with different parameters

Michael Gor
Greenhorn

Joined: Oct 07, 2011
Posts: 8
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?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Michael Gor
Greenhorn

Joined: Oct 07, 2011
Posts: 8
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

Joined: Jun 25, 2001
Posts: 16145
    
  21

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

Joined: Oct 07, 2011
Posts: 8
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Use the same facelet component with different parameters