struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ted Husted" <>
Subject Re: [Struts 2] problem with s:set and s:if
Date Sun, 17 Sep 2006 20:54:05 GMT
Personally, for something like this, I try to simplify the task as
much as possible in the Action. For example, I might put this sort of
a loop in the Action class and create a list of milestone numbers,
each with it's onw list of milestone items. So that the page can just
iterate through the numbers, and the items for each milestone, so that
the page doesn't have to work so hard.

Given a list of milestone numbers on the page, each containing its own
ist of milestone items, if it were me, I'd try something like

<s:iterator value="$milestoneNumbers">
   <s:property value="%{milestone.number}"/>
       <s:property value="%{milestone.tentativeDate}"/>
    <td width="80%" align="left">
    <s:iterator value=$milestoneItems>
       <li><s:property value="%{feature}" escape="false"/></li>

Of course, in the end, there will be the same amount of logic, it's
just a matter of where the logic is being applied. A key benefit of
applying as much logic as possible in the Action class, is that it's
much easier to test and step-thru the code, without getting the web
container involved.

-- HTH, Ted.

On 9/17/06, Garner Shawn <> wrote:
> I'm not sure what I'm doing wront but I only want to write out the
> table row and table data tags if it is a new milestone different than
> the last one.
> I seem to get either all or none here.
> Can somebody help me?
> <table border="1"
>                 cellspacing="0" cellpadding="4" bordercolor="#000000" width="100%"
> class="greyBackgroundClass">
>         <tr>
>                 <th>Milestone</th><th>Tentative Release Date</th><th>Features</th>
>         </tr>
>                 <s:set name="milestoneTemp" value="%{-1}" scope="page"/>
>                 <s:set name="newMilestone" value="%{false}" scope="page"/>
>                 <s:iterator value="#session.releaseList">
>                                 <s:if test="%{milestoneTemp != milestone.number}">
>                                         <s:set name="milestoneTemp"  value="%{milestone.number}"
>                                         <s:set name="newMilestone" value="%{true}"
>                                 </s:if>
>                                 <s:else>
>                                         <s:set name="newMilestone" value="%{false}"
>                                 </s:else>
>                                         <s:if test="%{newMilestone == true}">
>                                         <tr>
>                                         <td>
>                                                 <s:property value="%{milestone.number}"/>
>                                         </td>
>                                         <td>
>                                                 <s:property value="%{milestone.tentativeDate}"/>
>                                         </td>
>                                         <td width="80%" aling="left">
>                                         <ul>
>                                         </s:if>
>                                                 <li><s:property value="%{feature}"
>                                         <s:if test="%{newMilestone == true)">
>                                         </ul>
>                                         </td>
>                                 </tr>
>                                         </s:if>
>                 </s:iterator>
>         </table>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

HTH, Ted.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message