You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Billy Bacon <bi...@thirty3.net> on 2003/09/16 00:27:38 UTC

How can I convert this to JSTL?

I'm hoping someone can help me out with this one.... I'm almost finished
converting the entire app :-)

I have a <c:forEach> loop and within the loop I have a scriptlet. Now I'm
aware that JSTL variables are *not* visible within scriptlets. So how would
I convert the following below... 'suggestionList' is the variable that I'm
having trouble with.

<c:forEach items="${SPELL_CHECK_SUGGESTIONS_BEAN}" var="suggestionList">

<% String[] suggs =
(String[])((java.util.Map.Entry)suggestionList).getValue();

....
%>

</c:forEach>


Re: How to get the size of a java.util.List object in EL?

Posted by Serge Knystautas <se...@lokitech.com>.
Adam,

JSP 2.0 introduces the notion of functions within EL, and in step with 
that release, JSTL 1.1 will include some standard functions including 
size.  There are early releases like Tomcat 5.0 and Resin 3.0 that give 
you some features of JSP 2.0, although I haven't tried either. 
Hopefully the specs will get finalized to get these standards out there 
soon.

-- 
Serge Knystautas
President
Lokitech >> software . strategy . design >> http://www.lokitech.com
p. 301.656.5501
e. sergek@lokitech.com

Adam Hardy wrote:
> Hi Billy,
> 
> I don't know about this one. Maybe someone more guru-like will step up 
> with an answer 8-)
> 
> I'm not quite sure why EL doesn't like this but I think it's because the 
> List class is not a javabean - presumably EL looks for getSize() rather 
> than the actual size(), but that doesn't explain why it's complaining 
> about an integer.
> 
> 
> Adam
> 
> 
> On 09/17/2003 02:19 AM Billy Bacon wrote:
> 
>> I need to get the size (as an int) of a java.util.List I have. The 
>> following
>> doesn't work....
>>
>> <c:out value="Size = ${browseForm.map.colInfoList.size}"/>
>>
>> It gives me the following exception...
>>
>> ServletException in:/jsp/browseQueueBody.jsp] An error occurred while
>> evaluating custom action attribute "value" with value "Size =
>> ${browseForm.map.colInfoList.size}": The "." operator was supplied 
>> with an
>> index value of type "java.lang.String" to be applied to a List or 
>> array, but
>> that value cannot be converted to an integer. (null)'
>>
>> Does anyone know how I could get the size of the List?
>>
>> - Billy -
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>>
>>
> 




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


Re: How to get the size of a java.util.List object in EL?

Posted by Serge Knystautas <se...@lokitech.com>.
Adam,

JSP 2.0 introduces the notion of functions within EL, and in step with 
that release, JSTL 1.1 will include some standard functions including 
size.  There are early releases like Tomcat 5.0 and Resin 3.0 that give 
you some features of JSP 2.0, although I haven't tried either. 
Hopefully the specs will get finalized to get these standards out there 
soon.

-- 
Serge Knystautas
President
Lokitech >> software . strategy . design >> http://www.lokitech.com
p. 301.656.5501
e. sergek@lokitech.com

Adam Hardy wrote:
> Hi Billy,
> 
> I don't know about this one. Maybe someone more guru-like will step up 
> with an answer 8-)
> 
> I'm not quite sure why EL doesn't like this but I think it's because the 
> List class is not a javabean - presumably EL looks for getSize() rather 
> than the actual size(), but that doesn't explain why it's complaining 
> about an integer.
> 
> 
> Adam
> 
> 
> On 09/17/2003 02:19 AM Billy Bacon wrote:
> 
>> I need to get the size (as an int) of a java.util.List I have. The 
>> following
>> doesn't work....
>>
>> <c:out value="Size = ${browseForm.map.colInfoList.size}"/>
>>
>> It gives me the following exception...
>>
>> ServletException in:/jsp/browseQueueBody.jsp] An error occurred while
>> evaluating custom action attribute "value" with value "Size =
>> ${browseForm.map.colInfoList.size}": The "." operator was supplied 
>> with an
>> index value of type "java.lang.String" to be applied to a List or 
>> array, but
>> that value cannot be converted to an integer. (null)'
>>
>> Does anyone know how I could get the size of the List?
>>
>> - Billy -
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>>
>>
> 




Re: How to get the size of a java.util.List object in EL?

Posted by Henri Yandell <ba...@generationjava.com>.
This has been on the list before I think. The recommended solution appears
to be to replace your List class with a ListBean which contains a getSize
method. Would probably be useful if Taglib project could have these
classes available for download. Anyone implemented these and feel like
offering them up?

Another option is to have a tag to get it. Maybe Xephyrus could add it to
their datastruct taglib:

http://www.xephyrus.com/taglib-datastructs/reference.html

Hen

On Wed, 17 Sep 2003, Adam Hardy wrote:

> Hi Billy,
>
> I don't know about this one. Maybe someone more guru-like will step up
> with an answer 8-)
>
> I'm not quite sure why EL doesn't like this but I think it's because the
> List class is not a javabean - presumably EL looks for getSize() rather
> than the actual size(), but that doesn't explain why it's complaining
> about an integer.
>
>
> Adam
>
>
> On 09/17/2003 02:19 AM Billy Bacon wrote:
> > I need to get the size (as an int) of a java.util.List I have. The following
> > doesn't work....
> >
> > <c:out value="Size = ${browseForm.map.colInfoList.size}"/>
> >
> > It gives me the following exception...
> >
> > ServletException in:/jsp/browseQueueBody.jsp] An error occurred while
> > evaluating custom action attribute "value" with value "Size =
> > ${browseForm.map.colInfoList.size}": The "." operator was supplied with an
> > index value of type "java.lang.String" to be applied to a List or array, but
> > that value cannot be converted to an integer. (null)'
> >
> > Does anyone know how I could get the size of the List?
> >
> > - Billy -
> >
> >
> > ---------------------------------------------------------------------
> > 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
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>


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


Re: How to get the size of a java.util.List object in EL?

Posted by Henri Yandell <ba...@generationjava.com>.
This has been on the list before I think. The recommended solution appears
to be to replace your List class with a ListBean which contains a getSize
method. Would probably be useful if Taglib project could have these
classes available for download. Anyone implemented these and feel like
offering them up?

Another option is to have a tag to get it. Maybe Xephyrus could add it to
their datastruct taglib:

http://www.xephyrus.com/taglib-datastructs/reference.html

Hen

On Wed, 17 Sep 2003, Adam Hardy wrote:

> Hi Billy,
>
> I don't know about this one. Maybe someone more guru-like will step up
> with an answer 8-)
>
> I'm not quite sure why EL doesn't like this but I think it's because the
> List class is not a javabean - presumably EL looks for getSize() rather
> than the actual size(), but that doesn't explain why it's complaining
> about an integer.
>
>
> Adam
>
>
> On 09/17/2003 02:19 AM Billy Bacon wrote:
> > I need to get the size (as an int) of a java.util.List I have. The following
> > doesn't work....
> >
> > <c:out value="Size = ${browseForm.map.colInfoList.size}"/>
> >
> > It gives me the following exception...
> >
> > ServletException in:/jsp/browseQueueBody.jsp] An error occurred while
> > evaluating custom action attribute "value" with value "Size =
> > ${browseForm.map.colInfoList.size}": The "." operator was supplied with an
> > index value of type "java.lang.String" to be applied to a List or array, but
> > that value cannot be converted to an integer. (null)'
> >
> > Does anyone know how I could get the size of the List?
> >
> > - Billy -
> >
> >
> > ---------------------------------------------------------------------
> > 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
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>


Re: How to get the size of a java.util.List object in EL?

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Hi Billy,

I don't know about this one. Maybe someone more guru-like will step up 
with an answer 8-)

I'm not quite sure why EL doesn't like this but I think it's because the 
List class is not a javabean - presumably EL looks for getSize() rather 
than the actual size(), but that doesn't explain why it's complaining 
about an integer.


Adam


On 09/17/2003 02:19 AM Billy Bacon wrote:
> I need to get the size (as an int) of a java.util.List I have. The following
> doesn't work....
> 
> <c:out value="Size = ${browseForm.map.colInfoList.size}"/>
> 
> It gives me the following exception...
> 
> ServletException in:/jsp/browseQueueBody.jsp] An error occurred while
> evaluating custom action attribute "value" with value "Size =
> ${browseForm.map.colInfoList.size}": The "." operator was supplied with an
> index value of type "java.lang.String" to be applied to a List or array, but
> that value cannot be converted to an integer. (null)'
> 
> Does anyone know how I could get the size of the List?
> 
> - Billy -
> 
> 
> ---------------------------------------------------------------------
> 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


Re: How to get the size of a java.util.List object in EL?

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Hi Billy,

I don't know about this one. Maybe someone more guru-like will step up 
with an answer 8-)

I'm not quite sure why EL doesn't like this but I think it's because the 
List class is not a javabean - presumably EL looks for getSize() rather 
than the actual size(), but that doesn't explain why it's complaining 
about an integer.


Adam


On 09/17/2003 02:19 AM Billy Bacon wrote:
> I need to get the size (as an int) of a java.util.List I have. The following
> doesn't work....
> 
> <c:out value="Size = ${browseForm.map.colInfoList.size}"/>
> 
> It gives me the following exception...
> 
> ServletException in:/jsp/browseQueueBody.jsp] An error occurred while
> evaluating custom action attribute "value" with value "Size =
> ${browseForm.map.colInfoList.size}": The "." operator was supplied with an
> index value of type "java.lang.String" to be applied to a List or array, but
> that value cannot be converted to an integer. (null)'
> 
> Does anyone know how I could get the size of the List?
> 
> - Billy -
> 
> 
> ---------------------------------------------------------------------
> 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


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


How to get the size of a java.util.List object in EL?

Posted by Billy Bacon <bi...@thirty3.net>.
I need to get the size (as an int) of a java.util.List I have. The following
doesn't work....

<c:out value="Size = ${browseForm.map.colInfoList.size}"/>

It gives me the following exception...

ServletException in:/jsp/browseQueueBody.jsp] An error occurred while
evaluating custom action attribute "value" with value "Size =
${browseForm.map.colInfoList.size}": The "." operator was supplied with an
index value of type "java.lang.String" to be applied to a List or array, but
that value cannot be converted to an integer. (null)'

Does anyone know how I could get the size of the List?

- Billy -


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


How to get the size of a java.util.List object in EL?

Posted by Billy Bacon <bi...@thirty3.net>.
I need to get the size (as an int) of a java.util.List I have. The following
doesn't work....

<c:out value="Size = ${browseForm.map.colInfoList.size}"/>

It gives me the following exception...

ServletException in:/jsp/browseQueueBody.jsp] An error occurred while
evaluating custom action attribute "value" with value "Size =
${browseForm.map.colInfoList.size}": The "." operator was supplied with an
index value of type "java.lang.String" to be applied to a List or array, but
that value cannot be converted to an integer. (null)'

Does anyone know how I could get the size of the List?

- Billy -


Re: How can I convert this to JSTL?

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
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


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


Re: How can I convert this to JSTL?

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
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


Re: How can I convert this to JSTL?

Posted by Billy Bacon <bi...@thirty3.net>.
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...


Re: How can I convert this to JSTL?

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
<c:set var="suggsArray" value="${suggestionList.value}"/>

or were you really asking how you can access an EL variable in a scriplet?



Sorry but I'm off to bed now anyway.

Adam

On 09/16/2003 12:27 AM Billy Bacon wrote:
> I'm hoping someone can help me out with this one.... I'm almost finished
> converting the entire app :-)
> 
> I have a <c:forEach> loop and within the loop I have a scriptlet. Now I'm
> aware that JSTL variables are *not* visible within scriptlets. So how would
> I convert the following below... 'suggestionList' is the variable that I'm
> having trouble with.
> 
> <c:forEach items="${SPELL_CHECK_SUGGESTIONS_BEAN}" var="suggestionList">
> 
> <% String[] suggs =
> (String[])((java.util.Map.Entry)suggestionList).getValue();
> 
> ....
> %>
> 
> </c:forEach>
> 
> 
> ---------------------------------------------------------------------
> 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