• Post Reply Bookmark Topic Watch Topic
  • New Topic

Brain burp! Can't get the right Data Grid layout  RSS feed

 
Alan Biggs
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've been doing JSF for a while now, and I've encountered a hitch which I can't seem to get my mind around.

I recently built a prototype which used a panelGrid to show static items in a grid layout with 4 columns. Items 1 - 4 in the first row, 4 - 8 in the second, etc.

Now I want to dynamically populate the grid with data items (a List) from a managed bean. So the panelGrid must be replaced with a dataGrid, right?

Only now the dataGrid shows one item per row, so I can't reproduce the panelGrid layout I have in the prototype.

So what to do?

As I see it, I have three or four options:

1. Build a ton of logic into my bean to allow me to iterate through the items in the the List one at a time. Surely this shouldn't be necessary.

2. Integrate JSTL into my web page and use it to iterate through the List with a <c:forEach/>. (I read an article on devx.com explaining this,
http://www.devx.com/Java/Article/21020/0/page/1
but I tried it with luck so far. JSTL doesn't seem to read the List from the session. Any code examples would be really helpful! I'll post what I have if this helps you to help me!)

3. Use a third-party 'data-aware' JSF component that supports this layout option. Any suggestions?

4. Use some clever JSF expressions to access the items offset from the current one, like #{MyBean.listItems[n+1]}, but I haven't really researched this one too much as to know if it's even possible.

Number 2 is my prefered option at the moment.

TIA for your input.

[ August 13, 2005: Message edited by: Alan Biggs ]

[ August 13, 2005: Message edited by: Alan Biggs ]
[ August 13, 2005: Message edited by: Alan Biggs ]
 
Alan Biggs
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Progress on option 2 above:
One thing I discovered is that JSTL is now version 1.1 and the URL to use is updated from the article above:
xmlns:c="http://java.sun.com/jsp/jstl/core"

I've looked at some JSTL integration threads. What doesn't seem clear to me yet is whether I can mix and match JSTL tags with JSF tags.

For example, I got this to work in a test page, but it will not work in my more complex subview tile:

<h :p anelGrid columns="2" border="1">
<c:forEach
items="${sessionScope.MainPageBean.documentTypes}"
var="docType">
<f:verbatim>
<c ut value="${docType.title}"/>
</f:verbatim>
<f:verbatim>
<c ut value="${docType.description}"/>
</f:verbatim>
</c:forEach>
</h :p anelGrid>

Can anyone point me towards any guidelines or Dos and Don'ts for combining JSTL and JSF?

My only remaining option I believe will be to implement my own custom JSF component.
[ August 14, 2005: Message edited by: Alan Biggs ]
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The guideline for using JSLT and JSF on the same page is DON'T. JSF wasn't built to support this and while it may work some of the times, you'll find it to be more bug prone than what you want.

Most things that JSTL accomplish for you can be taken care of in the backing bean coupled with components attributes on the jsp.

As to your problem, I'm not I completely understand what you are trying to do. From what you said, I am getting that you have a table. And every 2 rows of this table is a single record? Is that correct? If so, my question is why does it need to be this way? If we are on the same page, we can go from here.
 
Alan Biggs
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg,

Thanks for your response.

I had read some posts mentioning that JSTL and JSF worked well together to give some basic level of control flow in the page. (Even that the JSF team had INTENDED that they be used together.)

So I'm a little surprized that you say don't do it.

What I am trying to do is slightly different from what you said.
For each row of my table I want to display up to 4 records.
So if I have 10 items in my backing bean List, they will be displayed in 2 and a half rows, grid fashion. I guess similar to how you would see files in icon view in your file system explorer.

Why does it have to be this way? I am following a precise design done my my graphic designer colleague which I would like to implement.

This is how I do it in my prototype/mock-up:



Obviously I want to replace the repeating <htm:div styleClass="ICON"> block with a repeating block which will render as many divs as I have items in my List.

The only way I can see of doing this is with a <h:dataTable/> but that restricts me to using one item per row.

(Please also note that I am using tiles, so this panelGrid is a subordinate of another container, which may add some complications.)

What would you suggest?
 
Alan Biggs
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah-Ha!

The MyFaces Newspaper Table component seems to be what I want.

Strangely named and hidden under the Tomahawk tab (why do they do this?) I finally found what I'm looking for.

Will be looking at changing my JSF RI to MyFaces in the near future.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!