On Wed, 19 Jan 2005 18:25:55 -0800, Kishore Senji <[EMAIL PROTECTED]> wrote:
> On Wed, 19 Jan 2005 18:49:52 -0600, [EMAIL PROTECTED]
> <[EMAIL PROTECTED]> wrote:
> > I need to know an additional question:
> > You sent me:
> >
> > <c:forEach items="${sessionScope.auditorList}" var="auditor" 
> > varStatus="status">
> >
> > I need to know if this would be correct as well, where 
> > creditApplicationListDto.businessLine is a Boolean:
> >
> > <c:forEach items="${creditApplicationListDto.businessLine}" var="true" 
> > varStatus="status">
> 
> Nope. "items" should evaluate to a collection.
> In JSTL it would be something like the below code to solve your
> problem (I haven't tested it, Just wrote it on top of my head)
> 
> <c:if test="${creditApplicationListDto.businessLine}">
>   <bean:message key="label.bln"/>
>   <c:set var="found" value="true"/>
> </c:if>
> <c:if test="${creditApplicationListDto.businessCard}">
>   <c:choose>
>      <c:when test="${found}">
>        ,&nbsp;<bean:message key="label.bcard"/>
>      </c:when>
>      <c:otherwise>
>        <bean:message key="label.bcard"/>
>        <c:set var="found" value="true"/>
>      </c:otherwise>
>   </c:choose>
> </c:if>
> <c:if test="${creditApplicationListDto.securedCard}">
>   <c:choose>
>      <c:when test="${found}">
>        ,&nbsp;<bean:message key="label.seccard"/>
>      </c:when>
>      <c:otherwise>
>        <bean:message key="label.seccard"/>
>        <c:set var="found" value="true"/>
>      </c:otherwise>
>   </c:choose>
> </c:if>
> <c:if test="${creditApplicationListDto.equipmentExpress}">
>   <c:choose>
>      <c:when test="${found}">
>        ,&nbsp;<bean:message key="label.equipExpress"/>
>      </c:when>
>      <c:otherwise>
>        <bean:message key="label.equipExpress"/>
>        <c:set var="found" value="true"/>
>      </c:otherwise>
>   </c:choose>
> </c:if>
> 
> Look how large the chunk of code is. 

You can also do it like this 

<%
  Map map = new HashMap();
  if(creditApplicationListDto.getBusinessLine()){ // assuming that you
make the "creditApplicationListDto" available as a scripting variable
    map.put("label.bln", creditApplicationListDto.getBusinessLine());
  }
  if(creditApplicationListDto.getBusinessCard()){
      map.put("label.bcard", creditApplicationListDto.getBusinessCard());
  }
  if(creditApplicationListDto.getSecuredCard()){
      map.put("label.seccard", creditApplicationListDto.getSecuredCard());
  }
  if(creditApplicationListDto.getEquipExpress()){
      map.put("label.equipExpress", creditApplicationListDto.getEquipExpress());
  }
  pageContext.setAttribute("map", map);
%>

<c:forEach items="${map.keySet}" var="key" varStatus="status">
  <c:choose>
    <c:when test="${not status.last}"><bean:write
message="${map[${key}]}"/>,&nbsp;</c:when>
    <c:otherwise><bean:write message="${map[${key}]}"/></c:otherwise>
  </c:choose>
</c:forEach>

All we did here is to create a collection which holds only the "true"
values. Note that you can do this in the DTO if you want to and expose
the collection through a getter

> Better way of doing it is by
> having some sort of an utility method or using a tag as "Jim"
> suggested
> 
> >
> > --------------------
> > Mick Knutson
> > Wells Fargo Business Direct
> > (415) 222-1020
> >
> > "This message may contain confidential and/or privileged information. If 
> > you are not the addressee or authorized to receive this for the addressee, 
> > you must not use, copy, disclose, or take any action based on this message 
> > or any information herein. If you have received this message in error, 
> > please advise the sender immediately by reply e-mail and delete this 
> > message. Thank you for your cooperation."
> > --------------------
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> > Sent: Friday, January 14, 2005 11:18 AM
> > To: Struts Users Mailing List
> > Subject: Re: Help with logic tags, and commas please.
> >
> > Not exactly the same, since I have use of a list but here's how I handled
> > it in JSTL...
> >
> >      <c:forEach items="${sessionScope.auditorList}" var="auditor"
> > varStatus="status">
> >
> >            <c:if test="${!status.last}">
> >                  <c:out value="${auditor.name}"/>,&nbsp
> >            </c:if>
> >
> >            <c:if test="${status.last}">
> >                  <c:out value="${auditor.name}"/>
> >            </c:if>
> >
> >      </c:forEach>
> >
> > Bart
> >
> > <[EMAIL PROTECTED]> wrote on 01/14/2005 02:04:07 PM:
> >
> > > I have the following code that prints something like this:
> > > BLN, BCard, SecCard, EquipExp
> > >
> > > There may be any combination of any of these 4 items, or non at all.
> > > And what I want is the ability to properly add commas after each
> > > item, or not print a comma if there is not an item:
> > >
> > > <logic:equal name="creditApplicationListDto" property="businessLine"
> > > value="true">
> > >     <bean:message key="label.bln"/>&nbsp;,
> > > </logic:equal>
> > > <logic:equal name="creditApplicationListDto" property="businessCard"
> > > value="true">
> > >     <bean:message key="label.bcard"/>&nbsp;,
> > > </logic:equal>
> > > <logic:equal name="creditApplicationListDto" property="securedCard"
> > > value="true">
> > >     <bean:message key="label.seccard"/>&nbsp;,
> > > </logic:equal>
> > > <logic:equal name="creditApplicationListDto"
> > > property="equipmentExpress" value="true">
> > >     <bean:message key="label.equipExpress"/>&nbsp;
> > > </logic:equal>
> > >
> > >
> > > --------------------
> > > Mick Knutson
> > > Wells Fargo Business Direct Information Systems
> > > (415) 222-1020
> > >
> > > "This message may contain confidential and/or privileged
> > > information. If you are not the addressee or authorized to receive
> > > this for the addressee, you must not use, copy, disclose, or take
> > > any action based on this message or any information herein. If you
> > > have received this message in error, please advise the sender
> > > immediately by reply e-mail and delete this message. Thank you for
> > > your cooperation."
> > > --------------------
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to