Peter, thanks for the contribution!

I've reviewed your code and the PortletTilesRequestProcessor is almost the same 
as
what I had defined myself already :-)
Your's is still based on the older Struts Bridge 0.1 version though.
The current version now also checks if it is running within a PortletContext and
if not just delegates to its parent.

Concerning the patches: I don't thin we need the saving of the Tiles 
ComponentContext
in the StrutsRenderContext after ActionRequest processing.

The proper usage of Struts Actions within a Portlet Context (or any portlet 
event handler
for that matter) is to clearly separate the behavior for ActionRequest and 
RenderRequest
processing (a MVC model enforced by the Portlet specification).

I normally do this by defining two Action mappings for the processing of an 
ActionRequest:
  a doAction and a viewAction.
The doAction should forward to the viewAction using a forward definition with 
redirect="true".
The redirect="true" will inform the Struts Bridge that the new Struts target 
url is the viewAction.
Without it, the original doAction will be executed *again* in the RenderRequest 
first!

Now, I can imagine that you have an existing TilesAction in which you put some 
attributes
in the current Tiles ComponentContext.
If that TilesAction is accessed during ActionRequest processing you would lose 
the
ComponentContext attributes just set because of the following redirect (always 
done by the
Pluto Container).

But, putting the ComponentContext in the StrutsRenderContext won't be a solid 
solution!

Only during the *first* following RenderRequest will the ComponentContext be 
restored as it is
for one use only. This means that if you refresh your browser page or click on 
any other
PortletURL (like a maximize button or access a different Portlet on the same 
page) your
ComponentContext attributes won't be available again on the subsequent 
RenderRequest, and you
layout is probably screwed.

There are two solutions to this problem which don't need saving the 
ComponentContext in the
StrutsRenderContext:
1) Split your TilesAction up in a doAction (shouldn't need to extend 
TilesAction anymore) and
   a viewAction and forward (with redirect="true") from the doAction to the 
viewAction.
   The viewAction (a TilesAction) then should define the ComponentContext 
attributes so these
   will always be set again on each RenderRequest.
2) Migrate to the latest Struts Bridge cvs head version (0.2) and use the new 
RenderContextAttributes
   feature which you can configure in a struts-portlet-config.xml.
   See http://nagoya.apache.org/eyebrowse/ReadMsg?listId=22&msgNo=19866 for 
preliminary
   documentation, I hope to provide proper documentation today or tomorrow.
   Not yet described in the above announcement is an optional "keep" boolean 
attribute for
   RenderContextAttributes. If set to true, these attribute will be restored 
every subsequent
   RenderRequest unless the targeted application url is changed or an 
ActionRequest is performed.
   Only then will these attributes be removed (from the session).
   You can interpret these RenderContextAttributes as being "scoped" to one 
ActionRequest and
   its resulting RenderRequest(s) only (which is a very, very nice feature I 
think).

   So, if you define the following in your struts-portlet-config.xml:

       <render-context>
         <attribute name="org.apache.struts.taglib.tiles.CompContext" 
keep="true"/>
       </render-context>

   you'll have the same effect as saving the ComponentContext in the 
StrutsRenderContext but
   then solid!

Although I'm not going to need your contribution anymore, I am very thankful 
for it as it focussed
me exactly on the potential problems we might encounter with the Tiles support.

Now that I've scanned all of the relevant Tiles code I don't see any more 
issues with it, provided
one uses a proper Action mapping and/or use the new RenderContextAttributes as 
described above.
So, I will commit a TilesPortletRequestProcessor today!

I know you also have planned more contributions and I'm looking forward to them!


Houston, we have Tiles support!

Regards, Ate


Peter Meier wrote:
Hi,

I'd like to join the discussion around Jetspeed 2 development and initially submit a working solution for Tiles support to the current J2 Struts bridge. The solution comprises a PortletTilesRequestProcessor, which extends org.apache.struts.tiles.TilesRequestProcessor the same way as PortletRequestProcessor extends org.apache.struts.action.RequestProcessor, and a few code patches for PortletServlet, PortletServletRequestDispatcher, and StrutsPortletRenderContext.These patches, in principal, take care of saving and restoring some context that would otherwise be lost due to the separation of action and render request. This context is Tiles specific and just added at places where the other Struts information is usually saved and restored. In order to use the PortletTilesRequestProcessor the controller tag in struts-config.xml has to reference it.
Please find attached the code; the code patches are marked accordingly. Please note that the code is based on the J2M1 release, and thus probably on Struts bridge version 0.1.
I am looking forward to receive feedback or comments.


Regards,
Peter

Architect,
TEC
Wellington, New Zealand
email: [EMAIL PROTECTED]


_org.apache.portals.bridges.struts.PortletTilesRequestProcessor_

/*
* Copyright 2000-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/


package org.apache.portals.bridges.struts;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionMapping;
import org.apache.struts.tiles.TilesRequestProcessor;


/** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Meier </a> */ public class PortletTilesRequestProcessor extends TilesRequestProcessor {

   public PortletTilesRequestProcessor() {

       super();
   }

public void process( HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException {

if ( !( response instanceof PortletServletResponseWrapper ) ) {
response = new PortletServletResponseWrapper( request, response );
}
super.process( request, response );
}


protected boolean processRoles( HttpServletRequest request, HttpServletResponse response, ActionMapping mapping )
throws IOException, ServletException {


boolean proceed = super.processRoles( request, response, mapping );
if ( proceed && ( (PortletServlet)super.servlet ).performActionRenderRequest( request, response, mapping ) ) {
return false;
}
else
return proceed;
}
}



_org.apache.portals.bridges.struts.StrutsPortletRenderContext_

/*
* Copyright 2000-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.portals.bridges.struts;

import java.io.Serializable;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.tiles.ComponentContext;


/**
* StrutsPortletRenderContext
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ate Douma </a>
* @version $Id: StrutsPortletRenderContext.java,v 1.1 2004/07/29 22:16:40 ate Exp $
*/
public class StrutsPortletRenderContext implements Serializable {


   private String path;
   private boolean dispatchNamed;
   private ActionForm actionForm;
   private boolean requestCancelled;
   private ActionMessages messages;
   private ActionMessages errors;

   // BEGIN: INSERT
   //
   private ComponentContext tilesComponentContext;

   //
   // END: INSERT

   public String getPath() {

       return path;
   }

   public void setPath( String path ) {

       this.path = path;
   }

   public boolean getDispatchNamed() {

       return dispatchNamed;
   }

   public void setDispatchNamed( boolean namedPath ) {

       this.dispatchNamed = namedPath;
   }

   public ActionForm getActionForm() {

       return actionForm;
   }

   public void setActionForm( ActionForm actionForm ) {

       this.actionForm = actionForm;
   }

   public boolean isRequestCancelled() {

       return requestCancelled;
   }

   public void setRequestCancelled( boolean requestCancelled ) {

       this.requestCancelled = requestCancelled;
   }

   public ActionMessages getMessages() {

       return messages;
   }

   public void setMessages( ActionMessages messages ) {

       this.messages = messages;
   }

   public ActionMessages getErrors() {

       return errors;
   }

   public void setErrors( ActionMessages errors ) {

       this.errors = errors;
   }

   public ComponentContext getTilesComponentContext() {

       return tilesComponentContext;
   }

// BEGIN: INSERT
//
public void setTilesComponentContext( ComponentContext tilesComponentContext ) {


       this.tilesComponentContext = tilesComponentContext;
   }
   //
   // END: INSERT
}


_org.apache.portals.bridges.struts.PortletServletRequestDispatcher_

/*
* Copyright 2000-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.portals.bridges.struts;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.portals.bridges.struts.util.HttpRequestDispatcherImpl;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.config.ActionConfig;
import org.apache.struts.taglib.tiles.ComponentConstants;
import org.apache.struts.tiles.ComponentContext;


/**
* PortletServletRequestDispatcher
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ate Douma </a>
* @version $Id: PortletServletRequestDispatcher.java,v 1.2 2004/11/27 01:04:12 ate Exp $
*/
public class PortletServletRequestDispatcher extends HttpRequestDispatcherImpl {


private static final Log log = LogFactory.getLog( PortletServletRequestDispatcher.class );
private boolean named;


public PortletServletRequestDispatcher( RequestDispatcher dispatcher, String path, boolean named ) {

       super( dispatcher, path );
   }

protected void invoke( ServletRequest request, ServletResponse response, boolean include ) throws ServletException,
IOException {


String request_type = (String)request.getAttribute( StrutsPortlet.REQUEST_TYPE );
if ( request_type != null && request_type.equals( StrutsPortlet.ACTION_REQUEST ) ) {
if ( log.isDebugEnabled() ) {
log.debug( "saving " + ( named ? "named " : " " ) + "dispatch to :" + getPath() + ", from " + request_type
+ " " + StrutsPortletURL.getPageURL( request ) );
}
HttpServletRequest req = (HttpServletRequest)request;
StrutsPortletRenderContext context = new StrutsPortletRenderContext();
context.setPath( getPath() );
context.setDispatchNamed( named );
ActionConfig actionConfig = (ActionConfig)request.getAttribute( Globals.MAPPING_KEY );
if ( actionConfig != null ) {
if ( actionConfig.getAttribute() != null && actionConfig.getScope().equals( "request" ) ) {
ActionForm actionForm = (ActionForm)request.getAttribute( actionConfig.getAttribute() );
context.setActionForm( actionForm );
Boolean requestCancelled = (Boolean)request.getAttribute( Globals.CANCEL_KEY );
if ( requestCancelled != null && requestCancelled.booleanValue() ) context.setRequestCancelled( true );
}
}
context.setMessages( (ActionMessages)request.getAttribute( Globals.MESSAGE_KEY ) );
context.setErrors( (ActionMessages)request.getAttribute( Globals.ERROR_KEY ) );
if ( context.getErrors() != null ) {
String originURL = StrutsPortletURL.getOriginURL( request );
if ( originURL != null ) {
request.setAttribute( StrutsPortlet.REDIRECT_PAGE_URL, originURL );
}
}


// INSERT START
//
context.setTilesComponentContext( (ComponentContext)request.getAttribute( ComponentConstants.COMPONENT_CONTEXT ) );
//
// INSERT END


String portletName = (String)req.getAttribute( StrutsPortlet.PORTLET_NAME );
req.getSession( true ).setAttribute( StrutsPortlet.RENDER_CONTEXT + "_" + portletName, context );
}
else {
if ( log.isDebugEnabled() ) {
log.debug( "invoking " + ( named ? "named " : " " ) + " dispatch to :" + getPath() + ", from " + request_type
+ " " + StrutsPortletURL.getPageURL( request ) );
}
super.invoke( request, response, true );
}
}
}



_org.apache.portals.bridges.struts.PortletServlet_

/*
* Copyright 2000-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/


package org.apache.portals.bridges.struts;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.Globals;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.taglib.tiles.ComponentConstants;


/** * PortletServlet * * @author <a href="mailto:[EMAIL PROTECTED]">Ate Douma </a> * @version $Id: PortletServlet.java,v 1.2 2004/11/27 01:04:12 ate Exp $ */ public class PortletServlet extends ActionServlet {

   public PortletServlet() {

       super();
   }

   public void init( ServletConfig config ) throws ServletException {

       super.init( new PortletServletConfigImpl( config ) );
   }

   public ServletContext getServletContext() {

       return getServletConfig().getServletContext();
   }

public boolean performActionRenderRequest( HttpServletRequest request, HttpServletResponse response, ActionMapping mapping )
throws IOException, ServletException {


if ( !request.getAttribute( StrutsPortlet.REQUEST_TYPE ).equals( StrutsPortlet.ACTION_REQUEST ) ) {
StrutsPortletRenderContext context = null;


String portletName = (String)request.getAttribute( StrutsPortlet.PORTLET_NAME );

String contextKey = StrutsPortlet.RENDER_CONTEXT + "_" + portletName;
context = (StrutsPortletRenderContext)request.getSession( true ).getAttribute( contextKey );
if ( context != null ) {
if ( log.isDebugEnabled() ) {
log.debug( "render context path: " + context.getPath() );
}
request.getSession().removeAttribute( contextKey );
if ( context.getActionForm() != null ) {
String attribute = mapping.getAttribute();
if ( attribute != null ) {
if ( log.isDebugEnabled() ) {
log.debug( "Putting form " + context.getActionForm().getClass().getName() + " into request as "
+ attribute + " for mapping " + mapping.getName() );
}
request.setAttribute( mapping.getAttribute(), context.getActionForm() );
}
else if ( log.isWarnEnabled() ) {
log.warn( "Attribute is null for form " + context.getActionForm().getClass().getName()
+ ", won't put it into request for mapping " + mapping.getName() );
}
}
if ( context.isRequestCancelled() ) request.setAttribute( Globals.CANCEL_KEY, Boolean.TRUE );
if ( context.getMessages() != null ) request.setAttribute( Globals.MESSAGE_KEY, context.getMessages() );
if ( context.getErrors() != null ) request.setAttribute( Globals.ERROR_KEY, context.getErrors() );


// BEGIN: INSERT
//
if ( context.getTilesComponentContext() != null )
request.setAttribute( ComponentConstants.COMPONENT_CONTEXT, context.getTilesComponentContext() );
//
// END: INSERT


RequestDispatcher dispatcher = null;
if ( context.getDispatchNamed() )
dispatcher = getServletContext().getNamedDispatcher( context.getPath() );
else
dispatcher = getServletContext().getRequestDispatcher( context.getPath() );
dispatcher.include( request, response );
return true;
}
}
return false;
}
}




------------------------------------------------------------------------

/*
* Copyright 2000-2004 The Apache Software Foundation.
* * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* * http://www.apache.org/licenses/LICENSE-2.0
* * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


package org.apache.portals.bridges.struts;

import java.io.Serializable;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.tiles.ComponentContext;


/**
* StrutsPortletRenderContext
* * @author <a href="mailto:[EMAIL PROTECTED]">Ate Douma </a>
* @version $Id: StrutsPortletRenderContext.java,v 1.1 2004/07/29 22:16:40 ate Exp $
*/
public class StrutsPortletRenderContext implements Serializable {


    private String path;
    private boolean dispatchNamed;
    private ActionForm actionForm;
    private boolean requestCancelled;
    private ActionMessages messages;
    private ActionMessages errors;

    // BEGIN: INSERT
    //
    private ComponentContext tilesComponentContext;

    //
    // END: INSERT

    public String getPath() {

        return path;
    }

    public void setPath( String path ) {

        this.path = path;
    }

    public boolean getDispatchNamed() {

        return dispatchNamed;
    }

    public void setDispatchNamed( boolean namedPath ) {

        this.dispatchNamed = namedPath;
    }

    public ActionForm getActionForm() {

        return actionForm;
    }

    public void setActionForm( ActionForm actionForm ) {

        this.actionForm = actionForm;
    }

    public boolean isRequestCancelled() {

        return requestCancelled;
    }

    public void setRequestCancelled( boolean requestCancelled ) {

        this.requestCancelled = requestCancelled;
    }

    public ActionMessages getMessages() {

        return messages;
    }

    public void setMessages( ActionMessages messages ) {

        this.messages = messages;
    }

    public ActionMessages getErrors() {

        return errors;
    }

    public void setErrors( ActionMessages errors ) {

        this.errors = errors;
    }

    public ComponentContext getTilesComponentContext() {

        return tilesComponentContext;
    }

    // BEGIN: INSERT
    //
    public void setTilesComponentContext( ComponentContext 
tilesComponentContext ) {

        this.tilesComponentContext = tilesComponentContext;
    }
    //
    // END: INSERT
}


------------------------------------------------------------------------

/*
* Copyright 2000-2004 The Apache Software Foundation.
* * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* * http://www.apache.org/licenses/LICENSE-2.0
* * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


package org.apache.portals.bridges.struts;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.portals.bridges.struts.util.HttpRequestDispatcherImpl;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.config.ActionConfig;
import org.apache.struts.taglib.tiles.ComponentConstants;
import org.apache.struts.tiles.ComponentContext;


/**
* PortletServletRequestDispatcher
* * @author <a href="mailto:[EMAIL PROTECTED]">Ate Douma </a>
* @version $Id: PortletServletRequestDispatcher.java,v 1.2 2004/11/27 01:04:12 ate Exp $
*/
public class PortletServletRequestDispatcher extends HttpRequestDispatcherImpl {


    private static final Log log = LogFactory.getLog( 
PortletServletRequestDispatcher.class );
    private boolean named;

    public PortletServletRequestDispatcher( RequestDispatcher dispatcher, 
String path, boolean named ) {

        super( dispatcher, path );
    }

    protected void invoke( ServletRequest request, ServletResponse response, 
boolean include ) throws ServletException,
            IOException {

        String request_type = (String)request.getAttribute( 
StrutsPortlet.REQUEST_TYPE );
        if ( request_type != null && request_type.equals( 
StrutsPortlet.ACTION_REQUEST ) ) {
            if ( log.isDebugEnabled() ) {
                log.debug( "saving " + ( named ? "named " : " " ) + "dispatch to :" + 
getPath() + ", from " + request_type
                        + " " + StrutsPortletURL.getPageURL( request ) );
            }
            HttpServletRequest req = (HttpServletRequest)request;
            StrutsPortletRenderContext context = new 
StrutsPortletRenderContext();
            context.setPath( getPath() );
            context.setDispatchNamed( named );
            ActionConfig actionConfig = (ActionConfig)request.getAttribute( 
Globals.MAPPING_KEY );
            if ( actionConfig != null ) {
                if ( actionConfig.getAttribute() != null && 
actionConfig.getScope().equals( "request" ) ) {
                    ActionForm actionForm = (ActionForm)request.getAttribute( 
actionConfig.getAttribute() );
                    context.setActionForm( actionForm );
                    Boolean requestCancelled = (Boolean)request.getAttribute( 
Globals.CANCEL_KEY );
                    if ( requestCancelled != null && 
requestCancelled.booleanValue() ) context.setRequestCancelled( true );
                }
            }
            context.setMessages( (ActionMessages)request.getAttribute( 
Globals.MESSAGE_KEY ) );
            context.setErrors( (ActionMessages)request.getAttribute( 
Globals.ERROR_KEY ) );
            if ( context.getErrors() != null ) {
                String originURL = StrutsPortletURL.getOriginURL( request );
                if ( originURL != null ) {
                    request.setAttribute( StrutsPortlet.REDIRECT_PAGE_URL, 
originURL );
                }
            }

            // INSERT START
            //
            context.setTilesComponentContext( 
(ComponentContext)request.getAttribute( ComponentConstants.COMPONENT_CONTEXT ) 
);
            //
            // INSERT END

            String portletName = (String)req.getAttribute( 
StrutsPortlet.PORTLET_NAME );
            req.getSession( true ).setAttribute( StrutsPortlet.RENDER_CONTEXT + 
"_" + portletName, context );
        }
        else {
            if ( log.isDebugEnabled() ) {
                log.debug( "invoking " + ( named ? "named " : " " ) + " dispatch to :" + 
getPath() + ", from " + request_type
                        + " " + StrutsPortletURL.getPageURL( request ) );
            }
            super.invoke( request, response, true );
        }
    }
}


------------------------------------------------------------------------

/*
* Copyright 2000-2004 The Apache Software Foundation.
* * Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* * http://www.apache.org/licenses/LICENSE-2.0
* * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/


package org.apache.portals.bridges.struts;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.Globals;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.taglib.tiles.ComponentConstants;


/**
* PortletServlet
* * @author <a href="mailto:[EMAIL PROTECTED]">Ate Douma </a>
* @version $Id: PortletServlet.java,v 1.2 2004/11/27 01:04:12 ate Exp $
*/
public class PortletServlet extends ActionServlet {


    public PortletServlet() {

        super();
    }

    public void init( ServletConfig config ) throws ServletException {

        super.init( new PortletServletConfigImpl( config ) );
    }

    public ServletContext getServletContext() {

        return getServletConfig().getServletContext();
    }

    public boolean performActionRenderRequest( HttpServletRequest request, 
HttpServletResponse response, ActionMapping mapping )
            throws IOException, ServletException {

        if ( !request.getAttribute( StrutsPortlet.REQUEST_TYPE ).equals( 
StrutsPortlet.ACTION_REQUEST ) ) {
            StrutsPortletRenderContext context = null;

            String portletName = (String)request.getAttribute( 
StrutsPortlet.PORTLET_NAME );

            String contextKey = StrutsPortlet.RENDER_CONTEXT + "_" + 
portletName;
            context = (StrutsPortletRenderContext)request.getSession( true 
).getAttribute( contextKey );
            if ( context != null ) {
                if ( log.isDebugEnabled() ) {
                    log.debug( "render context path: " + context.getPath() );
                }
                request.getSession().removeAttribute( contextKey );
                if ( context.getActionForm() != null ) {
                    String attribute = mapping.getAttribute();
                    if ( attribute != null ) {
                        if ( log.isDebugEnabled() ) {
                            log.debug( "Putting form " + 
context.getActionForm().getClass().getName() + " into request as "
                                    + attribute + " for mapping " + 
mapping.getName() );
                        }
                        request.setAttribute( mapping.getAttribute(), 
context.getActionForm() );
                    }
                    else if ( log.isWarnEnabled() ) {
                        log.warn( "Attribute is null for form " + 
context.getActionForm().getClass().getName()
                                + ", won't put it into request for mapping " + 
mapping.getName() );
                    }
                }
                if ( context.isRequestCancelled() ) request.setAttribute( 
Globals.CANCEL_KEY, Boolean.TRUE );
                if ( context.getMessages() != null ) request.setAttribute( 
Globals.MESSAGE_KEY, context.getMessages() );
                if ( context.getErrors() != null ) request.setAttribute( 
Globals.ERROR_KEY, context.getErrors() );

                // BEGIN: INSERT
                //
                if ( context.getTilesComponentContext() != null )
                        request.setAttribute( 
ComponentConstants.COMPONENT_CONTEXT, context.getTilesComponentContext() );
                //
                // END: INSERT

                RequestDispatcher dispatcher = null;
                if ( context.getDispatchNamed() )
                    dispatcher = getServletContext().getNamedDispatcher( 
context.getPath() );
                else
                    dispatcher = getServletContext().getRequestDispatcher( 
context.getPath() );
                dispatcher.include( request, response );
                return true;
            }
        }
        return false;
    }
}


------------------------------------------------------------------------

/*
* Copyright 2000-2004 The Apache Software Foundation.
* * Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* * http://www.apache.org/licenses/LICENSE-2.0
* * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/


package org.apache.portals.bridges.struts;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionMapping;
import org.apache.struts.tiles.TilesRequestProcessor;


/** * @author <a href="mailto:[EMAIL PROTECTED]">Peter Meier </a> */ public class PortletTilesRequestProcessor extends TilesRequestProcessor {

    public PortletTilesRequestProcessor() {

        super();
    }

    public void process( HttpServletRequest request, HttpServletResponse 
response ) throws IOException, ServletException {

        if ( !( response instanceof PortletServletResponseWrapper ) ) {
            response = new PortletServletResponseWrapper( request, response );
        }
        super.process( request, response );
    }

    protected boolean processRoles( HttpServletRequest request, 
HttpServletResponse response, ActionMapping mapping )
            throws IOException, ServletException {

        boolean proceed = super.processRoles( request, response, mapping );
        if ( proceed && ( (PortletServlet)super.servlet 
).performActionRenderRequest( request, response, mapping ) ) {
            return false;
        }
        else
            return proceed;
    }
}


------------------------------------------------------------------------

---------------------------------------------------------------------
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