permaculture playing cards
The moose likes Servlets and the fly likes Instance class within Tag File without scriplet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Instance class within Tag File without scriplet?" Watch "Instance class within Tag File without scriplet?" New topic

Instance class within Tag File without scriplet?

Angelo Giugliano

Joined: Sep 22, 2004
Posts: 6
Hello to all and thousand thanks in advance

My architecture is composed by: jsp-tag handler-delegate-session-entity-db
I was thinking to come near to jsp2.0 (el-jstl1.2). Is possible to instance one class into Tag File without to use an scriplet and if yes how give to class instanced some parameters?

My Tag File's example is:

<%@ taglib prefix="c" uri="" %>
<%@ variable name-given="strout" description="Parametro in uscita" variable-class="java.lang.String" scope="AT_END" %>
<%@ attribute name="strin" required="true" type="java.lang.String" description="Parametro in ingresso" %>
<%@ tag isELIgnored="false" %>
<%@ tag import="java.util.*" %>
<%@ tag import="javax.servlet.jsp.*" %>
<%@ tag import="javax.servlet.*" %>
<%@ tag import="test.*" %>

String a = (String)pageScope.getAttribute("strin");
TestDelegate testDelegate = new TestDelegate();
String str = testDelegate.getNewName(a);%>

<c:set var="strout" value="${str}"/>


In this way don't work. How can make?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Bartender: please move this to the JSP forum.

Welcome to the Ranch, Angelo.

You may be thinking about the problem not-so-correctly. If you are trying to convert an existing application from JSP 1.x to JSP 2.0, there are frequently some off-page changes that need to take place. Please read the JavaRanch Journal article that I wrote on this very subject.

To be specific, as you have discovered, scriplets are not allowed in tag files. And since your example includes a call to a method that expects a parameter, you cannot use the EL which expects bean-patterned classes.

You may need to take a step back and figure out what you are trying to accomplish and rework it. Or, if you need to do "general Java" type things in your tag, you may just need to use a Java-based tag handler rather than a tag file.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Instance class within Tag File without scriplet?
jQuery in Action, 3rd edition