File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Reference a composite component dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Reference a composite component dynamically" Watch "Reference a composite component dynamically" New topic

Reference a composite component dynamically

Heiko Tappe

Joined: Feb 19, 2013
Posts: 2
Let's say I have defined some composite components: "my:componentA", "my:componentB" and "my:componentC".

Now I would like to use these components "dynamically" via some kind of "component selector". For instance somehow like this:

Any idea how to achieve this?
Greg Charles

Joined: Oct 01, 2001
Posts: 2968

Hi Heiko, welcome to JavaRanch!

You could add a rendered attribute to your component to turn on and off rendering of it. If it's easier, you could put your component inside JSF container and use its rendered flag. All that assumes that by "dyanmic" you mean that it can change after requests to the server. If you want it to be dynamic completely on the client, you will need JavaScript / jQuery.
Heiko Tappe

Joined: Feb 19, 2013
Posts: 2
Sorry for not being precise enough.

I know I could do something like creating a new composite and inside the composite I could list several components/composites and only ONE component is rendered based on some incoming attribute.
But this way the composite will grow and grow. The component selector I am thinking about might serve as a selector for maybe more than 100 components.
So I think it's necessary or better to have some kind of "registry" for the component and select it via some "key".

Background: Imagine some generic UI for defining jobs. Each job has its specific parameters and after selecting a job I would like to offer some input component(s) specially designed for that job.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17410

I think IceFaces has a dynamic component tag. Either it or PrimeFaces.

As a rule, I prefer static definitions. they're easier to keep track of on the whole and easier to tweak for optimal appearance. But fortunately we have other options, too.

An IDE is no substitute for an Intelligent Developer.
I agree. Here's the link:
subject: Reference a composite component dynamically
It's not a secret anymore!