my dog learned polymorphism
The moose likes JSP and the fly likes Custom tags help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Custom tags help" Watch "Custom tags help" New topic

Custom tags help

sebastian pettersson

Joined: Apr 08, 2005
Posts: 3
I am trying to create a custom tag that generates the code for an HTML table in this manner:

Here the tag draws a table of no more than 3 coloumns and as many rows as it takes to include all items. And in each cell of the table the value of currentBean.aProperty is printed.

The tag is defined through a tag file:

So the table generating code works, i've come that far. What doesn't work is the line: "${currentBean.aProperty}" in the jsp code. This Exception is thrown:

javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to find a value for "aProperty" in object of class "java.lang.String" using operator "."

So apparently the container sees currentBean as a String object instead of a bean. If I change the EL expression to "${currentBean}" no exception is thrown and it evaluates to the fully specified classname of currentBean.

Can anyone help to get it working like i want it too with code like the first code snippet?

Thanks in advance,

[ April 10, 2005: Message edited by: sebastian pettersson ]
seb petterson
Ranch Hand

Joined: Mar 04, 2005
Posts: 118
Ok, so now i realize that the value of the variable "items", as it is declared in the jsp, is receieved as a String in the tag. And the forEach loop is probably just iterating over a set of substring elements separated by some token in the Collection's toString() value. Hence the call throwing the exception looks something like this:

So the question is how to define a custom tag (through a tag file preferably) that takes a bean (or any non-String value) variable.

Any feedback is appreciated, even if you don't know the answer.

sebastian pettersson

Joined: Apr 08, 2005
Posts: 3
Matter resolved:

I agree. Here's the link:
subject: Custom tags help
It's not a secret anymore!