tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Hardy <ahardy.str...@cyberspaceroad.com>
Subject Re: How can I convert this to JSTL?
Date Tue, 16 Sep 2003 08:11:00 GMT
Can't you replace the whole scriptlet? c:forEach supports iterating over 
arrays as well, so you change the for loop into a c:forEach.

I'm not clear what you are trying to achieve with the javascript Array() 
  - what is the parameter meant to be? A sequence of values or an index? 
It looks like you should lose the quotes around the parameter.

How about:

<c:forEach items="${SPELL_CHECK_SUGGESTIONS_BEAN}"
        var="suggestionList"
        varStatus="count">
  suggestions[<c:out value="${count.index}"/>] =
     new Array("<c:out value='${suggestionList.key}'/>");
  <c:set var="suggs" value="${suggestionList.value}" />
  <c:forEach items="suggs" var="myVar1" varStatus="count2">
      suggestions[<c:out value="${count.index}"/>][<c:out 
value="${count2.index}"/>] =
        "<c:out value="${myVar1}"/>";
  </c:forEach>
</c:forEach>


Interesting problem! Good luck,

Adam


On 09/16/2003 04:16 AM Billy Bacon wrote:
> Yea, I need to access the 'suggestionList' EL variable from within a
> scriplet. I don't prefer to use scriplets in my JSPs but in this case I
> don't think I can get around it because this loop that I'm in is creating
> javascript.
> 
> Here's what the JSP currently looks like...
> 
> 
> <script language="javascript">
> <!--
> 
> var suggestions = new Array();
> var replaceWin = null;
> 
> <c:forEach items="${SPELL_CHECK_SUGGESTIONS_BEAN}" var="suggestionList"
> varStatus="count">
> suggestions[<c:out value="${count.index}"/>] = new Array("<c:out
> value='${suggestionList.key}'/>");
> <% String[] suggs =
> (String[])((java.util.Map.Entry)suggestionList).getValue();
> 
> int len = suggs.length;
> for (int i=0; i < len; i++) {
> %>
>     suggestions[<c:out value="${count.index}"/>][<%= i+1 %>] = "<%= suggs[i]
> %>";
> <%
> }
> %>
> </c:forEach>
> 
> ....
> 
> </script>
> 
> 
> This use to work when I had the <logic:iterate> Struts tag that defined the
> suggestionList variable since that allowed scriplets to access it...
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
> 
> 

-- 
struts 1.1 + tomcat 4.1.27 + java 1.4.2
Linux 2.4.20 RH9


Mime
View raw message