You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Paul Moody <pa...@yahoo.co.uk> on 2005/05/27 18:54:10 UTC

problem with logic redirect tag and tiles

I have a problem using logic:redirect with tiles.

If I put the redirect tag into the page which inserts
a tile definition then the redirect works. For
example:

(in my tiles-defs.xml):

<definition name="mainLayout"
path="/tiles/mainLayout.jsp">
  <put name="pageMenu"
value="/common/defaultMenu.jsp"></put>
  <put name="pageBody"
value="/common/blankBody.jsp"></put>
</definition>


/main.jsp:

...
<%@ taglib uri="http://struts.apache.org/tags-tiles"
prefix="tiles" %>
<%@ taglib uri="http://struts.apache.org/tags-logic"
prefix="logic" %>
...
<%@ page contentType="text/html;charset=UTF-8"
pageEncoding="UTF-8" language="java" %>

<tiles:insert definition="mainLayout" flush="true">
  <tiles:put name="pageBody" type="String">
    <!-- check userData bean is present otherwise they
need to log-in -->
    <logic:empty name="userData">
      <logic:redirect action="login" />
    </logic:empty>
    ...
    blah blah some html and tags
    ...
  </tiles:put>
</tiles:insert>

The above redirect works fine. The problem is that if
I try to put a logic:redirect into the tile definition
jsp or a jsp that gets included using a <tiles:insert
attribute="..."> tag my redirect gets ignored. I get
no exception message but the html for the jsp stops at
the <logic:redirect> tag.


Examples of a redirect that fails:


in jsp /tiles/mainLayout.jsp:

...
<%@ taglib uri="http://struts.apache.org/tags-tiles"
prefix="tiles" %>
<%@ taglib uri="http://struts.apache.org/tags-logic"
prefix="logic" %>
...
<%@ page contentType="text/html;charset=UTF-8"
pageEncoding="UTF-8" language="java" %>

<!-- *** THIS REDIRECT FAILS, I GET A BLANK JSP WITH
THE SOURCE SHOWING ONLY THIS COMMENT *** -->
<logic:empty name="userData">
  <logic:redirect action="login" />
</logic:empty>
<html:html>
    <head>
        ...
        <meta http-equiv="Content-Type"
content="text/html; charset=UTF-8">
    </head>

    <body>
	...
        <tiles:insert attribute="pageMenu"/> 
        ...
        <tiles:insert attribute="pageBody"/>
        ... 
    </body>
</html:html>


also if I put a redirect into a jsp that gets inserted
as "pageBody" this fails and the body html stops at
the position of the logic:redirect tag.

Any ideas?


System info:

O.S.: Windows XP

struts version: 1.2.4

server: weblogic 8.1 sp3

Let me know if you need more info, thanks a lot.

Paul Moody


		
___________________________________________________________ 
How much free photo storage do you get? Store your holiday 
snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com

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


Re: problem with logic redirect tag and tiles

Posted by Eddie Bush <ea...@swbell.net>.
Dave,

It's about more than that.  You can send some amount of data - couldn't tell 
you how much.  The important thing is that the response has not been 
committed.  It sounds to me as if Pauls' response has been committed (due to 
sufficient output having been sent).

Essentially, you want to check right up front if you need to do a redirect.

Paul, why did you move your redirect into a tile?  If you need some pages 
not to check for your userData object, why not just have a second layout?

<!-- Will output document head and such - first order of business in body is 
to determine if "userData"
is present.  If not, it redirects.  If it is, it invokes tiles:insert for 
the "page" attribute. -->
<definition name="secure.root" ....>
  <put name="page" value="..." />
</definition>

<!-- This one does not have the check -->
<definition name="insecure.root" ...>
  <put name="page" value="..." />
</definition>

<!-- Here we use the above.  We could break the page
<definition name="secure.home" extends="secure.root">
  <put name="page" value="..." />
</definition>

<definition name="insecure.login" extends="insecure.root">
  <put name="page" value="..." />
</definition>

You'd be better served to use a filter to determine if a user is logged in 
and send them to your login page if they aren't, but the above should help 
you out, I think, if you're already heavily invested in this direction.

Regards,

Eddie

----- Original Message ----- 
From: "Dave Newton" <ne...@pingsite.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Friday, May 27, 2005 12:29 PM
Subject: Re: problem with logic redirect tag and tiles


> Paul Moody wrote:
>
>>I have a problem using logic:redirect with tiles.
>>[...]
>>Any ideas?
>>
> Could it be because a redirect only works if no data has been sent to the 
> browser yet? (But I thought I saw an HTML comment before the redirect that 
> works, so maybe that's not the right trail to head down.)
>
> Dave 



---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0521-4, 05/27/2005
Tested on: 5/28/2005 12:32:08 PM
avast! - copyright (c) 2000-2004 ALWIL Software.
http://www.avast.com




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


Re: problem with logic redirect tag and tiles

Posted by Dave Newton <ne...@pingsite.com>.
Paul Moody wrote:

>I have a problem using logic:redirect with tiles.
>[...]
>Any ideas?
>
Could it be because a redirect only works if no data has been sent to 
the browser yet? (But I thought I saw an HTML comment before the 
redirect that works, so maybe that's not the right trail to head down.)

Dave



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