Using scriplets in jsp-tag attribute

I have a strange problem with a custom taglibrary that I'm trying to write.
When I use the tag in a jsp like underneath the first outputs the right value (Welcome Hans), but the output of the second time shows: Welcome <%= test %>
This is a part of the JSP:
<% String test = "Hans"; %>
<arto:hello name="Hans" />
<arto:hello name="<%= test %>" />
I realy don't know how to let the tag display the value of the string in my jsp.
Can anyone give me some advice?
Thanks,
Hans
The files are:
import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class HelloTag extends TagSupport {
private String name;
public void setName(String name) {
this.name = name;
public int doStartTag() throws JspException {
try {
pageContext.getOut().print("Welcome " +name);
} catch (IOException ioe) {
throw new JspException("Error: IOException while writing to client");
return SKIP_BODY;
public int doEndTag() throws JspException {
return SKIP_PAGE;
The JSP:
<%@ taglib uri="arto" prefix="arto" %>
<%
String test = "Hans";
%>
<arto:hello name="<%= test %>" />
<arto:hello name="Hans" />
The TLD:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname></shortname>
<uri></uri>
<info></info>
<tag>
<name>hello</name>
<tagclass>HelloTag</tagclass>
<bodycontent>empty</bodycontent>
<info>Tag with Parameter</info>
<attribute>
<name>name</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
</taglib>

In the tld for the name attribute, use
<rtexprvalue>true</rtexprvalue>
This specifies that the attribute value can be a run-time expression. Otherwise, the value is taken as a literal.

Similar Messages

  • How can i use JSTL inside custom tag attribute

    Hi,
    I have one button tag which displays the button with round corner. I will show the button like this:
    <ep:button key="buttons.submit" name="submitBtn" styleClass="But"
              onClick='submitPage(''<c:out value='${buttonName}' />)' />
    I am getting the problem with the above code. how can i use JSTL inside the custom tags.
    Thanks in Advance,
    LALITH

    No. The details are given below:
    I have included the follwing line in web.xml file:
    <taglib>
        <taglib-uri>/tags/button</taglib-uri>
        <taglib-location>/WEB-INF/button.tld</taglib-location>
      </taglib>button.tld file
    <taglib>
         <tlibversion>1.0</tlibversion>
         <jspversion>2.0</jspversion>
         <shortname>button</shortname>
         <tag>
              <name>button</name>
              <tagclass>com.ksi.ep.web.taglib.ButtonTag</tagclass>
              <bodycontent>empty</bodycontent>
              <attribute>
                   <name>name</name>
                   <required>true</required>
                   <rtexprvalue>false</rtexprvalue>
              </attribute>
              <attribute>
                   <name>key</name>
                   <required>true</required>
                   <rtexprvalue>true</rtexprvalue>
              </attribute>
              <attribute>
                   <name>onClick</name>
                   <required>true</required>
                   <rtexprvalue>true</rtexprvalue>
              </attribute>
    </taglib>ButtonTag.java :
    public class ButtonTag extends TagSupport {
       private static final long serialVersionUID = 6837146537426981407L;
         * Initialise the logger for the class
        protected final transient Log log = LogFactory.getLog(ButtonTag.class);
         *  holds the Value of the button tag
        protected String onClick = null;
         *  holds message resources key
        protected String key = null;
         * The message resources for this package.
        protected static MessageResources messages =
                             MessageResources.getMessageResources
                                       ("ApplicationResources");
          *  (non-Javadoc)
          * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
         public int doStartTag() throws JspException {    
            StringBuffer label = new StringBuffer();         
            HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
            try {             
                   log.debug("in doStartTag()");
                   Locale locale = pageContext.getRequest().getLocale();
                 if (locale == null) {
                     locale = Locale.getDefault();
                 log.info("");
                 label.append("<a border=\"0\" style=\"text-decoration:none;color:#FFFFFF\" href=\"JavaScript:");
                 label.append(onClick);
                 label.append("\" >");
                   label.append("<table  onClick=\"");
                   label.append(onClick);               
                   label.append("\" ");
                   if(onmouseout!=null && !"".equalsIgnoreCase(onmouseout))
                    label.append(" onmouseout=\"");
                    label.append(onmouseout);               
                    label.append("\" ");
                   if(onmouseover!=null && !"".equalsIgnoreCase(onmouseover)){
                    label.append(" onmouseover=\"");
                    label.append(onmouseover);               
                    label.append("\" ");
                   if(title!=null && !"".equalsIgnoreCase(title)){
                    label.append(" title=\"");
                    label.append(title);               
                    label.append("\" ");
                   label.append("style=\"cursor:hand\" tabindex=\"1\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" background=\"");
                   label.append(request.getContextPath());
                   label.append(System.getProperty("file.separator"));
                   label.append("images");
                   label.append(System.getProperty("file.separator"));
                   label.append("background1.jpg\" > ");
                 label.append("<tr><td width=\"10\"><img  border=\"0\" src=\"");
                 label.append(request.getContextPath());
                   label.append(System.getProperty("file.separator"));
                   label.append("images");
                   label.append(System.getProperty("file.separator"));
                 label.append("leftcorner.jpg\" ></td> ");
                 label.append("<td valign=\"middle\"  style=\"padding-bottom:2px\"><font color=\"#FFFFFF\" style=\"");
                 label.append(styleClass);
                 label.append("\">");
                 label.append(messages.getMessage(key));
                 label.append("</font></td>");
                 label.append("<td width=\"10\" align=\"right\"><img src=\"");
                 label.append(request.getContextPath());
                   label.append(System.getProperty("file.separator"));
                   label.append("images");
                   label.append(System.getProperty("file.separator"));            
                 label.append("rightcorner.jpg\" border=\"0\"  ></td>");
                 label.append("</tr></table></a>");
                 pageContext.getOut().print(label.toString());
              } catch (Exception e) {               
                   log.error("Exception occured while rendering the button", e);
                   throw new JspException(e);
            return (SKIP_BODY);
         * Release all allocated resources.
        public void release() {       
            this.name=null;
            this.key=null;
            this.onClick=null;
    }In my JSP I have mentioned the taglib directive as
    <%@ taglib uri="/tags/button" prefix="ep"%>and
    <ep:button key="buttons.submit" name="submitBtn" styleClass="But"
         onClick='overwritePreApprovals('<c:out value='${transactionalDetails['inPrepList']}' />')' />Servlet.service() for servlet action threw exception
    org.apache.jasper.JasperException: /pages/pms/coordinator/Dashboard.jsp(325,48) Unterminated <ep:button tag
    Thanks,
    LALITH

  • Problem with scriplet variable as tag attribute

              This question was already treated here but it doesn't help me.
              I have a .jsp page where I am using a custom tag written by me like this :
              <%! String thecategory= request.getParameter("category");%>
              <gamemarket:listpost category="<%= thecategory %>">
              </gamemarket:listpost>
              Even with no white spaces after %>, it doesn't work .
              WEB logic JSP compiler always keep generating the error message :
              "unclosed string literal". .
              Please help. Its very urgent.
              

    What version of WLS are you using?
              "chris" <[email protected]> wrote in message
              news:3c7b75b0$[email protected]..
              >
              >
              > This question was already treated here but it doesn't help me.
              >
              > I have a .jsp page where I am using a custom tag written by me like this
              >
              > <%! String thecategory= request.getParameter("category");%>
              > <gamemarket:listpost category="<%= thecategory %>">
              > </gamemarket:listpost>
              >
              > Even with no white spaces after %>, it doesn't work .
              >
              >
              > WEB logic JSP compiler always keep generating the error message :
              > "unclosed string literal". .
              >
              > Please help. Its very urgent.
              

  • Problem with boolean attribute of JSP tag

    Hi,
    I've being trying to use a custom JSP tag, which has a boolean attribute, declared in the TLD as follows:
    <attribute>
    <name>checked</name>
    <required>false</required>
    <rtexprvalue>true</rtexprvalue>
    <type>boolean</type>
    </attribute>
    The JSP code snippet is:
    <ui:check checked="<%= myBean.isChecked() %>"/>
    where myBean.isChecked() returns a boolean value (primitive type).
    It works fine on some web containers, but it causes a JSP compilation error on Oracle9iAS 9.0.3 Java Edition, which looks like the following:
    Method toBoolean(boolean) not found in class test. _jsp_taghandler_57.setChecked( OracleJspRuntime.toBooleanObject( toBoolean( myBean.isChecked())));
    After decompiling the container's JSP parser, I found what I think it's a bug. The java class generated by the JSP parser does not define a toBoolean method, and neither do its superclasses. The method is defined on the OracleJspRuntime class! I think the correct code would have to be something like:
    OracleJspRuntime.toBooleanObject(OracleJspRuntime.toBoolean(...))
    If I'm correct, then the "convertExpression" method of the "oracle.jsp.parse.JspUtils" class must be changed, because it outputs such wrong code for not just boolean types, but for all the primitive types.
    So, has anyone ever faced this problem before? Does it have a workaround, or a patch? Is it included on the bug fixes for the 9.0.4 release?
    Thanks!

    Instead of:
    out.println("<body onload ="+strAlert+">");
    Try this:
    out.println("<body onload =\""+strAlert+\"">");
    Add two \" around the alert call.

  • Updating tag attributes in design time

    I have a design time renderer for my custom component... As the component renders itself in design time, I set some of the component properties from within the renderer... The property sheet correctly shows those values... However, the associated JSP tag in the source view does not show those attributes... The JSP tag attributes dictate the runtime behavior and since they are not set properly, my component misbehaves.
    How do I make sure that the tag attributes sync up with the property sheet values?
    Also, what is the motivation behind the property sheet displaying the component values and not the JSP tag values? Having it the way it is right now opens itself up to a bunch of out-of-sync problems like the one I encountered.
    Thanks,
    Keyur

    Ok - here are a couple of scenarios:
    1. I have a component, say chart component associated with a connection component like this:
    <my:connection id="connection1" />
    <my:chart connectionId="connection1" />The user first drags and drops the connection component. The ID connection1 is automatically associated to it. Next he drops the chart component. Now, I would like to automatically populate the connectionId attribute without the user having to type it in manually. I am able to do that (in design time) in the renderer of the chart component - I programmatically look for a connection component on the page and set the connectionId attribute of the control. And when I do that it correctly shows the connectionId attribute populated in the property sheet but the corresponding tag attribute is not.
    Sure enough, at runtime, it is the tag attribute values that count and since those are not updated by the IDE, it does not work as expected.
    2. Creator updates the style attribute when I move or resize the component. Now, I also have position attributes left and top defined on my component and I use these attributes at runtime to position my component. So, in design time I extract the left and top values from the style attribute and set them on the component. But again, the tag attributes are not populated and so the component is not positioned properly.
    #1 is to convenience the user so that he doesn't have to manually enter values for attributes which can be automatically populated at design time.
    In fact for #1, I would ideally like to show the user a drop down list of all the connections available to him in the property sheet and select the first one by default. Is this possible?
    #2 is for backward compatibility reasons - We already have runtime renderers in place which use left and top attributes explicitly to render the components at runtime. And this is not restricted to left and top only but other client attributes as well - such as borders, backgrounds etc. which we expose as separate attributes.

  • Variable Substitution with tag attribute

    Hi,
    is possible to use variable substitution with tag attribute? as follow:
    <root directory="xxx"  filename="yyy">
       <....
    </root>
    using variable substitution for directory : root,1,directory,1
                                                               root,1,filename,1

    Hi,
    I solved my problem using Dynamic Configuration to set the FileName and Directory fields in Adapter Specific Configuration. To use Variable Substitution only accept element in XML.
    Thanks for all.

  • New JSP Tags in WLS 7

              Hi!
              Can someone summarize for me additional custom WebLogic JSP tags available in
              WLS 7, compared to WLS 6.1 or changes in functionality of existing custom WebLogic
              JSP tags from WLS 6.1 to WLS 7.
              Thanks,
              Rahul.
              

              I am afraid not. Becuase if you don't buy their product, they even don't let you use their classes of that product.
              I tried to use a class inside CommerceServer, but they asked for the license all the time.
              My suggestion is you can get some idea from that, but don't use it directly except you have their license.
              "KhurramZ" <[email protected]> wrote:
              >Hi all,
              >Am experimenting with WL server 5.1 (eval version) and ejbs,jsp's.
              >Also came across documentation of JSP Tag libraries of WL personalization
              >server (in BEA website). (like <pz:..> , <cm:..>, <es:...>)
              >
              >Can I use those WLPS jsp tag libs in WLserver? Though I havent got WLPS ,and
              >in fact will not be using it in future.
              >
              >Thanx in advance
              >Khurram Z
              >[email protected]
              >
              >
              

  • EP 6 SP2 and Domino JSP Tag library

    I have been able to establish DIIOP connection between EP6 and Domino based on the workaround posted in this form. Calling the lotus.domino.* classes work just fine.
    However I haven't been able to get EP6 to work consistently with the Domino JSP tag library.
    Has anyone been successful in using the Domino JSP tag library?
    Thanks for sharing any insights/workarounds.

    Hello Luc,
    yes. Pls. perform the following steps:
    (1) add a reference to the taglib in portalapp.xml component profile
                   <component name="default">
                        <component-config>
                             <property name="ClassName" value="com.test.LotusJSPTest">
                             </property>
                             <property name="SecurityZone" value="com.test/high_safety">
                             </property>
                        </component-config>
                        <component-profile>
                             <property name="lotusTagLibary" value="domtags.tld">
                             </property>
                             <property name="tagLib" value="/SERVICE/htmlb/taglib/htmlb.tld">
                             </property>
                        </component-profile>
                   </component>
    (2) add a reference in the JSP
    <%@ taglib uri="lotusTagLibary" prefix="domino" %>
    (3) then use the taglib as documented, e.g.:
                 <domino:session id="session1" host ="p70448.wdf.sap.corp:8000" user="*webuser">
                        <domino:db id="db1" dbname="portalchallenge.nsf" >
                             <domino:view id="view1" viewname="view103">
                                  <domino:viewloop id="loop">
         <tr>
         <td style="border: 1px solid #000000; padding: 2px; text-align:right"><%=loop.getPosition('.')%></td>
                                            <td style="border: 1px solid #000000; padding: 2px"><domino:item name="txt_KeywordCode"/></td>
                                            <td style="border: 1px solid #000000; padding: 2px"><domino:item name="txt_Description"/></td>
                                            <td style="border: 1px solid #000000; padding: 2px"><domino:item name="txt_List"/></td>
         </tr>
         </domino:viewloop>
                               </domino:view>
                          </domino:db>
                     </domino:session>
    The easiest way to start is to make domtags.jar, domtags.tld, domutils.tld and NCSO.jar part of your portal application.
    Regards
    Michael

  • Using Javascript attributes in a JSP-Tag

    Hi!
    I want to submit a Javascript attribute to an embedded jsp Tag:
    <script language="JavaScript">
    function test()
         var jscriptvar= document.myform.myselection.selectedIndex;
    result = <%= jspobj.doit(jscriptvar) %>;
    </script>
    The exception is : Undefined variable: jscriptvar
    Is that possible?
    It works, if the doit-method doesn't have a parameter.
    I hope, someone can help me.
    Thanks
    Torsten

    JavaScript is executed on the client-side by the browser. The JSP code is executed on the server-side by the server and has no knowledge of JavaScript variables. You can not mix them in this manner.

  • JSP ${} expressions in JSF tag attributes

    Does anyone know why the expert group decided not to allow ${} style expressions within JSF tag attributes? I understand that a different syntax is needed to implement the 'late binding' #{} expressions used to link input controls to form beans, but not why the JSF tags actually prevent the use of immediately evaluated ${} expressions for accessing variables in the page scope in JSP 2.0.
    I know there has been a lot of discussion about this and other threads mention a security loophole that would be opened up by allowing expressions like #{blah.${someProperty}}, but I'm not sure why this sort of thing would cause a problem. Is there any way to enable this behaviour, such as editing the JSF tag library descriptors to allow runtime expressions (horrible though that sounds)? Or perhaps another JSF implementation that supports both immediately evaluated and late-binding expressions? It seems a rather unnecessary restriction that is going to cause much confusion and mistyping for all...
    Thanks in advance,
    Keith.

    Thanks Adam, I see the problem now. It's a fairly obscure loophole but serious nonetheless. Of course, this problem could also be avoided by not using request parameters within JSF tags as it doesn't affect the majority of legitimate uses for expressions.
    I have to disagree with you about mixing ${} and #{} expressions though. The majority of developers will be used to writing ${} expressions in JSTL and JSP text and so will expect them to do work the same in JSF tags. Judging by the number of posts in this forum about being unable to use page scope variables in JSF tags this issue is already confusing a lot of people.
    As a rule of thumb, "use ${} for expressions that are output to the page and #{} for binding controls to backing beans and invoking methods" (which perform clearly distinct functions) is a lot simpler and easier to learn IMHO than the current one, which is "use ${} for expressions that are output to the page except within a JSF tag, where you use #{} for the same thing and also to update form values and invoke action methods"! (OK, I'm exaggerating a little for effect, but you get the point... :-)
    I agree that mixing both types of expression in the same attribute might be a little confusing, but this is an unlikely edge case that should probably be prevented in value binding or action attributes anyway. It's more of an issue for label values where mistyping one for the other is already very common and, although not especially difficult to debug, is just another pitfall awaiting the unwary JSP developer. I'm not sure that JSP expressions would be much more difficult to debug anyway as the value and method bindings will simply not work, which is pretty obvious as soon as you try and test the thing.
    Is this something that the EG would be prepared to reconsider for the next release of JSF, or perhaps getting the security loophole addressed in the next JSP spec? In the meantime, is there any reason that developers shouldn't enable runtime expressions in the TLD file provided that they're willing to live with the consequences?
    (Sorry to harp on about it, but I've already had several complaints about this after recommending JavaServer Faces for a major development project at ingenta.com.)
    Many thanks,
    Keith.

  • Jsp tag for blog attribute in a flex asset

    hi Experts,
    I am using FW7.6.1, I have a flex asset with a blob attribute, when I create that flex asset, I can upload an image in that attribute, but I did not find a jsp tag for rendering that attribute which has a image saved, another question is what jsp tag should be used in case of a word file is uploaded in that attribute, that's to say:
    1. for a image, I want to display it in browser.
    2. for a word file, I want to show popup window to ask user if he wants to download or open.
    By using assetset:getattributevalues and render:stream, it's just for string type of attribute, not for blog.
    Thanks in advance.
    Best regards

    hi all,
    I got the answer from dev guide, seems should use:
    <blobservice:gettablename varname="uTabname"/>
    <blobservice:getidcolumn varname="idColumn"/>
    <blobservice:geturlcolumn varname="uColumn"/>
    and render:satelliteblob
    some complicated then I expected.
    Best regards

  • In javascript  how to use jsp tag value

    i want to change td value while clicking the options.In the td contains jsp page.while clicking the options i want to load particular jsp within in the td.i change the td value using innerHTML by assigning value this format <jsp:include page="..."/>.It's gives some error .
    JspTranslate:Attribute has no value
    code:
    function rightPageload(strPage) {
    pageval='<jsp:include page="/jsp/library/"'+strPage+'"/>'
    document.getElementById("d1").innerHTML=pageval;
    }

    Do you want to use taglibs or develop custom tags? Either way take a look at these:
    http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPTags.html
    http://www.stardeveloper.com/articles/display.html?article=2001081301&page=1
    http://www.onjava.com/pub/a/onjava/2000/12/15/jsp_custom_tags.html
    http://jakarta.apache.org/taglibs/tutorial.html
    http://www.ibm.com/developerworks/edu/j-dw-java-custom-i.html
    http://www.herongyang.com/jsp/tag.html

  • uix:table using JSP tags

    I cannot figure out how to bind a dataobject list using the <uix:table> tag. Could someone please help me with this.
    Jeff Driskell

    Do you mean that you already have a DataObjectList which you want to set as the <uix:table>'s tableData attribute? If so, I believe you have two choices:
    1. You can use a scriptable variable for the table and call setTableData() explicitly on the TableBean.
    2. You can use a scriptable variable for a dataScope and register a DataProvider which provides access to your DataObjectList. Then, you can use the tableDataBinding attribute of the <uix:table> tag to bind to your DataProvider.
    Examples of both of these techniques are provided in the "Scriptable variables" section of the "UIX JSP Tag Libraries" section of the UIX Developer's Guide.

  • What is the standard on using some jsp tags?

    Has it become an industry standard to not use scriplets, expressions and declarative tags in jsp or is it all dependant on the scale of the application and the preference of the developer. I have seen the arguments for not using these tags and while I can see how they can become problematic for large applications with many developers I never had a problem developing a small application just by myself.
    I would like to know how many of you jsp developers still use these tags and how many don't and your reasons why you do or why you don't?
    I wonder if most people actually see these problems for themselves or do they just join the in crowd because it's the new thing
    And if it is a standard why aren't they just phased out of exiistance. Stuff like that makes it hard for people to learn. I can't tell you how many tutorials i've seen teaching scriptlets and expressions

    I started with scripting, etc. but early on switched to CTLs. They can be bundled and distributed very easily.
    I had read many, many times how hard it was to maintain a site that used a lot of scripting, etc. but gave it only a little heed. Like you, I was a one man show, certainly I could remember what I was doing.
    It didn't take long before I could see that they were right. I immediately ceased what I was doing, repackaged nearly all of the logic into tag libraries (8 in all), redesigned the existing applications to use the tag libraries (which was a pain in the beginning, but worth it big time).
    I am now redesigning our company website to include things like order status, event calendars and a lot of neat web-based stuff. I will have this website done in half the time of our old static html website.

  • Using jsp variables within JSP tag

    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?

    Your definition of the selectString attribute must indicate that it can accept runtime expressions.
    <%
    String cust_id = request.getParameter("cust_id");
    String selectString = new String("r.ccar_id = c.id AND c.cust_id = " + cust_id);
    %>
    <%@ 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="<%= selectString %>"/>

Maybe you are looking for

  • Windows tool to compile forms on unix server

    We have one client using Forms 6i on the web, so I need to test in this environment. Currently to compile the fmb on the unix platform, I use Hummingbird software (Connectivity, Exceed, Xstart) to run the compile using the command f60genm. I do not p

  • Detect print information in a network

    Dear all, I am new to Java network programming. I have a network of pc and a printer connected to one of the workstations. When someone print a document, how can detect : who print that document, how many pages, etc? I am looking forward to hearing f

  • KMANU field value download from R/3 to CRM for price Condition type

    Hi We done changes for KMANU field in R/3 - price condition type and that changes have to download from r/3 to CRM. I was tried below object adapters to update field value (R/3 u2013 table name: T685A - KMANU) from R/3 to CRM (Table :PRCC_COND_CT u20

  • Struts Config.XML file error

    if Error in page (value not entered in textfield) , it will be redirected to a same page with server valid error page . After redirecting javascript,css r not working(means not included) but it is working when page is first time loaded. help me what

  • Flash will not install on Mac OS X.5.7.

    Attachment will not open without Flash. Download is successful. menu indicated installation was successful but app does not show up in APPs, therefore attachment will not open.  Apple help said Adobe would have to solve.  This is a MacBook, OS 10.5.7