generate a list widgets in JSF using "binding"

Go To StackoverFlow.com

0

I have a list of objects, "think draggable panels" that need to be rendered on the screen. Each of these Panels has it's own material it needs to render inside it. My initial thought was to do something like

<ui:repeat value="#{bean.widgets} var="widget">
    <p:panel binding="#{widget.contents}/>
</ui:repeat>

Now this doesn't work probably for many reason. One i know of is that the "var" is only request scope. So, whereas i can access the values of fields within my "widget" java object, I can't directly call a method to bind my panel to.

Could anyone provide direction to take?

Currently running PrimeFaces 3.2 | GlassFish 3.1.2 | Mojarra 2.1.6

2012-04-05 16:59
by user1269227


0

The binding attribute is evaluated during view build time, while the <ui:repeat var> attribute is evaluated during view render time, so it's indeed null at the point the <p:panel> is discovered and built.

Use JSTL <c:forEach> instead of <ui:repeat> (and fix the missing quote):

<c:forEach items="#{bean.widgets}" var="widget">
    <p:panel binding="#{widget.contents}/>
</c:forEach>

This way you're also really generating physically multiple <p:panel> components instead of only one which get rendered multiple times.

Using JSTL may in turn however have other caveats, depending on the total picture which isn't clear from the question. See also JSTL in JSF2 Facelets... makes sense?

2012-04-05 17:05
by BalusC
Let me throw another layer of complexity on it then. These panels are each created with a primefaces tab which is dynamically created. So, c:forEach will fail since there is no tab at view build time (correct?). Also, yes, my bean is ViewScoped as well - user1269227 2012-04-05 17:21
Well, look for a different approach. E.g. dynamic includes, tag files or something, depending on the concrete functional requirements - BalusC 2012-04-05 17:21
My requirements are that I have 'n' number of panels I need displayed in a tab. Each panel has properties that can be changed that need to be pushed back to server (that only pertain to that panel). Each panel is bound to a pojo model that needs to be updated. I suspect I'm missing some fundamental building blocks regarding my JSF knowledge as I'm not sure how a dynamic include or custom component can be used to solve this. I appreciate your insight - user1269227 2012-04-05 17:58
I have tried already tried a couple different approaches. I've made all the UIComponents from the tabview down on the backend and bound them using "binding". This worked until I wanted to do some sort of ajax update on each panel and of course this failed. It's as if each panel needs it's own bean... but that's just sill,y it's at this point that I feel my approach is incorrect - user1269227 2012-04-05 19:13
Ads