Custom Tags including other tags

J

joseph.berthe

Hi,

I want to create a Custom Tags which display a login page.

I have created a file with all graphical stuffs. Inside that file I
want to put on some JSP functions such as using variables or other
tags.

Furthermore I want to create a custom tags which able to include that
graphical file.

My problem is my graphical file is included like only text, so all JSP
stuff are not used.

I have already tested :
-- pageContext.include(myFile.jsp);
-- pageContext.include(myFile.jsp, true);

In doAfterBody
-- BodyContent body = getBodyContent();
JspWriter wout = body.getEnclosingWriter();
wout.println("<%@ include file=\"formlogin.jsp\" ");
body.clearBody();

Obviouly the problem comes from the compilation schedule. I mean when I
want to write down JSP stuff inside my page, it is to late, the
compiler has already compile the files and it think it is just text.


Thanks
 
R

Raymond DeCampo

Hi,

I want to create a Custom Tags which display a login page.

I have created a file with all graphical stuffs. Inside that file I
want to put on some JSP functions such as using variables or other
tags.

Furthermore I want to create a custom tags which able to include that
graphical file.

My problem is my graphical file is included like only text, so all JSP
stuff are not used.

I have already tested :
-- pageContext.include(myFile.jsp);
-- pageContext.include(myFile.jsp, true);

In doAfterBody
-- BodyContent body = getBodyContent();
JspWriter wout = body.getEnclosingWriter();
wout.println("<%@ include file=\"formlogin.jsp\" ");
body.clearBody();

Obviouly the problem comes from the compilation schedule. I mean when I
want to write down JSP stuff inside my page, it is to late, the
compiler has already compile the files and it think it is just text.

Try using the include() method on the javax.servlet.RequestDispatcher class.

HTH,
Ray
 
J

joseph.berthe

Thanks,

So it doesn't work at all. The only positive thing is now I can insert
HTML files.

Remark :
But i'm thinking about that technology (Custom Tags). My goal is to put
graghical component inside a tags and interact with it and reuse it.
But probably it is not suitable for that. I have read something about
STRUTS, probably this is what I need. What do you think ?


I have done :

---------------------------JAVA file -----------------------
public class loginform extends BodyTagSupport {

//Variables
....

// Functions
....

public int doStartTag() throws JspException{
try {
} catch (Exception e) {
throw new Error("That's bad.start");
}
return EVAL_BODY_BUFFERED;
}

public int doAfterBody() throws JspException{
try {
String resource = "formlogin.jsp";
ServletRequest req = pageContext.getRequest();
ServletResponse res = pageContext.getResponse();
RequestDispatcher rd = req.getRequestDispatcher(resource);
rd.include(req, res);

} catch(Exception e ) {
throw new Error("That's bad body." + e);
}
return EVAL_BODY_BUFFERED;
}

public int doEndTag() throws JspException{
try {

} catch (Exception e) {
throw new Error("That's bad.end");
}
return SKIP_PAGE;
}
}

-------------- TLD File ----------------------
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
web-jsptaglibrary_2_0.xsd">
<tlib-version>1.0</tlib-version>
<short-name>loginform</short-name>
<uri>/WEB-INF/tlds/loginform</uri>

<tag>
<name>loginform</name>
<tag-class>MyTags.loginform</tag-class>
<body-content>tagdependent</body-content>
</tag>
</taglib>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top