The thing is that neither JSP nor Tiles are designed for what you want
to do. BTW, FreeMarker is already in your application.

musachy

On Thu, Feb 12, 2009 at 2:19 PM, Ignacio de Córdoba <icord...@skios.es> wrote:
>
> hi again,
> thanks for your reply. I've never used FreeMaker or Velocity. I use
> Tiles2... can you figure out if your solution can be solved with Tiles2. I
> wouldn't like to get into those, I'm sure great, technologies only for this.
>
> Thanks,
> Ignacio
>
>
> Musachy Barroso wrote:
>>
>> I don't know how to fix it, but i would never use JSP for this. I
>> would suggest you use FreeMarker or Velocity which will be very easy
>> to get working and won't break across different containers/versions.
>> For example, for FreeMarker (which will be in the classpath already),
>> I use this:
>>
>> public static void process(ServletContext context, String template,
>> Map<String, Object> values, Writer writer) throws IOException,
>> TemplateException {
>>         Configuration cfg = new Configuration();
>>         cfg.setDirectoryForTemplateLoading(new
>> File(context.getRealPath("/templates")));
>>         cfg.setObjectWrapper(new DefaultObjectWrapper());
>>
>>         BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
>>         TemplateHashModel staticModels = wrapper.getStaticModels();
>>         Template temp = cfg.getTemplate(template);
>>         temp.process(values, writer);
>>         writer.flush();
>>     }
>>
>> //also JSP has not way to deal with empty spaces and such
>>
>> musachy
>>
>> On Thu, Feb 12, 2009 at 1:49 PM, Ignacio de Córdoba <icord...@skios.es>
>> wrote:
>>>
>>> Hi there,
>>> I had a working solution that was fine for struts1 and doesn't work with
>>> struts2.
>>> The scenario is evey time the application needs to send a mail from an
>>> action (for example, when a user signs up, the system sends him a welcome
>>> mail)
>>>
>>> My solution got the JSP the following way:
>>>
>>>        public String getResourceAsString(String path) throws
>>> ServletException,
>>> IOException
>>>        {
>>>                HttpServletRequest request =
>>> org.apache.struts2.ServletActionContext.getRequest();
>>>                HttpServletResponse response =
>>> ServletActionContext.getResponse();
>>>                try
>>>                {
>>>                        ByteArrayOutputStream out = new
>>> ByteArrayOutputStream();
>>>                        RequestDispatcher dispatcher =
>>> request.getRequestDispatcher(path);
>>>                        RedirectingServletResponse dummyResponse = new
>>> RedirectingServletResponse(response, out);
>>>                        dispatcher.include(request, dummyResponse);
>>>                        return out.toString();
>>>                } catch (NullPointerException e)
>>>                {
>>>                        return "<p>No such template: " + path + "</p>";
>>>                }
>>>        }
>>>
>>> (RedirectingServletResponse class just extends HttpServletResponseWrapper
>>> and captures output to a ByteArrayOutputStream)
>>>
>>>
>>> The JSP needs a small scriptlet at its end:
>>> <% out.flush(); %>
>>>
>>> Without it, the mail is sent blank as the JSP is not rendered to
>>> HTML/text
>>> as the request has not ended (I use the current thread request because:
>>> 1) I
>>> don't know how to create a brand new request/response 2) This way I can
>>> use
>>> all request parameters, attributes... in the mail sent and so not use
>>> just
>>> plain HTML but real JSP.
>>>
>>> The problem now is that struts2 shows the following exception:
>>>
>>> java.io.IOException: Stream closed
>>>
>>>
>>> org.apache.jasper.runtime.JspWriterImpl.ensureOpen(JspWriterImpl.java:204)
>>>
>>> org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:115)
>>>    org.apache.jasper.runtime.JspWriterImpl.flush(JspWriterImpl.java:173)
>>>
>>> org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:956)
>>>
>>> org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:609)
>>>
>>> org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:123)
>>>
>>> org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
>>>
>>> com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:361)
>>>
>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:265)
>>>
>>> com.servengine.struts2.InjectEJBInterceptor.intercept(InjectEJBInterceptor.java:89)
>>>
>>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
>>>
>>> org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
>>>
>>> org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:468)
>>>
>>> org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:395)
>>>
>>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
>>>
>>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206
>>>
>>> Any ideas on this... or better... any directions on how can I instanciate
>>> a
>>> "fake" response not based on current struts2 Action ServletResponse
>>> object
>>> (and so flush() or close() will not affect it).
>>>
>>> Thanks,
>>> Ignacio
>>> --
>>> View this message in context:
>>> http://www.nabble.com/How-to-render-a-JSP-Struts2-action-to-send-it-%28mail%2C-...%29-tp21982445p21982445.html
>>> Sent from the Struts - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>>> For additional commands, e-mail: user-h...@struts.apache.org
>>>
>>>
>>
>>
>>
>> --
>> "Hey you! Would you help me to carry the stone?" Pink Floyd
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>> For additional commands, e-mail: user-h...@struts.apache.org
>>
>>
>>
>
> --
> View this message in context: 
> http://www.nabble.com/How-to-render-a-JSP-Struts2-action-to-send-it-%28mail%2C-...%29-tp21982445p21982968.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to