Yeah, RequestDsiapatcher would work (like the struts IncludeAction) with the
StoreTag I sent, then you wouldn't have to forward in the jsp.

-------Action.execute()-------
// Determine Email Template
Strint emailTemplate = "EmailTemplate.jsp";

// Get formatted email content
javax.servlet.RequestDispatcher rd =
servlet.getServletContext().getRequestDispatcher(emailTemplate);
rd.include(request, response);
String emailContent = form.getEmailContent();

// Process
....send email---

 ------EmailTemplate.jsp-----
 <custom:store name="myForm" property="emailContent" scope="session">
     ------ format your email here -----
 </custom:store>


...and use the StoreTag to just save the contents of the jsp in a
bean/request/session

Niall

P.S. The first line in the doAfterBody() was a mistake in the StoreTag.


----- Original Message ----- 
From: "Mark Lowe" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Tuesday, March 02, 2004 2:02 PM
Subject: Re: JSP context in an action


> I'm still chewing on the problem. But a custom tag lib would seem a
> possibility. I ended up using a velocity servlet and doing things that
> way, my aim in trying otherwise was not to have to use velocity as its
> another bunch of libraries that in theory I shouldn't need.
>
> Ideally i'd have a template directory under WEB-INF where numb-nuts
> dreamweaver types can edit email templates and i particularly like the
> expression syntax which is like jsp2. So i was trying to think of a way
> of using just that.
>
> Velocity would be a really tidy way of doing things if the
> VelocityEngine class had a getTemplate method that takes in a file
> rather than just a string. At the moment I've a velocity servlet thats
> really only there to get around this problem.
>
> But as things are its not that bad i've have just preferred not having
> to have a velocity servlet running just to find the where abouts of the
> template.
>
> Using jsp even better as everythings already there, just how to drill
> to what i need. RequestDispatcher could be an option request the file
> get its context and then stuff the map in there, but could be
> tree-barking or/and smoking too much crack.
>
>
>
> On 2 Mar 2004, at 12:59, Niall Pemberton wrote:
>
> > Mark,
> >
> > I'd like to know how to do what you're but, unless someone else knows,
> > how
> > about a different approach:
> >
> > You could have a "store" tag which gets the body of a tag and stores it
> > somewhere (in the request or session or in a bean in the request or
> > session)
> > and then forwards to an email action which then gets the stored
> > content and
> > sends an email. Something like:
> >
> > ------EmailTemplate.jsp-----
> > <custom:store name="myForm" property="emailContent" scope="session">
> >     ------ format your email here -----
> > </custom:store>
> > <logic:forward name="emailForward"/>
> >
> >
> > ------- StoreTag.java---------
> >
> > package lib.framework.taglib;
> > import javax.servlet.jsp.tagext.BodyTagSupport;
> > import javax.servlet.jsp.JspException;
> > import org.apache.struts.util.RequestUtils;
> > import org.apache.commons.beanutils.BeanUtils;
> > /**
> > * @author Niall Pemberton
> > * @version 1.0.0
> > */
> > public class StoreTag extends BodyTagSupport {
> >
> > protected String name = null;
> > protected String property = null;
> > protected String scope = null;
> >
> > public StoreTag() {
> > }
> > public void setName(String name) {
> > this.name = name;
> > }
> > public String getName() {
> > return name;
> > }
> > public void setProperty(String property) {
> > this.property = property;
> > }
> > public String getProperty() {
> > return property;
> > }
> > public void setScope(String scope) {
> > this.scope = scope;
> > }
> > public String getScope() {
> > return scope;
> > }
> > public int doAfterBody() throws JspException {
> > org.apache.struts.action.RequestProcessor ccc;
> > String value = null;
> > if (bodyContent != null) {
> > value = bodyContent.getString().trim();
> > }
> > if (property == null) {
> > pageContext.setAttribute(name, value, RequestUtils.getScope(scope));
> > } else {
> > // find the bean
> > Object bean = RequestUtils.lookup(pageContext, name, scope);
> > if (bean == null)
> > throw new JspException("Cannot find bean '"+name+"' in scope
> > '"+scope+"'");
> > try {
> > BeanUtils.setProperty(bean, property, value);
> > }
> > catch (Exception ex) {
> > throw new JspException("Error setting property '"+property+"' on bean
> > '"+name+"' in scope '"+scope+"': "+ex);
> > }
> > }
> > return (SKIP_BODY);
> > }
> > public void release() {
> > name = null;
> > property = null;
> > scope = null;
> > }
> > }
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to