wood burning stoves 2.0*
The moose likes JSF and the fly likes Jsf problem with iteration in a page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSF
Bookmark "Jsf problem with iteration in a page" Watch "Jsf problem with iteration in a page" New topic
Author

Jsf problem with iteration in a page

John Cuzzola
Greenhorn

Joined: Jul 14, 2011
Posts: 3
Hello everybody,

I am looking to solve what on paper seems an easy problem but I spend a few hours yesterday and I was not able to come to a conclusion.

I am trying to iterate over a list in a jsf, the catch is, whatever tag I use I can't have it spitting out any html at all.

I have tried a combination of jstl and jsf, but they don't mix, it does not let me re-use what I set in the var in the jstl loop inside my jsf tag.
Also, I tried jsp scriptlet and jsf, but f:param does not allow me to enter any expression like this <%=
In production, we don't have facelets installed so it will be hard for me to push to get it installed.

Do you have any idea or can you send me to the right direction...

thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16095
    
  21

Welcome to the JavaRanch, John!

JSF is a very pure implementation of the MVC design paradigm. In MVC, logic belongs in the Controller, not in the View. In other words, not in the web page, in scriptlets, in JSTL (which, as you're discovered, don't work well in JSF), not in JavaScript, or whatever.

JSF is also abstract. If you look at the docs for the dataTable control, for example, I don't think you'll find the words "loop" or "iterate" anywhere in there. A dataTable is a 2-dimensional rendering of data, and the mechanism used to enumerate that data isn't important.

I'm unclear on what the actual abstract goal you have in mind, however. We recently had someone else with a similar question, so you may want to search around this forum and see if that thread helps.


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

Joined: Jul 14, 2011
Posts: 3
Sorry I was not clear, I understand how mvcs work.
I have a list
I want to "loop" and create <divs> with inside a commandlink and a image. Inside the commandlink I have to pass a couple of f:param (which are iterated in the list).
We used to use datatables but it generates html tables, while I don't want any html beside the divs I create in the loop.

I hope it makes clear.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16095
    
  21

I thought the whole anti-table jihad thing died out years ago. JSF is an abstract framework and I no more care what sort of HTML comes out of it than I do which assembly-language instructions Java uses to execute code. As long as the display comes out proper, only PHBs with nothing more constructive to do (like, say, maybe ensuring that apps are truly secure) and nerds have any reason to care.

Sorry, you touched a nerve. Besides, if ideology is going to drive things, my own policy is to not embed HTML in JSF Views at all. It mucks up the JSF renderer, which is supposed to be operating independent of the display medium selected. So I use JSF panelGrids and let the renderer worry about whether a 1x1 panelGrid should come out as a table, div, or something completely other.

Nevertheless. If you absolutely MUST do divs, use the ui:repeat Facelets tag. Assuming there's not an edict about that one too.
John Cuzzola
Greenhorn

Joined: Jul 14, 2011
Posts: 3
Well, I know what you mean about table vs divs. I am a software developer, so I could not care less which one I use, but I work for a big company and that was a requirements from the designer so my hands are tight.
I found a solution with facelets, but funny thing, I cannot use it either. It is a major website and to add a library it is a pain to get approval.
that's the reason why I tried scriptlet and it did not work either. I don't have many options.
 
GeeCON Prague 2014
 
subject: Jsf problem with iteration in a page