Hi,

I will ask the basic question first so that you don't have to read the whole
email:

So is there no way to use the same request over 2 or more jsp files that are
nested in
each other?

Now my test case:

I have a template jsp file that has all the layout of my site.
in the right left corner will al the dynamic data.

like this:

// tag libs includes
<form:html locale="true">
<head>
<title><bean:message key="index.title"/></title>
</head>
<body bgcolor="#fce8a0" topmargin="0" leftmargin="0">

<table width="100%" border="0" height="123" cellpadding="0" cellspacing="0"
bgcolor="#0066ff">
   <tr>
    <td>
        // standard layout of my site
        // jadajadajadajada
    </td>
        // The include logic.
        <logic:present name="<%= JSP_INCLUDE_KEY %>" scope="request">
        <bean:include id="subpage" name="<%=
(String)request.getAttribute(Constants.JSP_INCLUDE_KEY) %>"/>
        <%= subpage %>
        </logic:present>
        <logic:notPresent name="<%= Constants.JSP_INCLUDE_KEY %>" scope="request">
        <bean:include id="subpage" name="/index.jsp"/>
        <%= subpage %>
        </logic:notPresent>
  </tr>
</table>
</body>
</form:html>

This template file is always the ActionForward that i return as the next
page to see
after this action, something in the perform method of a Action:

        request.setAttribute(Constants.JSP_INCLUDE_KEY,
mapping.findForward("pensioen3a").getPath());
        return mapping.findForward("template");

The nicest thing about this is that if i want to change something of my site
i only have to edit
one file and every page/view is changed also like the logon page or the
pages with the forms.

But now my problem.

An Action is mostly triggerd by the subpage (where the form is in).
That Action is testing the input (some validation) if that goes wrong that
a ACtionError is made and is attached to the request.
But when i forward it (to the same page) i forward it to the template again
and that
template includes the page with the form.
But the include generates another request for that subpage so my
ActionErrors object
and other objects that i stored in the request aren't there!!

I also do this in te validate() of a Form:

        String fromPage = request.getParameter("frompage");
        mapping.setInput(mapping.findForward("template").getPath());
        request.setAttribute(Constants.JSP_INCLUDE_KEY,
mapping.findForward(fromPage).getPath());

So that when there are errors returned it knows that the input is the
template and the
include is the same page it come's from.

But this also doesn't work.
I can't be the only one with this problem.
Are nobody else using subpages where the form/inputs are in an another one
that is the standard layout page?

I thought to be smart and made my own include tag:

public int doStartTag() throws JspException
{
        try
        {
                RequestDispatcher rd=
pageContext.getServletContext().getRequestDispatcher(_sPage);
                rd.forward(pageContext.getRequest(), pageContext.getResponse());
        } catch(Exception e)
        {
                throw new JspException(e.getMessage());
        }
        return SKIP_BODY;
}

But the problem is then that the subpage (the _sPage string) is displayed
first, above
the main page instead of in the main page. Why is this? Because when i walk
through the code
then i see the main page that writes to the output and then the subpage and
then the main
page again. I think this has something to do with flushing ect.
But if i flush first (right above the RequestDispatcher line i do this:

 pageContext.getOut().flush();

Then i get the main page on top again but an error in the place where the
subpage should be:

        Location: /postbank/template.jsp
        Internal Servlet Error:

        javax.servlet.ServletException: Cannot forward as OutputStream or Writer
has already been        obtained

So is there no way to use the same request over 2 or more jsp files that are
nested in
each other?

Johan







Reply via email to