• Post Reply Bookmark Topic Watch Topic
  • New Topic

Issue with c:forEach

 
krish chaitu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

Iam using the jstl c:forEach to display the List & getting the following error when trying to use the list as below

<c:forEach var="list" items="${list }"></c:forEach>
<tr><td><cut value="${list.gci}" /></td></tr>

getting the following error
An error occurred while evaluating custom action attribute "value" with value "${list.getGci}": 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).


How to display the values from the list that are added from the DTO object to the list.

Please help me .....

Thanks
krish
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it's a list, why are you trying to obtain a property from it rather than an indexed element?

It can't be both a list and a bean.
 
krish chaitu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your reply,but how can i display it on my jsp for one field.

I have 4 elements in the list that are added from DTO object & i need to display those valuesin a jsp


Thanks
krish
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your list is called list and you named your indiviual items list also -- why?

Use a differnt scoped varible name for the list items.
[ October 31, 2007: Message edited by: Bear Bibeault ]
 
krish chaitu
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I dont think this will work, since i have 2 fields in my database & 2 fields in my dto ,so if i have to display the value for one element in jsp that has a list of elements & the same for the other element i have to display the list from the same list.

Please explain me in detail..
Thanks
krish
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Once again, you can;t use the same scoped variable name to mean two different things. Code this something like:

 
Hemant Sharma
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Apart from the change suggested by Bear, you need to make one more change in your code. If we see the below code


<c:forEach var="list" items="${list }"></c:forEach>
<tr><td><cut value="${list.gci}" /></td></tr>


the row is outside the c:forEach tag, it should be within the c:forEach tag.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Hemant Sharma:
the row is outside the c:forEach tag, it should be within the c:forEach tag.

Good catch... that didn't jump out at me.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!