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

[419 byte] By [tochprasada] at [2007-11-26 15:34:54]
# 1

We can use JSTL inside custom tags. It worked for me.

Please check the code :

ep:button key="buttons.submit" name="submitBtn" styleClass="But"

onClick='submitPage(''><c:out value='${buttonName}' />)' />

replace above code with

ep:button key="buttons.submit" name="submitBtn" styleClass="But"

onClick='submitPage(''<c:out value='${buttonName}' />)' />

i.e. delete >.

Hope this helps. If there is no spell mistakes, please post the exact error your are getting.

loyolagema at 2007-7-8 21:52:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

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 = 6837146537426981407;

/**

* 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('&lt;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>

tochprasada at 2007-7-8 21:52:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

>how can i use JSTL inside the custom tags

The fundamental rule of custom tags is that you can't have a custom tag nested as an attribute to another custom tag. For attributes you can only use expressions such as <%= expr %> or (in a JSP2.0 container) ${expr}

Hope that helps,

evnafets

evnafetsa at 2007-7-8 21:52:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...