You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Cedric Dumoulin <ce...@lifl.fr> on 2002/03/26 15:26:38 UTC

Re: Tiles question: Is it possible to insert a ComponentDefinition into a Tile context dynamically?

  Yes and no ;-)
  No, this is not a feature directly supported by Tiles
  Yes, as you have sources, and you know which definition factory you use, you
can add directly a definition to the factory.
   How : create definition, retrieve the factory from context, cast it to its
real implementation, use available methods to add definition.
  This added definition will be available from all your application. Be care to
not overwrite an existing definition !

    Cedric

Chris Cool wrote:

> Hello, Cedric:
>
> Thank you for responding to my question.
>
> As you stated, I can add/overload an attribute in the current context.
> Specifically, I am adding a new item to an existing list. However, each item
> in the list is the key to a Tile definition. Most of the definitions are in
> the XML file, but I want to add a new Tile definition dynamically so that
> the new item in the list is a reference to the new Tile definition. Is this
> possible?
>
> Thanks again,
>
> Chris
>
> -----Original Message-----
> From: Cedric Dumoulin [mailto:cedric.dumoulin@lifl.fr]
> Sent: Monday, March 25, 2002 10:29 AM
> To: Struts Users Mailing List
> Subject: Re: Tiles question: Is it possible to insert a
> ComponentDefinition into a Tile context dynamically?
>
>   Hello,
>
>   If you are in a tile controller, you don't have to create a new
> ComponentDefinition, you can set the attributes of the current tiles
> (because you
> are in the controller).
>   To add / overload an attribute in the context, do something like :
>   String attribute = (String)context.getAttribute("attributeName");
>   attribute = "new value";
>   context.setAttribute("attributeName", attribute);
>
>   To add a list, create the list, add elements, and add the list to context.
>   You can overload a previously defined list. Do not modify content of an
> existing list, because it is shared between inherited instances. :
>
>    List list = new java.util.ArrayList();
>   list.add( "a value" );
>   list.add( "another value");
>   context.setAttribute("listAttributeName", list);
>
>   Hope this help,
>
>     Cedric
>
> P.S. :
> The DefinitionsUtil.setActionDefinition( aDefinition ); is to be used when
> you
> are inside a Struts action called by Struts mechanism.
>   It has not effect when used inside a tile controller
> Chris Cool wrote:
>
> > Hi,
> >
> > I have a tile that reads items from a PutList list and then inserts each
> > item into the current page.
> >
> >    <struts_logic:iterate id="item" name="itemList" scope="page"
> > type="String">
> >        <tiles:insert name='<%=item%>' flush="true"/>
> >    </struts_logic:iterate>
> >
> > When the items in the list are tiles defined in my tileDefinitions.xml
> file,
> > the tiles are inserted into my JSP correctly. However, I want to
> dynamically
> > create a tile definition and insert it into the page context.
> >
> > I am generating the ComponentDefinition in my tile controller and
> accessing
> > the "itemList" where I add the name of the dynamically generated
> definition:
> >
> >       /* get the item list and insert new tile def into it */
> >       ArrayList itemList = (ArrayList)context.getAttribute("itemList");
> >       if (itemList != null) {
> >
> >         HashMap map = new HashMap();
> >         map.put("name", "newtarget");
> >         map.put("link", "newtarget.do");
> >
> >         ComponentDefinition newItem =
> >                         new ComponentDefinition("new.item",
> >                                           "/mytiles/simpleItem.jsp",
> >                                                         map);
> >
> >         DefinitionsUtil.setActionDefinition( request, breadCrumbItem );
> >         itemList.add("new.item");
> >       }
> >
> > In my tile, the "itemList" contains the "new.item" entry, but it does not
> > appear to find the ComponentDefinition I created.
> >
> > Thanks for you help.
> >
> > Chris
> >
> > --
> > 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>