Hi Matt

Recall this problem that we discussed a while back? Well, I had a bit more
of a play in the weekend. I discovered that if you use the SSL extension,
the multiple forwards of *.do will not work. Well, it works in a very weird
way, basically only chosing one .do to forward. Try it out sometime if you
can. I think one of the problems come from the SLL extension switching the
request between secure and non-secure.

I am currently working on an alternative to including multiple *.do, which
will then make the application work on Tomcat as well as SSL extensions.

This is just a note to you it case you strike the same problem in the
future.

Keith



-----Original Message-----
From: Keith Chew [mailto:[EMAIL PROTECTED]]
Sent: Monday, 11 March 2002 9:26 a.m.
To: Struts Users Mailing List
Subject: RE: design flaw if using a template...


Hi Matt

I have done more research over the weekend and this is what I have found:

The multiple *.do only works in Resin, not Tomcat. In Tomcat, this is the
exception:

"javax.servlet.jsp.JspException: Cannot forward after response has been
committed"

Further investigation shows that Tomcat is calling flushBuffer() after the
first forward. Resin handles this differently, as shown in this post I
found:

****************************************************************************
********
-----Original Message-----
From: Andreas Junghans [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, January 22, 2002 1:09 AM
To: Tomcat Developers List
Cc: [EMAIL PROTECTED]
Subject: Re: HttpServletResponseWrapper error.


Hi Jay,

> This works with Resin. However, in Tomcat, when I wrap the response, I
> "commit" the original response object and can not forward to a thank you
> page. I catch a "java.lang.IllegalStateException: Cannot forward after
> response has been committed". In my debug tests, the response is committed
> during the RequestDispatchers forward method.

I've had a similar case. The problem is that Tomcat calls flushBuffer() on
the response, which seems to be completely "legal" regarding the Servlet
spec. Calling flushBuffer() commits the response, and after that, no forward
is possible.

If Resin behaves differently, this is probably due to a different buffer
size or different buffer handling. Perhaps Resin doesn't call flushBuffer()
at all, which (in my understanding) is just as spec compliant as Tomcat's
behaviour.

What you have to do is override flushBuffer() in your response wrapper to
prevent HttpServletResponseWrapper from passing the flush to the original
response. In my case, I simply added an empty flushBuffer() method to the
wrapper, and it worked. However, you should note that some containers
_might_ rely on the side effects of the original flushBuffer() (e.g. that
exceptions are raised when calling methods like sendRedirect() afterwards).
Although this is highly unlikely, you have to "simulate" these effects in
your wrapper if you want to be _absolutely_ sure your application runs in
every container.

Regards

  Andreas Junghans

****************************************************************************
********

I have tried the latest version of Tomcat 4.0.3, but no joy.

Keith




-----Original Message-----
From: Matt Read [mailto:[EMAIL PROTECTED]]
Sent: Friday, 8 March 2002 11:04 a.m.
To: Struts Users Mailing List
Subject: RE: design flaw if using a template...


I'm glad you've found a solution. I'd still say you're misusing
<template:insert> though, because it's not really a template that you're
inserting but if it works, it works.

-----Original Message-----
From: Keith Chew [mailto:[EMAIL PROTECTED]]
Sent: 07 March 2002 21:15
To: Struts Users Mailing List
Subject: RE: design flaw if using a template...


Hi Matt

I am such an idiot.

In my template.jsp, I have:

<template:insert template="/news.do"/>

This is equivalent to a jsp include. My mistake was news.do forwards to
new.jsp after getting the data from the database.

However, news.jsp uses template.jsp too!! So it's trying to go into an
infinite loop!

I have changed new.jsp to just return the news. It's going well.

Thank you very much for all you help.

Keith



-----Original Message-----
From: Matt Read [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 7 March 2002 3:31 p.m.
To: Struts Users Mailing List
Subject: RE: design flaw if using a template...


Keith, they're not the same thing, by any means. As you said, if you use
your method:
        <template:insert template="/news.do" />
you get a "too many servlet includes `/template.jsp'" error. This is doesn't
really suprise me at all - you're basically trying to use something which
blatantly isn't a template, as a template.

However if you use the method I outlined in my examples, i.e. you "put"
content into a template, whether this content is a .jsp or an action mapping
url - it works.

Honestly, just use <template:put> as it is documented and your problems will
be solved.

Matt.

-----Original Message-----
From: Keith Chew [mailto:[EMAIL PROTECTED]]
Sent: 07 March 2002 02:18
To: Struts Users Mailing List
Subject: RE: design flaw if using a template...


Hi Matt

I will try this again tonight. But I am doing the same as you (well, just
another way):

In template.jsp, you can either go:

<template:get name="somecontent"/>

if you have passed in "somecontent" to the template, eg in thepage.jsp:

        <template:insert template="/template.jsp">
                <template:put name="somecontent" content="/news.do" />
        </template:insert>

This is what you have done. Alternatively, in template.jsp, you can go:

<template:insert template="/news.do"/>

if you don't pass "somecontent" to template.jsp. The line above is just like
a jsp:include tag.

Anyway, I will test this again tonight. I hope it's something stupid I have
done. I will also report the exact exception after the test.

Thanks again Matt.

Keith


-----Original Message-----
From: Matt Read [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 7 March 2002 1:28 p.m.
To: Struts Users Mailing List
Subject: RE: design flaw if using a template...


Yep, that's pretty much what I did. I don't really have a cut-down example
that demonstrates it working as I tried it as part of an app that I'm
building.

I'm not sure you're understanding the correct use of <template:insert> and
<template:put>. Make sure you use an example similar to mine rather than the
one you posted in your first message. Note the differences, mine uses:
        <template:put name="newspanel" content="/news/shownews.do" />
to put the Action into the template that's declared using:
        <template:insert template="/templates/myTemplate.jsp">

Your example seemed to be trying to use the path to the Action itself as the
template which is completely different:
        <template:insert template="news.do"/>

You need to do the following:
1. Create an action mapping like this in struts-config.xml:
        <action path="/mypage"
                type="org.apache.struts.actions.ForwardAction"
                parameter="/thePage.jsp" />
2. Create your template file "/mytemplate.jsp" something like this:
        <%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
        <table><tr>
                <td><template:get name="leftSide"/></td>
                <td><template:get name="rightSide"/></td>
        </tr></table>
3. Create your page "/thePage.jsp" something like this:
        <%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
        <template:insert template="/WEB-INF/templates/template.jsp">
                <template:put name="leftSie" content="/path/to/some/other/action.do" />
                <template:put name="leftSie"
content="/path/to/some/other/different/action.do" />
        </template:insert>

4. Open up http://mymachine.com/mypage.do and it should show the result of
your 2 actions that you "put" in step 3.

Hope this is clear enough.

Matt.

-----Original Message-----
From: Keith Chew [mailto:[EMAIL PROTECTED]]
Sent: 07 March 2002 00:14
To: Struts Users Mailing List
Subject: RE: design flaw if using a template...



Matt, thank you very much for trying this out. I appreciate the time you are
spending to help me track the problem.

Can you give this a go:

In the address bar, type a *.do address, eg
http://localhost:8080/test/page1.do

This will call Page1Action, which forwards to page1view.jsp

In page1view.jsp, it will have your template which inserts shownews.do.

I believe this will fail.

If you have a JSP in the address bar, it's fine. But with a .do, it's not.

I have using the 26 Feb 2002 snapshot.

Keith



-----Original Message-----
From: Matt Read [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 7 March 2002 12:54 p.m.
To: Struts Users Mailing List
Subject: RE: design flaw if using a template...


I did try it and it worked fine. I'm using the nightly build.

-----Original Message-----
From: Keith Chew [mailto:[EMAIL PROTECTED]]
Sent: 06 March 2002 23:49
To: Struts Users Mailing List
Subject: RE: design flaw if using a template...


Hi Matt

Yes, that's exactly what I want. In fact, I have the same code that you have
given below.

But Struts does not allow it. It complains that the request is already
commited and cannot forward twice.

Can someone try this out for me please? Maybe I have missed out something...

If this can be achieved, it'll be so easy to mix and match your Actions, put
them as links in a page or in the template.

Keith




-----Original Message-----
From: Matt Read [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 7 March 2002 12:12 p.m.
To: Struts Users Mailing List
Subject: RE: design flaw if using a template...


My apologies if I'm misunderstanding your point but if you're concerned that
the elements that you "put" into your template are not going through the an
xxxAction then why not put the URL for the action in instead of a .jsp? This
way your ShowNewsAction is following the same flow as any other content.
E.g.

<template:insert template="/WEB-INF/templates/myTemplate.jsp">
    <template:put name="newspanel" content="/news/shownews.do" />
    <template:put name="content">
                ... some html
    </template:put>
</template:insert>

Matt.

-----Original Message-----
From: Keith Chew [mailto:[EMAIL PROTECTED]]
Sent: 06 March 2002 23:02
To: Struts Users Mailing List
Subject: RE: design flaw if using a template...


Hi Ross

Good comments.

You see, with custom tags, there are several problems:
- For each different parts of the template, I need to create a custom tag
- This custom tag is actually what an xxxAction class is meant to do, ie
retrieve data from a database and prepare the data for view
- If I later decide not to put news in the template and put it in a separete
page, I need to port the taglib code to an xxxAction class. Not very
flexible.
- taglibs from Struts point of view, only renders data for viewing. It
should not be performing model work, which should really be in the xxxAction
class.

So, I can see that Struts was designed to handle "user invoked" actions, not
"code invoked" actions.

Any more thoughts?
Keith



-----Original Message-----
From: Ross MacCharles [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 7 March 2002 11:14 a.m.
To: 'Struts Users Mailing List'
Subject: RE: design flaw if using a template...


Consider rethinking the philosophy that all data rendered in the JSP must
come from an ActionForm.   In my mind the ActionForm generally represents
the editable data for the page displayed to the user.  There's no problem
with displaying data from other sources on the same page - especially read
only data.

For news I would simply use a custom tag to get it and display it.

Put another way, I wouldn't want to have to set up a bean with "setNews" and
"setMemberCount" when I have no intention of allowing my application to edit
those values.

/Ross


 -----Original Message-----
From:   Keith Chew [mailto:[EMAIL PROTECTED]]
Sent:   Wednesday, March 06, 2002 4:28 PM
To:     Struts Users Mailing List
Subject:        design flaw if using a template...

Hi

Struts provides us with a nice MVC architecture, where:
- a user's click maps to an Action
- based on the results, the user is forwarded to the view

Now, I have a template.jsp which all pages will use. The template will
contain some views that are common to all pages, eg:
- Latest News
- Site visits
- Member count

To retrieve these information, it gets them from the database. However,
there is no user click to invoke the action. This is where the limitation of
Struts comes in. Let me explain:

In the template.jsp, we can have:

<template:insert template="news.jsp"/>

In news.jsp we can access the database and retrieve the news for display.
This breaks the MVC pattern, since the view is accessing the model.
Alternatively, we have have this in the template.jsp:

<template:insert template="news.do"/>

This will call the NewsAction which accesses the database, and forwards the
results to the news.jsp for display.

This is a great concept, but it does not work. Struts does not allow
multiple forwards (this happens when the current page is already a .do).
Here's an example:
(1) User clicks on viewUserDetail.do
(2) ViewDetialAction forwards to user.jsp
(3) In template.jsp (used by user.jsp), news.do invokes NewsAction, and it
forwards to news.jsp

This is a double forward, which results in an exception.

Basically, I want to call

<template:insert template="news.do"/>

in the JSP. Has anyone done something like this?

Keith


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

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


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


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


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


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


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


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


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


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


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


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


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


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

Reply via email to