How can we access the bean attribute in JSP?
I tried
<core:forEach var="header" items="${command.headerList}" >
<td><core:out value="${header.columnName}"/></td>
</core:forEach>
where headerList is the list of myBean which is having the attribute columnName [ getter / setter are defined in the class ]
Looks fine. What happens instead?
also how can i access the nth element in the List? i tried
${command.headerList[i]}
Looks fine as long as i is initialized and in scope. What happens instead?
When i write
${command.headerList}
it displays
com.bean.MyBean@14ecb90, com.bean.MyBean@169b35, com.bean.MyBean@27d572
It should include [ in the front and ] in the tail, but for the remnant it looks fine as long as you didn't override Object#toString() in MyBean class. What had you expected?
and when i write
${header}
inside the forEach loop it displays:
javax.servlet.jsp.el.ImplicitObjectELResolver$ImplicitObjects$7@d9d714
Looks fine. What had you expected?
Summarized: I don't understand your problem. Please elaborate more. Post an SSCCE. Tell about the expected input/output. Tell about the actual input/output.
Edit you've edited your question. Well, here are the updated answers.
${header.columnName}
Expected: it should print the value in columnName
Actual: it is not printing anything at all
Then it actually didn't contain a value. To test it properly, override Object#toString() something like as follows:
public String toString() {
return "header[" + columnName + "]";
}
And test it using ${command.headerList}. You can also add some System.out or Logger statement to the getter method to see if it is actually invoked and actually returned a value. Or if you understand how to use it, just run a code debugger. Every decent IDE ships with one.
Next:
${command.headerList[i]}
Output: nothing displayed.
Then there's no means of a valid i. To test it properly, do the following to get the first item:
${command.headerList[0]}