Ok, I figured out that <f:param> and <h:outputText> cannot use the var
attribute of <tr:forEach>. Replacing <h:outputText> with <tr:outputText>
fixed that problem, but I don't know how to fix <f:param> problem -
there does not seem to be an equivalent <tr:??> tag.
Naresh
P.S. Earlier I was using a <tr:commandLink> with a <tr:setActionListener
to get a similar functionality. However it was causing an extra read
from my database which I am trying to eliminate. Here's the earlier
implementation (forumListBean and forumDetailsBean are in request scope
- I do not want them in session scope - which admitedly will make the
implementation a lot simpler, but again I Want my session to be as light
as possible):
<h:form>
<div>
<tr:forEach var="forum" items="#{forumListBean.forums}">
<tr:commandLink immediate="true" text="#{forum.title}"
action="showForum">
<tr:setActionListener
from="#{forum.id}"
to="#{forumDetailsBean.forumId}"/>
</tr:commandLink>
</tr:forEach>
</div>
</h:form>
-----Original Message-----
From: Naresh Bhatia [mailto:[EMAIL PROTECTED]
Sent: Friday, November 24, 2006 11:02 AM
To: [email protected]
Subject: Generating links with request parameters in a <tr:forEach> loop
I am trying to generate links with request parameters in a <tr:forEach>
loop. Here's the desired output:
<a href="/forums/ShowForum.jsf?forumId=1">Forum 1</a> <br/>
<a href="/forums/ShowForum.jsf?forumId=2">Forum 2</a> <br/>
<a href="/forums/ShowForum.jsf?forumId=3">Forum 3</a> <br/>
What is the easiest way to do this? I have tried the following:
<h:form>
<div>
<tr:forEach var="forum" items="#{forumListBean.forums}">
<h:outputLink
value="#{facesContext.externalContext.requestContextPath}/ShowForum.jsf"
>
<f:param name="forumId" value="#{forum.id}" />
<h:outputText value="#{forum.title}" />
</h:outputLink>
</tr:forEach>
</div>
</h:form>
This simply produces:
<a href="/forums/ShowForum.jsf?forumId="></a>
Obviously, the forum id and forum title are not substituted.
Naresh