File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes How to pass parameter to custom tag from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to pass parameter to custom tag from JSP" Watch "How to pass parameter to custom tag from JSP" New topic
Author

How to pass parameter to custom tag from JSP

kim pham
Greenhorn

Joined: May 11, 2011
Posts: 13
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

Joined: Jul 06, 2005
Posts: 1029
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

Joined: May 11, 2011
Posts: 13
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

Joined: Jul 06, 2005
Posts: 1029
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.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to pass parameter to custom tag from JSP