• Post Reply Bookmark Topic Watch Topic
  • New Topic

C:If tag doubt.

 
Pradeep Kumar
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can i use the c for each tag for a String array. Will the following below piece of codew work if listOfIds is a String[] type and if it does not work for String array will it work for List object(if the listOfIds is a List object instead of a String array.)

I have a hidden field in my form object.

<c:forEach var="id"
items="${requestScope.myForm.listOfIds}">
<input type="hidden" name="listOfIds" value="<cut value='${id}'/>">
</c:forEach>
[ December 11, 2007: Message edited by: Ben Souther ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, if you'd look at the JSTL specification, you'd see that the forEach tag does work with arrays. Both arrays of objects and arrays of primitives. So you're ok there.
Then, could you check the following :
1. Are sure about requestScope.myForm.listOfIds ? What is myForm in the requestScope ?
2. You are giving the same name to all hidden tags. Is it ok ?
 
Pradeep Kumar
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So are you sure the items attribute of C:ForEach tag works fine with String array.

for example this piece of snippet where the listOfIds are of type String array.

<c:forEach var="id" items="${requestScope.listOfIds}">
<input type="hidden" name="listOfValidatedIds" value="<cut alue='${id}'/>">
</c:forEach>
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. If listOfIds is an array of String in the request scope, no problem. Do you have any particular error ?
By the way, you're still giving the same name to your hidden tags ;)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!