Oops, sorry. My bad.
This doesn't work with components in this way.
If you want to update with Ajax I suggest you try donf jangs solution. The
following works on full page refresh.
You need to have MainMenu and SideMenu as components in your Layout.java
Layout.java
@Component
private MainMenu mainMenu;
@Component
private SideMenu sideMenu;
Object setupRender()
{
sideMenu.setSelectedMainMenuItem(mainMenu.getSelectedMenuItem());
....
return null;
}
MainMenu.java
@Persist
private String selectedItem;
@Property
private List<String> menuItems = Arrays.asList("home", "about", "help");
@Property
private String currentMenuItem;
public String getSelectedMenuItem()
{
return selectedItem;
}
Object onActionFromMyMenu(String context)
{
selectedItem = context;
return null;
}
MainMenu.tml
...
<ul>
<t:loop source="menuitems" value="currentMenuItem">
<li><a t:type="actionLink" t:id="myMenu"
context="currentMenuItem">${message:${currentMenuItem}-label}</a>
</t:loop>
</ul>
MainMenu.properties
home-label=Start
about-label=About
help-label=Help
SideMenu.java
@Persist
private String selectedMainMenuItem;
public getSelectedMainMenuItem()
{
return selectedMainMenuItem;
}
public setSelectedMainMenuItem(String value)
{
selectedMainMenuItem=value;
}
The rest with the blocks can stay as it is in the first post.
If you don't write explicit getters and setters like I did in this second
example, it won't compile, since the getters and setters are only created at
runtime by Tapestry when using the @Property annotation. Sorry for being so
rash. I hope this helps, and as I said if you want Ajax, look at donf yangs
code.
2009/6/12 Eldred Mullany <[email protected]>
> Hi Otho
>
> Thank you for the feedback, I am trying this example, but notice that I
> get a transformation exception if I inject my component as per your
> example. Complaining about it not having a serviceID ?
>
> Using T5 5.1.0.5
>
> How do I provide a serviceID to ComponentResourcesInjectionProvider ?
>
> Thank you
>
> -----Original Message-----
> From: Otho [mailto:[email protected]]
> Sent: Thursday, June 11, 2009 3:33 PM
> To: Tapestry users
> Subject: Re: Two Menu Components
>
> Create an eventhandler in your MainMenu component which fires on select
> and
> gives the selected menuitem as context.
>
> For example
>
> class MainMenu
> @Inject
> private SideMenu sideMenu;
>
> Object onActionFromYourMenu(String context)
> {
> sideMenu.setSelectedMainMenuItem(context);
>
> return null;
> }
>
> class SideMenu
>
> @Property
> @Persist
> private String selectedMainMenuItem;
>
> @Inject
> private Block whateverBlock;
>
> @Property
> @Persist
> private Block displayBlock;
>
> Object setupRender()
> {
> if(selectedMainMenuItem.equals("whatever")
> displayBlock = whateverBlock;
>
> ...
>
> return null;
> }
>
> SideMenu.tml
>
> <div class="sidemenu">
> <t:delegate to="displayBlock"/>
> </div>
>
> <t:block t:id = "whateverBlock">
> <ul>
> <li>Whatver has to be done</li>
> <ul>
> </t:block>
>
>
> 2009/6/11 Eldred Mullany <[email protected]>
>
> > Hi All
> >
> >
> >
> > I need some advice on how to get two menu components to talk to each
> > other. The fist component is a top menu with a whole lot of links,
> when
> > an action link is fired(from the first menu component) I want to pass
> a
> > parameter string to the second component (sub-menu) which will render
> > based on the parameter it's been passed to it.
> >
> >
> >
> > So in other words second menu component is dependent on the first.
> >
> >
> >
> > Its pretty much high level but some advice would be useful. Perhaps a
> > component listener of some sort?
> >
> >
> >
> > Any ideas ?
> >
> >
> >
> > Thanks
> >
> > Eldred
> >
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>