I have a variable defined within a JSP:
<%
String cust_id = request.getParameter("cust_id");
%>
I want to use this variable as a parameter to a custom tag:
<%@ taglib uri="/tlds/DBTags.tld" prefix="db" %>
<db:MultiColumnSelect columns="c.id, c.po" name="ccar_id" table_name="ccar_headers c, ccar_rmas r" selectString="r.ccar_id = c.id AND c.cust_id = <%= cust_id %>"/>
The selectString value that is passed to my tag is:
r.ccar_id = c.id AND c.cust_id = <%= cust_id %>
The <%= cust_id %> is not replaced by the actual variable value.
How would I accomplish using this variable within my JSP tag?
Discussions
Web tier: servlets, JSP, Web frameworks: Using a script variable as an attribute for a JSP tag
-
Using a script variable as an attribute for a JSP tag (6 messages)
- Posted by: Tom Cole
- Posted on: August 27 2003 07:59 EDT
Threaded Messages (6)
- Using a script variable as an attribute for a JSP tag by Paul Strack on August 27 2003 11:05 EDT
- Using a script variable as an attribute for a JSP tag by Tom Cole on August 27 2003 12:32 EDT
-
Using a script variable as an attribute for a JSP tag by Paul Strack on August 27 2003 03:19 EDT
-
Using a script variable as an attribute for a JSP tag by Tom Cole on August 27 2003 03:21 EDT
-
Using a script variable as an attribute for a JSP tag by Paul Strack on August 27 2003 03:50 EDT
- Many Thanks... by Tom Cole on August 31 2003 11:41 EDT
-
Using a script variable as an attribute for a JSP tag by Paul Strack on August 27 2003 03:50 EDT
-
Using a script variable as an attribute for a JSP tag by Tom Cole on August 27 2003 03:21 EDT
-
Using a script variable as an attribute for a JSP tag by Paul Strack on August 27 2003 03:19 EDT
- Using a script variable as an attribute for a JSP tag by Tom Cole on August 27 2003 12:32 EDT
-
Using a script variable as an attribute for a JSP tag[ Go to top ]
- Posted by: Paul Strack
- Posted on: August 27 2003 11:05 EDT
- in response to Tom Cole
You can't mix and match scripting and fixed text inside custom tag attributes. The solution is to assemble your value in a different variable, and pass *that* to the attribute:
<%
String cust_id = request.getParameter("cust_id");
String selectString = "r.ccar_id = c.id AND c.cust_id = " + cust_id;
%>
<db:MultiColumnSelect columns="c.id, c.po" name="ccar_id" table_name="ccar_headers c, ccar_rmas r" selectString="<%= selectString %>"/> -
Using a script variable as an attribute for a JSP tag[ Go to top ]
- Posted by: Tom Cole
- Posted on: August 27 2003 12:32 EDT
- in response to Paul Strack
Thanks for your help. I tried the folowing:
<%
String select = "cust_id = " + cust_id;
%>
<db:MultiColumnSelect name="ccar_id" columns="id, po" separator=" -P.O.# " table_name="ccar_headers" selectString="<%=select%>"/>
And I still got the error. It appears that they way the tags are processed, they will not allow this type of variable usage. In the above example, the selectString that was passed to my tag was : <%=select%> not the contents of select....
Oh well, I went ahead and switched it over to a servlet. Works fine now. But all told, that really sucks. The usefulness of tags to me without this capability is 1/3 of what it could be.... -
Using a script variable as an attribute for a JSP tag[ Go to top ]
- Posted by: Paul Strack
- Posted on: August 27 2003 15:19 EDT
- in response to Tom Cole
The tag developer can explicitly exclude run-time expression values like <%=...%> in tag attributes. This is probably what happened in your case.
This kind of database logic is better off in a servler or a helper Java class anyway. -
Using a script variable as an attribute for a JSP tag[ Go to top ]
- Posted by: Tom Cole
- Posted on: August 27 2003 15:21 EDT
- in response to Paul Strack
I'm the tag developer....
My purpose for this tag was to provide a means for html developers who have some SQL knowedge to incorporate some read-only information into their webpages without having to learn the whole J2EE thing...
My Boss here is quite capable in the html arena, but forget trying to get him to write scriplets or servlets or anything of the kind. -
Using a script variable as an attribute for a JSP tag[ Go to top ]
- Posted by: Paul Strack
- Posted on: August 27 2003 15:50 EDT
- in response to Tom Cole
Oh! If you are the tag developer, then simply go into the tag library descriptor and change the attribute configuration:
<attribute>
<name>[attribute-name]</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
By setting rtexprvalue to true, you should be able to use runtime expression values, that is <%=...%> scriptlets, to assign tag attribute values. -
Many Thanks...[ Go to top ]
- Posted by: Tom Cole
- Posted on: August 31 2003 11:41 EDT
- in response to Paul Strack
Thanks a ton for the help. I'm learning JSP, Servlet and Tag development through through a book titled "Java for the Web with Servlets, JSP and EJB. Although it's a great book, sometimes the information gets detached, i.e creating custom tags and the .tld descriptor.
Thanks again.