3

Is there any way of iterating over a list in JSF 1.2 without using any third party components? I know I can do it using Tomahawk. I also know that it can be done using JSTL, but I am keeping that as my last resort. Also I cannot use <ui:repeat> since we are using JSF 1.2. Is there any elegant way like <ui:repeat> to do it in jsf 1.2?

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
RegisteredUser
  • 380
  • 6
  • 18

1 Answers1

8

The only JSF 1.2 component which can iterate over a List is the <h:dataTable>.

In JSP, the only other "standard" (i.e. not "3rd party") tag which can iterate over a List is the JSTL <c:forEach>. Using JSTL shouldn't harm that much if the List which you'd like to iterate over is already available during view build time. You'll only run into trouble when it's only available during view render time, for example because it's been nested in a <h:dataTable> and should be iterating over a property of table's var. This just won't work due to reasons also mentioned in JSTL in JSF2 Facelets... makes sense?

There are no other ways without using a 3rd party library such as Tomahawk's <t:dataList>, unless you're open to reinventing the wheel by creating a custom UIComponent yourself. This is however not a trivial job.

It's however possible to integrate Facelets 1.x in JSF 1.2. A guide is described in the Facelets 1.x docbook. This is only going to be quite some of work if you already have an existing JSF application using JSP as view technology; you'd need to convert JSP to Facelets. But it'll in end make the upgrade path to JSF 2.x so much easier. See also a.o. Migrating from JSF 1.2 to JSF 2.0 and Why Facelets is preferred over JSP as the view definition language from JSF2.0 onwards?

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • 1
    Thank you for this depressing piece of information... Why oh why am I trapped in JSF 1.2!!?! – jahroy Oct 02 '12 at 19:46
  • @Jah: Just integrate Tomahawk and use ``. Any business restriction which says that you may not use a 3rd party component library such as Tomahawk is plain stupid. – BalusC Oct 02 '12 at 19:50
  • @BalusC, I tried doing it like ' #{abc} ' but it doesnt work. – RegisteredUser Oct 02 '12 at 19:55
  • 1
    @nvy: you need a `` to specify a table column. Also, unlike in Facelets, you can't use deferred EL in template text in JSP, so you should really use `` for the `#{abc}`. So, all with all, this should do: ``. See also the Java EE 5 tutorial: http://docs.oracle.com/javaee/5/tutorial/doc/bnarf.html#bnarz – BalusC Oct 02 '12 at 19:59