File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Iterating tags in Seam (ui:repeat and c:forEach)

 
Denis Zjukow
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Having struggled for a couple of days I finally gave up and decided to ask for help.

I use Seam with Facelets. What I want is to show a list of entities in a table cell i.e a single cell may contain a comma-separted list.

Let's say I have two entity types: Item and Subitem. An instance of type Item may have a number of Subitems. In my case the relation between these two entity types is many-to-many.

So if I have Item1 with three subitems: Subitem1, Subitem2 and Subitem3, I want to see something like this:



Please note that I don't want a comma after the last subitem in a cell (Subitem3 in this case). Nothing special, an obvious requierment, isn't it?

The first thing I tried was ui:repeat:



Everything's fine except for the fact that there is a nasty comma after the last subitem. This made me try c:forEach tag:



Unfortunately this code won't work! It just leaves my favorite column empty. It seams that c:forEach do not see variable item.
I then tried to find a way to add the conditional logic to ui:repeat, but haven't managed to find anything like c:forEach's 'varStatus'.

Any ideas? Thank you all in advance!
 
K Bbb
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use <ui:fragment rendered="#{conditional}">

also you could render the 1st item outside the loop, then set the start index to 1 on the loop and then in the loop render the comma first, then the loop item

finaly you can move the code into the java side and don't loop at all..
 
K Bbb
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
also.. most of the time it doesn't work to mix c: tags with h: tags, c: tags are compile time, h: tags are render time. you can sometimes put an h: tag inside a c: tag, but not the other way.
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess, the JSF forum is the right place for this question. You might get more answers there. I will move this there for you.
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"K Bbb",

Great information there, but please change your display name to meet the JavaRanch Naming Policy of using your real first and real last names, thanks

Mark
 
Denis Zjukow
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, K Bbb. I like the idea of conditional rendering. That's exactly what I was looking for.

However, it just seems strange to me that there is nothing like c:forEach among built-in facelet tags. I wish ui:repeat had same functionality as c:forEach, but it unfortunately doesn't.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic