• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass parameter to custom tag from JSP

 
kim pham
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Wanted to pass parameter to custom tag as below but the JSP crashed.
<msg:myCustomTag tagName="tagName1" dataType= "<%= ed.getDataType %>" />
Is that the correct syntax?
Thank in advance for the help
JP
 
Stefan Evans
Bartender
Posts: 1784
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How have you defined your custom tag? With a simple .tag file or in java classes?
Check the log for an error message. That will tell you more.
It looks like you might be missing the parentheses () from the method call in your scriptlet expression?

Providing "ed" is a bean in an attribute scope, you should be able to also do the EL equivalent:
(ie if you created it with useBean, or set an appropriate attribute)

<msg:myCustomTag tagName="tagName1" dataType= "${ed.dataType}" />


What is the type returned by getDataType? Unless you specify otherwise, attributes to a tag are expected to be strings.
 
kim pham
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response.
in my jsp
<%
Map data = (Map) request.getAttribute("data");
Customer ed = (Customer ) data.get("defaults");
%>

ed.dataType() return int

<msg:myCustomTag tagName="tagName1" dataType= "${ed.dataType()}" /> Didn't work either.
Thanks,
 
Stefan Evans
Bartender
Posts: 1784
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And the error message you are seeing is?

Also, it is recommended that you stop using scriptlets.

ed is a scriptlet variable not an EL expression.
But you are getting it from a request attribute, so the equivalent JSTL would be:



or just ${data.defaults.dataType}

provided that all of the appropriate values are there.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic