Expression Language in Java Server Faces

F

fastcars

I am trying to render a page using the latest versions of
MyFaces/tomahawk. (1.1.4)

I had a question re a nested data structue. I have a structure that has
A list of categories, Each category may have items and subcategories,
and the subcategories have items as well.

So what I have done, is have a row index var at the top level which I
then use in subsequent EL index expressions further on.

ie

value="#{PortalBean.portalpage.categories[catIdx].subcategories}"

This gets an 'catIdx' unresolved attribute in the debug log and doesnt
work.

Is this to be expected ?

What other options do I have to render this data structure?
As far as I can see I need nested datatables.


What is the correcty approach ?






<t:dataTable value="#{PortalBean.portalpage.categories}"
cellpadding="1" cellspacing="0"
var="cats" styleClass="timetable" rowIndexVar="catIdx">
<t:column>
<t:div >
<t:dataTable
value="#{PortalBean.portalpage.categories[catIdx].categoryitems}"
cellpadding="1" cellspacing="0"
var="item" >
<h:commandLink action="#{item.itemhref}" >
<t:graphicImage url="#{item.iconhref}"
rendered="#{item.rendericon}"></t:graphicImage>
<h:eek:utputLabel value="#{item.itemname}"></h:eek:utputLabel>
</h:commandLink>
</t:dataTable>
<t:dataTable
value="#{PortalBean.portalpage.categories[catIdx].subcategories}"
cellpadding="1" cellspacing="0"
var="subcat" rowIndexVar="scatIdx">
<t:column id="header">
<h:eek:utputText value="#{subcat.categoryname}"/>
</t:column>
<t:dataTable
value="#{PortalBean.portalpage.categories[catIdx].subcategories[scatIdx].categoryitems}"

cellpadding="1" cellspacing="0" var="item" >
<h:commandLink action="#{item.itemhref}" >
<t:graphicImage url="#{item.iconhref}"
rendered="#{item.rendericon}"></t:graphicImage>
<h:eek:utputLabel value="#{item.itemname}"></h:eek:utputLabel>
</h:commandLink>
</t:dataTable>
</t:dataTable>

</t:div>
</t:column>
</t:dataTable>
 
H

hiwa

fastcars said:
I am trying to render a page using the latest versions of
MyFaces/tomahawk. (1.1.4)

I had a question re a nested data structue. I have a structure that has
A list of categories, Each category may have items and subcategories,
and the subcategories have items as well.

So what I have done, is have a row index var at the top level which I
then use in subsequent EL index expressions further on.

ie

value="#{PortalBean.portalpage.categories[catIdx].subcategories}"

This gets an 'catIdx' unresolved attribute in the debug log and doesnt
work.

Is this to be expected ?

What other options do I have to render this data structure?
As far as I can see I need nested datatables.


What is the correcty approach ?






<t:dataTable value="#{PortalBean.portalpage.categories}"
cellpadding="1" cellspacing="0"
var="cats" styleClass="timetable" rowIndexVar="catIdx">
<t:column>
<t:div >
<t:dataTable
value="#{PortalBean.portalpage.categories[catIdx].categoryitems}"
cellpadding="1" cellspacing="0"
var="item" >
<h:commandLink action="#{item.itemhref}" >
<t:graphicImage url="#{item.iconhref}"
rendered="#{item.rendericon}"></t:graphicImage>
<h:eek:utputLabel value="#{item.itemname}"></h:eek:utputLabel>
</h:commandLink>
</t:dataTable>
<t:dataTable
value="#{PortalBean.portalpage.categories[catIdx].subcategories}"
cellpadding="1" cellspacing="0"
var="subcat" rowIndexVar="scatIdx">
<t:column id="header">
<h:eek:utputText value="#{subcat.categoryname}"/>
</t:column>
<t:dataTable
value="#{PortalBean.portalpage.categories[catIdx].subcategories[scatIdx].categoryitems}"

cellpadding="1" cellspacing="0" var="item" >
<h:commandLink action="#{item.itemhref}" >
<t:graphicImage url="#{item.iconhref}"
rendered="#{item.rendericon}"></t:graphicImage>
<h:eek:utputLabel value="#{item.itemname}"></h:eek:utputLabel>
</h:commandLink>
</t:dataTable>
</t:dataTable>

</t:div>
</t:column>
</t:dataTable>
Your catIdx should bes a registered property of a registered managed
bean on your faces-config.xml file. It's access in an EL should be:
myMbean.catIdx
And of course your bean should have get/set method for catIdx property.
 
F

fastcars

hiwa said:
fastcars said:
I am trying to render a page using the latest versions of
MyFaces/tomahawk. (1.1.4)

I had a question re a nested data structue. I have a structure that has
A list of categories, Each category may have items and subcategories,
and the subcategories have items as well.

So what I have done, is have a row index var at the top level which I
then use in subsequent EL index expressions further on.

ie

value="#{PortalBean.portalpage.categories[catIdx].subcategories}"

This gets an 'catIdx' unresolved attribute in the debug log and doesnt
work.

Is this to be expected ?

What other options do I have to render this data structure?
As far as I can see I need nested datatables.


What is the correcty approach ?






<t:dataTable value="#{PortalBean.portalpage.categories}"
cellpadding="1" cellspacing="0"
var="cats" styleClass="timetable" rowIndexVar="catIdx">
<t:column>
<t:div >
<t:dataTable
value="#{PortalBean.portalpage.categories[catIdx].categoryitems}"
cellpadding="1" cellspacing="0"
var="item" >
<h:commandLink action="#{item.itemhref}" >
<t:graphicImage url="#{item.iconhref}"
rendered="#{item.rendericon}"></t:graphicImage>
<h:eek:utputLabel value="#{item.itemname}"></h:eek:utputLabel>
</h:commandLink>
</t:dataTable>
<t:dataTable
value="#{PortalBean.portalpage.categories[catIdx].subcategories}"
cellpadding="1" cellspacing="0"
var="subcat" rowIndexVar="scatIdx">
<t:column id="header">
<h:eek:utputText value="#{subcat.categoryname}"/>
</t:column>
<t:dataTable
value="#{PortalBean.portalpage.categories[catIdx].subcategories[scatIdx].categoryitems}"

cellpadding="1" cellspacing="0" var="item" >
<h:commandLink action="#{item.itemhref}" >
<t:graphicImage url="#{item.iconhref}"
rendered="#{item.rendericon}"></t:graphicImage>
<h:eek:utputLabel value="#{item.itemname}"></h:eek:utputLabel>
</h:commandLink>
</t:dataTable>
</t:dataTable>

</t:div>
</t:column>
</t:dataTable>
Your catIdx should bes a registered property of a registered managed
bean on your faces-config.xml file. It's access in an EL should be:
myMbean.catIdx
And of course your bean should have get/set method for catIdx property.



This didnt fix the problem

added to PortalBean


public int getcatidx(){ return new this.categoryIndex;}
public int getscatidx() { return this.itemIndex;}

public void setcatidx(int idx){ this.categoryIndex = idx;}
public void setscatidx(int idx) { this.itemIndex = idx;}

getCatIdx got called twice then there was an exception 500 mentioning
java.lang.Integer
Changed signature on get and set to integer , and function didnt get
called, and rendering of page hung (timed out)

This leaves me to believe
a) what I am doing is not supported functionality
b) I am out of ideas attempting to render the data in a sensible
fashion in JSF. It took me an hour or so to create a great looking page
using a bean and JSP. Days later with JSF and I am still wondering what
the best approach is. For simple pages JSF adds value, as the dataset
becomes more complex and rendering conditional on many data items, the
effort and verbosity of the presentation layer in JSF gets in the way
of getting product delivered.

Even if this does work in JSF, and I am sure this is possible, the code
I have in JSP is very simple and the UI looks great and takes very
little time to build.

I had a notion that maybe I could create components that lived in a jar
that I could drop on the page and render a complex dataset. I attempted
to build a component, and it looked like I needed

a) a tag class
b) a UI Conmponent class
c) a renderer.

This is just too hard. There needs to be a layer over the top that
hides much of the complexity. I dont have time to peruse the myfaces
source code to determine exactly what I need. The examples I have seen
are fairly trivial, all dont handle EL expressions for tag attributes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top