You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Garner Shawn <sh...@gmail.com> on 2006/09/17 21:20:26 UTC

[Struts 2] problem with s:set and s:if

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}"  scope="page"/>
					<s:set name="newMilestone" value="%{true}"  scope="page"/>
				</s:if>
				<s:else>
					<s:set name="newMilestone" value="%{false}" scope="page"/>
				</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}" escape="false"/></li>
					<s:if test="%{newMilestone == true)">
					</ul>
					</td>
				</tr>
					</s:if>
	    	</s:iterator>
    	</table>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [Struts 2] problem with s:set and s:if

Posted by Ted Husted <hu...@apache.org>.
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">
 <tr>
  <td>
   <s:property value="%{milestone.number}"/>
   </td>
    <td>
       <s:property value="%{milestone.tentativeDate}"/>
     </td>
    <td width="80%" align="left">
    <ul>
    <s:iterator value=$milestoneItems>
       <li><s:property value="%{feature}" escape="false"/></li>
    </s:iterator>
    </ul>
</td>
</tr>
</s:iterator>

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.
* http://www.husted.com/struts/


On 9/17/06, Garner Shawn <sh...@gmail.com> 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}"  scope="page"/>
>                                         <s:set name="newMilestone" value="%{true}"  scope="page"/>
>                                 </s:if>
>                                 <s:else>
>                                         <s:set name="newMilestone" value="%{false}" scope="page"/>
>                                 </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}" escape="false"/></li>
>                                         <s:if test="%{newMilestone == true)">
>                                         </ul>
>                                         </td>
>                                 </tr>
>                                         </s:if>
>                 </s:iterator>
>         </table>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
HTH, Ted.
* http://www.husted.com/struts/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org