You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jim Crossley <jc...@ifleet.com> on 2002/02/06 15:30:03 UTC

Dynamic tiles (attn: Cedric)

I've just started using Tiles, and I really like it.

I want to be able to overload my attributes in my struts actions prior
to forwarding to the tiles definitions, but I'm having some trouble.
I found this message in the archives:

http://www.mail-archive.com/struts-user%40jakarta.apache.org/msg16127.html

But I can't seem to make it work.  When I attempt to run
tiles-doc/test/testAction, I get this:

Error
Can't get component context. 

It seems ComponentContext.getContext(request) always returns null.

I'm using Struts 1.0.1 with the current Tiles (2002 01 11, I think).

Any advice?

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Dynamic tiles (attn: Cedric)

Posted by Cedric Dumoulin <ce...@lifl.fr>.

Jim Crossley wrote:

> I'm now beginning to think that what I really need is a Controller, so
> I'm going to focus my efforts there for now.  The docs mention that a
> Controller could be implemented as a Struts action.  Does that require
> the Action to implement the Controller interface or is there some
> Tiles magic that occurs merely by setting the controllerClass
> attribute in the definition?

  There is some magic. Tiles check whether you use Action or Controller interface.
If you use Action, it will wrap it with a Controller interface.
   Also you can put the url of your Struts action as controller, with no change to
the action <tiles:insert ... controllerUrl="action.do" />.

  My prefer way is to extends TilesAction (which itself extends struts action), and
implements the new perform() which provide an extra parameter (the tile context !).

  Cedric


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Dynamic tiles (attn: Cedric)

Posted by Jim Crossley <jc...@ifleet.com>.
Ok, after looking at testStrutsAction.jsp, I realized that
testAction.do is not doing exactly what I thought it was, and invoking
it standalone was never going to work anyway.

I'm now beginning to think that what I really need is a Controller, so
I'm going to focus my efforts there for now.  The docs mention that a
Controller could be implemented as a Struts action.  Does that require
the Action to implement the Controller interface or is there some
Tiles magic that occurs merely by setting the controllerClass
attribute in the definition?

Sorry to be a pest, but I'm trying to get up to speed quickly and the
docs are a bit overwhelming (I'm not complaining, mind you :-).

-- Jim

Jim Crossley <jc...@ifleet.com> writes:

> Cedric Dumoulin <ce...@lifl.fr> writes:
> 
> > tiles-doc.jar is shipped with Struts1.1 previous than 15 jan, and is
> > ready to run. So you can try the mentioned url test directly on it,
> > and it should run. If not, let me know.
> 
> This runs:
>   http://localhost:8080/tiles-doc/test/testStrutsAction.jsp
> 
> This does not:
>   http://localhost:8080/tiles-doc/test/testAction.do
> 
> It doesn't because the call to ComponentContext.getContext(request) in
> org.apache.struts.example.tiles.test.TestActionTileAction returns
> null.
> 
> So I'm still not sure how to overload definition attributes (specified
> in an XML file) in a Struts action.  :-(
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Dynamic tiles (attn: Cedric)

Posted by Cedric Dumoulin <ce...@lifl.fr>.
  If the actionForward contains a definition name, the definition is retrieved,
and missing attributes are added to your definition. Otherwise, ActionForward has
no effect, and I think you should be able to return null.

Jim Crossley wrote:

> One more question...
>
> >  ComponentDefinition definition =
> >      DefinitionsUtil.getDefinition(mapping.findForward("success").getPath(),
> >                                    request,
> >                                    getServlet().getServletContext());
> >  definition.putAttribute( "title", "Overloaded title" );
> >  DefinitionsUtil.setActionDefinition( request, definition);
>
> Once the above code is executed in Action.perform, how does the
> subsequent return value (ActionForward) affect the definition
> previously set?
>
> In other words, once I call setActionDefinition, does it matter which
> ActionForward I return?  Could I simply return a new ActionForward()?
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Dynamic tiles (attn: Cedric)

Posted by Jim Crossley <jc...@ifleet.com>.
One more question...

>  ComponentDefinition definition =
>      DefinitionsUtil.getDefinition(mapping.findForward("success").getPath(),
>                                    request,
>                                    getServlet().getServletContext());
>  definition.putAttribute( "title", "Overloaded title" );
>  DefinitionsUtil.setActionDefinition( request, definition);

Once the above code is executed in Action.perform, how does the
subsequent return value (ActionForward) affect the definition
previously set?

In other words, once I call setActionDefinition, does it matter which
ActionForward I return?  Could I simply return a new ActionForward()?

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Dynamic tiles (attn: Cedric)

Posted by Cedric Dumoulin <ce...@lifl.fr>.

Jim Crossley wrote:

> Thanks, Cedric.  I got this to work in the perform method of my Action
> class:
>
>    ComponentDefinition definition =
>        DefinitionsUtil.getDefinition(mapping.findForward("success").getPath(),
>                                      request,
>                                      getServlet().getServletContext());
>    definition.putAttribute( "title", "Overloaded title" );
>    DefinitionsUtil.setActionDefinition( request, definition);
>
> Does it make sense to override the Tiles ActionServlet to invoke the
> above code to make some dynamic attributes available to all of my
> definition views?  Or would the Controller class be a better solution?
>

  It depends of what you want. If you want such behavior on all your definitions
views, why not. If you want it just on some definitions, use controller.

>
> -- Jim
>
> Cedric Dumoulin <ce...@lifl.fr> writes:
>
> >   So your install seem to work perfectly. Sorry for the wrong
> >   response before, it > is what happen when you do to much things in
> >   the same time.
> >
> >   It is normal that the componentContext is not found if you access
> >   directly the > action (with *.do). The context is set when the
> >   tile is inserted, or when an > action forward to a tile.
> >
> >   It work in the first url, because the action is inserted, so the
> >   context > created.  A workaround is to have another action
> >   forwarding to the action overloading > parameter.  Another
> >   possibility is to define a definition with appropriate attributes,
> >   and > set it in jsp context as in (not tested)
> >
> >   ComponentDefinition definition = new ComponentDefinition();
> >     // initialize definition here. If struts forward also specify a definition,
> > attributes defined here will preval
> >     definition.putAttribute( "attributeName", "aValue" );
> >       ....
> >      // Set def to be used by struts forward
> >   DefinitionsUtil.setActionDefinition( request, definition);
> >   return (mapping.findForward("success"));
> >
> >   Also check example/tiles/test/TestActionTileAction.java
> >
> >    Hope this help,
> >
> >       Cedric
> >
> >
> > Jim Crossley wrote:
> >
> > > Cedric Dumoulin <ce...@lifl.fr> writes:
> > >
> > > > tiles-doc.jar is shipped with Struts1.1 previous than 15 jan, and is
> > > > ready to run. So you can try the mentioned url test directly on it,
> > > > and it should run. If not, let me know.
> > >
> > > This runs:
> > >   http://localhost:8080/tiles-doc/test/testStrutsAction.jsp
> > >
> > > This does not:
> > >   http://localhost:8080/tiles-doc/test/testAction.do
> > >
> > > It doesn't because the call to ComponentContext.getContext(request) in
> > > org.apache.struts.example.tiles.test.TestActionTileAction returns
> > > null.
> > >
> > > So I'm still not sure how to overload definition attributes (specified
> > > in an XML file) in a Struts action.  :-(
> > >
> > > --
> > > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > > For additional commands, e-mail: <ma...@jakarta.apache.org>
> >
> >
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Dynamic tiles (attn: Cedric)

Posted by Jim Crossley <jc...@ifleet.com>.
Thanks, Cedric.  I got this to work in the perform method of my Action
class:

   ComponentDefinition definition =
       DefinitionsUtil.getDefinition(mapping.findForward("success").getPath(),
                                     request,
                                     getServlet().getServletContext());
   definition.putAttribute( "title", "Overloaded title" );
   DefinitionsUtil.setActionDefinition( request, definition);

Does it make sense to override the Tiles ActionServlet to invoke the
above code to make some dynamic attributes available to all of my
definition views?  Or would the Controller class be a better solution?

-- Jim

Cedric Dumoulin <ce...@lifl.fr> writes:

>   So your install seem to work perfectly. Sorry for the wrong
>   response before, it > is what happen when you do to much things in
>   the same time.
> 
>   It is normal that the componentContext is not found if you access
>   directly the > action (with *.do). The context is set when the
>   tile is inserted, or when an > action forward to a tile.
> 
>   It work in the first url, because the action is inserted, so the
>   context > created.  A workaround is to have another action
>   forwarding to the action overloading > parameter.  Another
>   possibility is to define a definition with appropriate attributes,
>   and > set it in jsp context as in (not tested)
> 
>   ComponentDefinition definition = new ComponentDefinition();
>     // initialize definition here. If struts forward also specify a definition,
> attributes defined here will preval
>     definition.putAttribute( "attributeName", "aValue" );
>       ....
>      // Set def to be used by struts forward
>   DefinitionsUtil.setActionDefinition( request, definition);
>   return (mapping.findForward("success"));
> 
>   Also check example/tiles/test/TestActionTileAction.java
> 
>    Hope this help,
> 
>       Cedric
> 
> 
> Jim Crossley wrote:
> 
> > Cedric Dumoulin <ce...@lifl.fr> writes:
> >
> > > tiles-doc.jar is shipped with Struts1.1 previous than 15 jan, and is
> > > ready to run. So you can try the mentioned url test directly on it,
> > > and it should run. If not, let me know.
> >
> > This runs:
> >   http://localhost:8080/tiles-doc/test/testStrutsAction.jsp
> >
> > This does not:
> >   http://localhost:8080/tiles-doc/test/testAction.do
> >
> > It doesn't because the call to ComponentContext.getContext(request) in
> > org.apache.struts.example.tiles.test.TestActionTileAction returns
> > null.
> >
> > So I'm still not sure how to overload definition attributes (specified
> > in an XML file) in a Struts action.  :-(
> >
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Dynamic tiles (attn: Cedric)

Posted by Cedric Dumoulin <ce...@lifl.fr>.
  So your install seem to work perfectly. Sorry for the wrong response before, it
is what happen when you do to much things in the same time.

  It is normal that the componentContext is not found if you access directly the
action (with *.do). The context is set when the tile is inserted, or when an
action forward to a tile.

  It work in the first url, because the action is inserted, so the context
created.
  A workaround is to have another action forwarding to the action overloading
parameter.
  Another possibility is to define a definition with appropriate attributes, and
set it in jsp context as in (not tested)

  ComponentDefinition definition = new ComponentDefinition();
    // initialize definition here. If struts forward also specify a definition,
attributes defined here will preval
    definition.putAttribute( "attributeName", "aValue" );
      ....
     // Set def to be used by struts forward
  DefinitionsUtil.setActionDefinition( request, definition);
  return (mapping.findForward("success"));

  Also check example/tiles/test/TestActionTileAction.java

   Hope this help,

      Cedric


Jim Crossley wrote:

> Cedric Dumoulin <ce...@lifl.fr> writes:
>
> > tiles-doc.jar is shipped with Struts1.1 previous than 15 jan, and is
> > ready to run. So you can try the mentioned url test directly on it,
> > and it should run. If not, let me know.
>
> This runs:
>   http://localhost:8080/tiles-doc/test/testStrutsAction.jsp
>
> This does not:
>   http://localhost:8080/tiles-doc/test/testAction.do
>
> It doesn't because the call to ComponentContext.getContext(request) in
> org.apache.struts.example.tiles.test.TestActionTileAction returns
> null.
>
> So I'm still not sure how to overload definition attributes (specified
> in an XML file) in a Struts action.  :-(
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Dynamic tiles (attn: Cedric)

Posted by Jim Crossley <jc...@ifleet.com>.
Cedric Dumoulin <ce...@lifl.fr> writes:

> tiles-doc.jar is shipped with Struts1.1 previous than 15 jan, and is
> ready to run. So you can try the mentioned url test directly on it,
> and it should run. If not, let me know.

This runs:
  http://localhost:8080/tiles-doc/test/testStrutsAction.jsp

This does not:
  http://localhost:8080/tiles-doc/test/testAction.do

It doesn't because the call to ComponentContext.getContext(request) in
org.apache.struts.example.tiles.test.TestActionTileAction returns
null.

So I'm still not sure how to overload definition attributes (specified
in an XML file) in a Struts action.  :-(

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Dynamic tiles (attn: Cedric)

Posted by Cedric Dumoulin <ce...@lifl.fr>.
  tiles-doc.jar is shipped with Struts1.1 previous than 15 jan, and is ready to run. So
you can try the mentioned url test directly on it, and it should run. If not, let me
know.

  However, you have mentioned that you try to use Tiles with Struts1.0.1. If true, you
need to use tilesForStruts1-0.jar instead of tiles.jar.
  Both tiles jar contains exactly the same compiled classes, but one is compiled with
Struts1.1, and the other with Struts1.0. They are not fully compatible due to some
changes in some base classes in Struts. Don't forget to remove tiles.jar if you want
tilesForStruts1-0.jar be taken into account.

Jim Crossley wrote:

> I don't mean to be a bondhead, but all I did was copy the
> tiles-doc.jar to Tomcat's webapps directory.  Wouldn't it be bundled
> with the correct struts version?
>
> The page, /test/testStrutsAction.jsp, *does* run correctly, but
> /test/testAction.do does not.  It's the latter that seems to be what I
> need to get working, right?
>
> Also, the two tiles jar files seem to be the same size:
>
> -rw-r--r--    1 jim    jim      80633 Jan 14 08:52 tiles.jar
> -rw-r--r--    1 jim    jim      80633 Jan 14 08:52 tilesForStruts1-0.jar
>
> Is that just a coincidence or might the current tiles distribution be
> messed up?  In my app, either jar file seems to work fine.
>
> -- Jim
>
> Cedric Dumoulin <ce...@lifl.fr> writes:
>
> >   First, check that you use tilesForStruts1.0.jar, as you are using Struts1.0.1.
> >   Second, check if your tiles/struts1.0.1 installation works :
> >
> >    * install tiles-doc.jar or struts-tiles.jar
> >    * replace WEB-INF/lib/struts.jar with struts.jar from 1.0.1
> >    * replace tiles.jar with tilesForStruts1.0.jar (remove the first and put the
> >      second)
> >    * start your web container
> >    * try url ???/test/testStrutsAction.jsp
> >         o If this run correctly, your installation is correct, if not, there is a
> >           problem with install
> >
> >     Cedric
> >
> > Jim Crossley wrote:
> >
> > > I've just started using Tiles, and I really like it.
> > >
> > > I want to be able to overload my attributes in my struts actions prior
> > > to forwarding to the tiles definitions, but I'm having some trouble.
> > > I found this message in the archives:
> > >
> > > http://www.mail-archive.com/struts-user%40jakarta.apache.org/msg16127.html
> > >
> > > But I can't seem to make it work.  When I attempt to run
> > > tiles-doc/test/testAction, I get this:
> > >
> > > Error
> > > Can't get component context.
> > >
> > > It seems ComponentContext.getContext(request) always returns null.
> > >
> > > I'm using Struts 1.0.1 with the current Tiles (2002 01 11, I think).
> > >
> > > Any advice?
> > >
> > > --
> > > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > > For additional commands, e-mail: <ma...@jakarta.apache.org>
> >
> >
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Dynamic tiles (attn: Cedric)

Posted by Jim Crossley <jc...@ifleet.com>.
I don't mean to be a bondhead, but all I did was copy the
tiles-doc.jar to Tomcat's webapps directory.  Wouldn't it be bundled
with the correct struts version?

The page, /test/testStrutsAction.jsp, *does* run correctly, but
/test/testAction.do does not.  It's the latter that seems to be what I
need to get working, right?

Also, the two tiles jar files seem to be the same size:

-rw-r--r--    1 jim    jim      80633 Jan 14 08:52 tiles.jar
-rw-r--r--    1 jim    jim      80633 Jan 14 08:52 tilesForStruts1-0.jar

Is that just a coincidence or might the current tiles distribution be
messed up?  In my app, either jar file seems to work fine.

-- Jim

Cedric Dumoulin <ce...@lifl.fr> writes:

>   First, check that you use tilesForStruts1.0.jar, as you are using Struts1.0.1.
>   Second, check if your tiles/struts1.0.1 installation works :
> 
>    * install tiles-doc.jar or struts-tiles.jar
>    * replace WEB-INF/lib/struts.jar with struts.jar from 1.0.1
>    * replace tiles.jar with tilesForStruts1.0.jar (remove the first and put the
>      second)
>    * start your web container
>    * try url ???/test/testStrutsAction.jsp
>         o If this run correctly, your installation is correct, if not, there is a
>           problem with install
> 
>     Cedric
> 
> Jim Crossley wrote:
> 
> > I've just started using Tiles, and I really like it.
> >
> > I want to be able to overload my attributes in my struts actions prior
> > to forwarding to the tiles definitions, but I'm having some trouble.
> > I found this message in the archives:
> >
> > http://www.mail-archive.com/struts-user%40jakarta.apache.org/msg16127.html
> >
> > But I can't seem to make it work.  When I attempt to run
> > tiles-doc/test/testAction, I get this:
> >
> > Error
> > Can't get component context.
> >
> > It seems ComponentContext.getContext(request) always returns null.
> >
> > I'm using Struts 1.0.1 with the current Tiles (2002 01 11, I think).
> >
> > Any advice?
> >
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Dynamic tiles (attn: Cedric)

Posted by Cedric Dumoulin <ce...@lifl.fr>.
  First, check that you use tilesForStruts1.0.jar, as you are using Struts1.0.1.
  Second, check if your tiles/struts1.0.1 installation works :

   * install tiles-doc.jar or struts-tiles.jar
   * replace WEB-INF/lib/struts.jar with struts.jar from 1.0.1
   * replace tiles.jar with tilesForStruts1.0.jar (remove the first and put the
     second)
   * start your web container
   * try url ???/test/testStrutsAction.jsp
        o If this run correctly, your installation is correct, if not, there is a
          problem with install

    Cedric

Jim Crossley wrote:

> I've just started using Tiles, and I really like it.
>
> I want to be able to overload my attributes in my struts actions prior
> to forwarding to the tiles definitions, but I'm having some trouble.
> I found this message in the archives:
>
> http://www.mail-archive.com/struts-user%40jakarta.apache.org/msg16127.html
>
> But I can't seem to make it work.  When I attempt to run
> tiles-doc/test/testAction, I get this:
>
> Error
> Can't get component context.
>
> It seems ComponentContext.getContext(request) always returns null.
>
> I'm using Struts 1.0.1 with the current Tiles (2002 01 11, I think).
>
> Any advice?
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>