I have defined a custom tag to take one parameter, a number, which it then uses to look up some information and return. I keep getting a NumberFormatException though. I am passing the number to the tag in my jsp by use of a EL.
<my:myTag id="${action.id}"/>
In the bean class for Action :
private int id;
private void setId(int id){
this.id = id;
}
private int getId(){
return id;
}
In my custom tag handler :
private int id;
//getters and setters for id
public int doStartTag() throws JSPException {
//Does some stuff with id
}
In my tld (omitted some stuff) :
<attribute>
<name>id</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
The tag does what I want it to if I just pass a number in (ie, id=”6″) but always throws the exception when I try to use the EL expression value. Is there some int-string conversion happening somewhere when the expression is evaluated or something? It is an int field in the bean and I assumed it would just get passed through as such? I have tried changing the attribute of my tag handler to String and Integer and neither have resolved this. I have set rtexprvalue to true so it should be evaluating it fine. Any help appreciated.
OK, this is the longer version of my comment above…
In JSP 1.x, the JSP engine did not know anything about the expression language. The EL was defined as part of JSTL, but it was built in to the tags themselves, the engine didn’t get involved in the evaluation.
In JSP 2.0, the EL was moved into the JSP spec, and the engine supports it. In JSP 2.1, the EL was merged with the JSF EL.
So, if you’re using JSP 1.x, then you have to do the EL yourself.
But, just to make things more complicated, in JSP 2.0 the API for customer tag handlers was simplified. In JSP 1.x, tags implemented
Tag, but in JSP 2.0 tags implementSimpleTag.A JSP 2.x engine will support JSP 1.x style tags (classes implementing
Tag) but will treat them in the same way that JSP 1.x treated them – the EL is not evaluated by the engine, and the tag will need to explicitly evaluate it.As for
rtexprvalue, this actually controls whether a scriptlet expression is supported, and not whether an EL expression is supported (that attribute pre-dates the EL).