It's not a secret anymore!*
The moose likes Struts and the fly likes Problem with IndexId attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem with IndexId attribute" Watch "Problem with IndexId attribute" New topic
Author

Problem with IndexId attribute

Vivek Choudhary
Greenhorn

Joined: Jan 30, 2008
Posts: 4
Hi All..
I am new to struts and having a problem with IndexId attribute of iterate..
I have to edit the marks of courses of some students..
so first i have to display the marks and courses and then submit new marks..


----my jsp code(editMarks.jsp)--------



---------my Form Bean(StudentMarksFrom.java)---------



------------my Action Form(StudentMarksAction.java)---------



-----Struts-confix.xml--------



I m getting an error "javax.servlet.ServletException: Exception thrown by getter for property course[0] of bean org.apache.struts.taglib.html.BEAN"

can anyone help me..
thanks in advance..
Alaa Nassef
Ranch Hand

Joined: Jan 28, 2008
Posts: 460
Hello Vivek,

You have some mistakes in your JSP. Let's just explain the logic:iterate first. First of all, the id attribute is a name given to the current element of the collection you are iterating on. This means that if you are iterating on a collection named collection and you put the value of the id attribute as element, then at the first iteration, element will have the value of collection[0], and so on.

The indexId attribute is just a name of a variable that will act as a counter variable so that you can use it in your JSP for several reasons (for example if you are displaying results in rows, you can give a style to even rows, and another to odd ones), but not to get the element from the collection, since it's already there.

Now, your collection is in the action form, and that's a little tricky. Here, the name attribute should be the name of your form (I guess as defined in the struts config file), and the property attribute should be the name of the collection property in that form. I usually prefer putting my collections in a request attribute rather than in the form class.

I hope this helps. Please try and tell me the result


Visit my blog: http://jnassef.blogspot.com/
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problem with IndexId attribute
 
Similar Threads
problem in converting from session scope to request scope in struts
Indexed Setting/properties
logic:iterate exception null pointer exception
Dynamic iterate checkbox
Indexed Properties with List of Strings