aspose file tools*
The moose likes JSF and the fly likes Reusable composite component with children. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Reusable composite component with children." Watch "Reusable composite component with children." New topic
Author

Reusable composite component with children.

Jens Lofgren
Greenhorn

Joined: Jun 05, 2011
Posts: 5
Im trying to create a reusable composite component that will use/iterate over childcomponents (much like h:dataTable uses h:column). The thing is I want to make it reusable across applications so I dont want it to "know" about any specific application class like PriceRow.java. That way I can distribute only the components and not any specific class and the "user"-application can use any class that keep information about price. (like h:dataTable don't have specific knowledge about every single class that it can render in a table)

The way I would like to use it:


pricePanel.xhtml (I guess this is where my problem is... I want to make the var-name dynamic.)


priceRow.xhtml


My problem is that I cant get "send" the row-instance to my child-component! Is there a way to do this?




/ J

Ps. For a number of reasons I don't want to use h:dataTable for this
Stefan Wehner
Greenhorn

Joined: Jun 07, 2011
Posts: 1
Hi Jens,

We've come upon this same issue implementing a composite component.
And from looking at the code it seems that the UIRepeat component doesn't allow ValueExpressions for var or varStatus, so you can only really use static Strings here.
As it sounds a bit strange not to accept ValueExpressions here, we filed a bug report with an attached patch http://java.net/jira/browse/FACELETS-372
I don't know if there is some good reason to disallow ValueExpressions so we'll see if this is going to be included in any future release.
If you want to try it meanwhile please go ahead and let us know if it works for you!

If not you're stuck with having a fixed "var" that you must use in the code included for each element...
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16233
    
  21

Welcome to the JavaRanch, Jens!

I think what I would probably be doing myself is that I would create a custom tag in xhtml. Especially since creating custom controls in JSF is not a trivial task!

If you do that, your variable information (parameters) could be defined as attributes in the tag invocation.

Here's a VERY rough sketch on how it would work:



And the basis of the custom tag would then be something vaguely resembling this:


Note that you don't (can't) explicitly define the custom tag's attribute names, but you will have to set up a tag mapping file that tells Facelets where the file containing the sources for the mytag tags are.


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

Joined: Jun 05, 2011
Posts: 5
Stefan Wehner wrote:Hi Jens,

We've come upon this same issue implementing a composite component.
And from looking at the code it seems that the UIRepeat component doesn't allow ValueExpressions for var or varStatus, so you can only really use static Strings here.
As it sounds a bit strange not to accept ValueExpressions here, we filed a bug report with an attached patch http://java.net/jira/browse/FACELETS-372
I don't know if there is some good reason to disallow ValueExpressions so we'll see if this is going to be included in any future release.
If you want to try it meanwhile please go ahead and let us know if it works for you!

If not you're stuck with having a fixed "var" that you must use in the code included for each element...


Interesting and disappointing! And great to hear that you filed report! Will follow it up!
I will try your patch as soon as I have the time but for now I will have to solve it some other way since I'm supposed to be done yesterday ;)

Thanks!
/J
Jens Lofgren
Greenhorn

Joined: Jun 05, 2011
Posts: 5
Tim Holloway wrote:Welcome to the JavaRanch, Jens!

I think what I would probably be doing myself is that I would create a custom tag in xhtml. Especially since creating custom controls in JSF is not a trivial task!

If you do that, your variable information (parameters) could be defined as attributes in the tag invocation.

Here's a VERY rough sketch on how it would work:



And the basis of the custom tag would then be something vaguely resembling this:


Note that you don't (can't) explicitly define the custom tag's attribute names, but you will have to set up a tag mapping file that tells Facelets where the file containing the sources for the mytag tags are.


Tanks for the welcome Tim... and for the help!

Actually I've managed to create composite components as you describe!

The thing is I want to encapsulate it "one more level" compared to your example. I would actually like the ui:repeat to be inside my custom component. So I would like two new components.
- "pricePanel" that is able iterate over:
- "priceRow"'s

I want to "hide" the iteration from he user of the component. I want the "pricePanel" to be "in charge" of rendering the pricelist. Not the end user (developer). Imagine I would like to release a new version of the pricePanel that changes the way the pricelist is rendered. From <table> to <dd><dt></dt></dd> for example. Or maybe I go crazy and use flash or something

/J
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16233
    
  21


Or maybe I go crazy and use flash or something


Please don't. Flash cost one of the major auto manufacturers a sale because they had a Flash-only website and none of my browsers at the time (phone or 64-bit desktop) was a supported Flash platform. I bought from a manufacturer whose website I could actually see.

From the sound of it, what you ought to be doing is using a dataTable. It's designed for that kind of stuff. ui:iterator is brute force and really is more geared towards repetitive rendering of more complex things,
Jens Lofgren
Greenhorn

Joined: Jun 05, 2011
Posts: 5
Tim Holloway wrote:

Or maybe I go crazy and use flash or something


Please don't. Flash cost one of the major auto manufacturers a sale because they had a Flash-only website and none of my browsers at the time (phone or 64-bit desktop) was a supported Flash platform. I bought from a manufacturer whose website I could actually see.

From the sound of it, what you ought to be doing is using a dataTable. It's designed for that kind of stuff. ui:iterator is brute force and really is more geared towards repetitive rendering of more complex things,


Just kidding about flash ;) And dataTable is not an option for a number of reasons

/J
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reusable composite component with children.