• Post Reply Bookmark Topic Watch Topic
  • New Topic

Scriplets in the tag attribute  RSS feed

 
Aparna Reguri
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a custom tag which has the attribute called name, if I directly assign some value using the scriplet it is rendered correctly . But if want to concatenate it with some string and then pass it as an attribute it is not rendered properly.

Example:

<%@ taglib uri="/hello" prefix="examples" %>
<html>
<head>
<title>First custom scripting tag</title>
</head>
<body>

<%
String name="SR1";
String cout = "sample_"+ name;
%>

<examples:test name="<%=name%>" />
<examples:test name="sample_"+<%=name%> />

</body>
</html>

My Tag Handler class just prints the name

<examples:test name="<%=name%>" /> is prints the name successfully.

But when I want to append something to it print using <examples:test name="sample_"+<%=name%> />, then there is a JspException Unterminated <examples:test tag
Is this a wrong of doing or how I can this be achieved.

I know that using <cut> it is possible by I don't want it to be assigned to some variable like cout in the above example and keep this same in some jstl scope.


Thanks in Advance!!!


Thanks and Regards
Aparna Reguri






 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aparna Reguri wrote:I know that using <c:out> it is possible by I don't want it to be assigned to some variable like cout in the above example and keep this same in some jstl scope.


Why not?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not be using scriptlets at all in your JSP pages at this point in time. Scriptlets and Java code in JSP pages has been discredited for almost 9 years now. It's time to move on.

That said, when you use scriptlet expressions as attribute values to custom tags, the scriptlet expression must be the entire value -- it cannot be just part of a value expression such as you are attempting to use.
 
Aparna Reguri
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear Bibeault for your reply.
Going forward will take care of the code indentation. Sorry for inconvenience

Also for the
That said, when you use scriptlet expressions as attribute values to custom tags, the scriptlet expression must be the entire value -- it cannot be just part of a value expression such as you are attempting to use.
is there any documentation or any sort of article which says this, as I have to give justification for this.

Thanks in Advance!!!


Thanks and Regards
Aparna
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can search through the JSP Specification for it -- but really, what other justification other than it doesn't work do you need?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!