| Author |
Converting request parameters to JSP tag-file attributes
|
Madhumitha Subramanian
Greenhorn
Joined: Nov 09, 2009
Posts: 7
|
|
I have a JSP that invokes a tag-file with some attributes as defined in the tag-file. I want to convert the request parameters that I receive for this JSP as attributes to the tag-file dynamically. For eg., If my JSP file is sample.jsp and it's contents are :
And I receive attr1,attr2 as request parameters in my JSP - say /sample.jsp?attr1=value1&attr2=value2..., How do I pass on the same as attributes to the tag-file?
I tried using JSTL tags in the JSP to generate run-time attributes like below, but no luck!
When I try the above code, I get
"Expression language not allowed in a template text body."
I've declared the tag's body-content as "scriptless" with dynamic-attributes enabled. As rtexprvalue of a JSP attribute defaults to true, I don't understand why this exception occurs. Any help would be greatly appreciated!
|
 |
Sudhakar Sharma
Ranch Hand
Joined: Apr 04, 2009
Posts: 71
|
|
|
are you passing parameter to that jsp? try <jsp:param> tag, I am also confussed in your question talking about parameter or attribute.
|
 |
Frits Walraven
Rancher
Joined: Apr 07, 2010
Posts: 1064
|
|
Hi Madhumitha,
"Expression language not allowed in a template text body."
With the <jsp:attribute> you are defining attributes for the enclosing <c:forEach> tag, and if you do that you have to define a <jsp:body> (because the body of <c:forEach> is not defined as empty)...
I guess you want to add the parameter names and parameter values as attribute names and attribute values to the <tag:showTag>, don't you? Can you show us your tld entry or tag-file and your showTag implementation?
Have you thought of this construction?
Regards,
Frits
|
 |
Madhumitha Subramanian
Greenhorn
Joined: Nov 09, 2009
Posts: 7
|
|
Hi Sudhakar and Fritz,
Thanks for the replies.
@Sudhakar
When I try the jsp:param, I get
"The jsp:param action must not be used outside the jsp:include, jsp:forward, or jsp:params elements"
Quite expected, as I want them to be passed on as attributes to the showTag tag and not as parameters.
@Fritz
With the <jsp:attribute> you are defining attributes for the enclosing <c:forEach> tag, and if you do that you have to define a <jsp:body> (because the body of <c:forEach> is not defined as empty)
Alrite, this din't strike me before. So what I want to achieve looks quite impossible now Anyways, I want to add parameter name as attribute name and the parameter's value as attribute's value to the tag-file.
So when I make a request like /sample.jsp?attr1=value1&attr2=value2&...
I want to convert this to : <tag:showTag attr1=value1 attr2=value2/> in the JSP file
And my showTag.tag file is something like this :
Trust I was clear. Any possible solution to this?
|
 |
Frits Walraven
Rancher
Joined: Apr 07, 2010
Posts: 1064
|
|
Any possible solution to this?
Well I am still not sure what you are trying to do with this <tag:showTag>. What should the jsp do with the parameter names and parameter values? If you would have posted your implementation I could have suggested a solution. It seems you didn't like the one I posted earlier?
What about this one (making use of dynamic attributes in a tag-file)
The JSP-file:
and the tag-file
with a url of:
having a result of:
name attr2
value b
name attr1
value a
Regards,
Frits
|
 |
 |
|
|
subject: Converting request parameters to JSP tag-file attributes
|
|
|