You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Eldred Mullany <el...@easypay.co.za> on 2009/06/11 14:26:30 UTC

Two Menu Components

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  

 


RE: Two Menu Components

Posted by Eldred Mullany <el...@easypay.co.za>.
Thanks Donf and Otho, my two menu components work like a charm. I used
the MultiZoneUpdate method. I now have a very interactive menu system ! 

-----Original Message-----
From: donf yang [mailto:donf.yang@gmail.com] 
Sent: Thursday, June 11, 2009 3:31 PM
To: Tapestry users
Subject: Re: Two Menu Components

Oh, some mistakes:

<t:Block>  - >   <t:block>

-----------------------------------MyMenu.java
-----------------------------------
Object onShowSubMenu(String submenuId){
    this.submenuId = submenuId;
    //It's depends on which zone u linked
    //MultiZoneUpdate multiZoneUpdatenew = new
MultiZoneUpdate("majorMenuZone", this);
    MultiZoneUpdate multiZoneUpdatenew = new
MultiZoneUpdate("subMenuZone",
majorMenus.get(submenuId));
    return multiZoneUpdatenew;
}



On Thu, Jun 11, 2009 at 9:20 PM, donf yang <do...@gmail.com> wrote:

> codes fragements:
>
> Main.tml
> <div t:type="zone" id="majorMenuZone">
>   <t:MyMenu majorMenus="menuSource">
>    <div t:type="zone" id="subMenuZone"/>
> </t:MyMenu>
> </div>
>
> <t:Block t:id="subMenuBlock1" ><a href="">sub1-menu1</a>  <a
> href="">sub1-menu2</a></t:Block>
>   <t:Block t:id="subMenuBlock2" ><a href="">sub2-menu1</a>  <a
> href="">sub2-menu2</a></t:Block>
>
>
>
>
-----------------------------------Main.java----------------------------
-------
> //Provide menu source, key-title of sub menu | value - content block
of sub
> menu
>
> @Inject
> Block subMenuBlock1, subMenuBlock2;
>
> Map getMenuSource(){
>     Map<String, Block> menuSource = new HashMap<String, Block>();
>     menuSource.put("submenu1title",subMenuBlock1 );
>     menuSource.put("submenu2title",subMenuBlock2 );
> }
>
>
> -----------------------------------MyMenu.java
> -----------------------------------
> @Parameter
> private Map majorMenus;
> private String submenuId;
>
> //If u got a style on majormenu, return MyMenu
> Object onShowSubMenu(String submenuId){
>     this.submenuId = submenuId;
>     return majorMenus.get(submenuId);
>     //or return MainMenu
> }
> -----------------------------------MyMenu.tml
> -----------------------------------
> <t:Loop>
> //loop major menu titles here, and create component event
"showSubMenu" ,
> link one of zones.
> </t:Loop>
>
> There are 2 ways to refresh your menus:
> 1. return MyMenu to refresh the whole things of your menu component
> 2. return content block of your submenu, and you can return a
> MultiZoneUpdate anyway.
>   On Thu, Jun 11, 2009 at 8:26 PM, Eldred Mullany <
> eldred.mullany@easypay.co.za> wrote:
>
>> 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
>>
>>
>>
>>
>
>
> --
>
> Regards,
>
> Donf Yang
>
>
------------------------------------------------------------------------
------
> To be surprised,to wonder,is to begin to understand.
>



-- 

Regards,

Donf Yang
------------------------------------------------------------------------
------
To be surprised,to wonder,is to begin to understand.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Two Menu Components

Posted by donf yang <do...@gmail.com>.
Oh, some mistakes:

<t:Block>  - >   <t:block>

-----------------------------------MyMenu.java
-----------------------------------
Object onShowSubMenu(String submenuId){
    this.submenuId = submenuId;
    //It's depends on which zone u linked
    //MultiZoneUpdate multiZoneUpdatenew = new
MultiZoneUpdate("majorMenuZone", this);
    MultiZoneUpdate multiZoneUpdatenew = new MultiZoneUpdate("subMenuZone",
majorMenus.get(submenuId));
    return multiZoneUpdatenew;
}



On Thu, Jun 11, 2009 at 9:20 PM, donf yang <do...@gmail.com> wrote:

> codes fragements:
>
> Main.tml
> <div t:type="zone" id="majorMenuZone">
>   <t:MyMenu majorMenus="menuSource">
>    <div t:type="zone" id="subMenuZone"/>
> </t:MyMenu>
> </div>
>
> <t:Block t:id="subMenuBlock1" ><a href="">sub1-menu1</a>  <a
> href="">sub1-menu2</a></t:Block>
>   <t:Block t:id="subMenuBlock2" ><a href="">sub2-menu1</a>  <a
> href="">sub2-menu2</a></t:Block>
>
>
>
> -----------------------------------Main.java-----------------------------------
> //Provide menu source, key-title of sub menu | value - content block of sub
> menu
>
> @Inject
> Block subMenuBlock1, subMenuBlock2;
>
> Map getMenuSource(){
>     Map<String, Block> menuSource = new HashMap<String, Block>();
>     menuSource.put("submenu1title",subMenuBlock1 );
>     menuSource.put("submenu2title",subMenuBlock2 );
> }
>
>
> -----------------------------------MyMenu.java
> -----------------------------------
> @Parameter
> private Map majorMenus;
> private String submenuId;
>
> //If u got a style on majormenu, return MyMenu
> Object onShowSubMenu(String submenuId){
>     this.submenuId = submenuId;
>     return majorMenus.get(submenuId);
>     //or return MainMenu
> }
> -----------------------------------MyMenu.tml
> -----------------------------------
> <t:Loop>
> //loop major menu titles here, and create component event "showSubMenu" ,
> link one of zones.
> </t:Loop>
>
> There are 2 ways to refresh your menus:
> 1. return MyMenu to refresh the whole things of your menu component
> 2. return content block of your submenu, and you can return a
> MultiZoneUpdate anyway.
>   On Thu, Jun 11, 2009 at 8:26 PM, Eldred Mullany <
> eldred.mullany@easypay.co.za> wrote:
>
>> 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
>>
>>
>>
>>
>
>
> --
>
> Regards,
>
> Donf Yang
>
> ------------------------------------------------------------------------------
> To be surprised,to wonder,is to begin to understand.
>



-- 

Regards,

Donf Yang
------------------------------------------------------------------------------
To be surprised,to wonder,is to begin to understand.

Re: Two Menu Components

Posted by donf yang <do...@gmail.com>.
codes fragements:

Main.tml
<div t:type="zone" id="majorMenuZone">
  <t:MyMenu majorMenus="menuSource">
   <div t:type="zone" id="subMenuZone"/>
</t:MyMenu>
</div>

<t:Block t:id="subMenuBlock1" ><a href="">sub1-menu1</a>  <a
href="">sub1-menu2</a></t:Block>
  <t:Block t:id="subMenuBlock2" ><a href="">sub2-menu1</a>  <a
href="">sub2-menu2</a></t:Block>



-----------------------------------Main.java-----------------------------------
//Provide menu source, key-title of sub menu | value - content block of sub
menu

@Inject
Block subMenuBlock1, subMenuBlock2;

Map getMenuSource(){
    Map<String, Block> menuSource = new HashMap<String, Block>();
    menuSource.put("submenu1title",subMenuBlock1 );
    menuSource.put("submenu2title",subMenuBlock2 );
}


-----------------------------------MyMenu.java
-----------------------------------
@Parameter
private Map majorMenus;
private String submenuId;

//If u got a style on majormenu, return MyMenu
Object onShowSubMenu(String submenuId){
    this.submenuId = submenuId;
    return majorMenus.get(submenuId);
    //or return MainMenu
}
-----------------------------------MyMenu.tml
-----------------------------------
<t:Loop>
//loop major menu titles here, and create component event "showSubMenu" ,
link one of zones.
</t:Loop>

There are 2 ways to refresh your menus:
1. return MyMenu to refresh the whole things of your menu component
2. return content block of your submenu, and you can return a
MultiZoneUpdate anyway.
On Thu, Jun 11, 2009 at 8:26 PM, Eldred Mullany <
eldred.mullany@easypay.co.za> wrote:

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


-- 

Regards,

Donf Yang
------------------------------------------------------------------------------
To be surprised,to wonder,is to begin to understand.

RE: Two Menu Components

Posted by Ville Virtanen <vi...@cerion.fi>.
Hi, 

this is wild guess, but take a look at the environment? You can push, pop
and peek objects that are in the environment, shared by all enclosed
components.

http://tapestry.apache.org/tapestry5/guide/env.html

http://tapestry.apache.org/tapestry5/apidocs/org/apache/tapestry5/services/Environment.html

 - Ville 


eldred wrote:
> 
> Hi Guys
> 
> No problem, thanks Otho and donf yang for helping a newbie at Tapestry.
> Am still trying get my head around how to pass data between components
> (not same as pages) ie how to pass data from one component to another.
> Let me be more precise: 
> 
> If I use the @Component annotation then my second menu component it has
> be nested inside first <t:mainMenu><div class="sidemenu"/></t:mainMenu>
> there you can pass a string to submenu provided that its enclosed inside
> MainMenu component, however would not work if my two menu components sit
> independently from each other inside my Layout component. Apologies is I
> did not explain myself clearly enough. Here is my Layout.tml code
> fragment: 
> 
> 
> ... 
> 
> <!--Main menu top-->
> <!--header-->					
> <t:mainmenu myStringParameter="Link1,Link2 Link3..."/> 
> 	<div style="clear:both;"/>
> 	<!-- Body -->
> 	<div id="bd">
> 		<div id="yui-main">
> 			<div class="yui-b">
> 				<div id="bd">
> 			           <t:body />
> 			      </div>
> 			</div>
> 		</div>
> 		<div class="yui-b">
> 			<t:sideMenu/>
> 		</div>
> 	</div>		  
> 	 <!-- end body -->
> 	<div style="clear:both;"></div>
> 
> ...
> 
> When the event hander is called ie onAction(String context) from
> MainMenu.java I want to be able to pass that string from the onAction
> method (MainMenu.java) to another method called
> setSelectedMenuItem(String context) inside SideMenu.java without getting
> a NullPointerException. If I use @Component annotation then I need to
> nest <t:mainMenu><div class="sidemenu"/></t:mainmenu> then it will work.
> But because my sidemenu component sits further down in my Layout.tml
> page, how can I do this ?
> 
> Thanks again for the assistance. 
> 
> 
> 
> -----Original Message-----
> From: Otho [mailto:taar93@googlemail.com] 
> Sent: Friday, June 12, 2009 2:55 PM
> To: Tapestry users
> Subject: Re: Two Menu Components
> 
> 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> ${message:${currentMenuItem}-label} 
> </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 <el...@easypay.co.za>
> 
>> 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:taar93@googlemail.com]
>> 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 <el...@easypay.co.za>
>>
>> > 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: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Two-Menu-Components-tp23980338p24067890.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Two Menu Components

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, Jun 17, 2009 at 3:35 AM, Eldred Mullany
<el...@easypay.co.za> wrote:

> Hi Guys

Hi!

> No problem, thanks Otho and donf yang for helping a newbie at Tapestry.
> Am still trying get my head around how to pass data between components
> (not same as pages) ie how to pass data from one component to another.

Take a look at the @Environmental annotation. It is used, for example,
by fields to check if it has a validation error. They do that by
getting a ValidationTracker instance from the environment, which is
pushed by the Form component while starting its rendering.

--
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


RE: Two Menu Components

Posted by Eldred Mullany <el...@easypay.co.za>.
Hi Guys

No problem, thanks Otho and donf yang for helping a newbie at Tapestry.
Am still trying get my head around how to pass data between components
(not same as pages) ie how to pass data from one component to another.
Let me be more precise: 

If I use the @Component annotation then my second menu component it has
be nested inside first <t:mainMenu><div class="sidemenu"/></t:mainMenu>
there you can pass a string to submenu provided that its enclosed inside
MainMenu component, however would not work if my two menu components sit
independently from each other inside my Layout component. Apologies is I
did not explain myself clearly enough. Here is my Layout.tml code
fragment: 


... 

<!--Main menu top-->
<!--header-->					
<t:mainmenu myStringParameter="Link1,Link2 Link3..."/> 
	<div style="clear:both;"/>
	<!-- Body -->
	<div id="bd">
		<div id="yui-main">
			<div class="yui-b">
				<div id="bd">
			           <t:body />
			      </div>
			</div>
		</div>
		<div class="yui-b">
			<t:sideMenu/>
		</div>
	</div>		  
	 <!-- end body -->
	<div style="clear:both;"></div>

...

When the event hander is called ie onAction(String context) from
MainMenu.java I want to be able to pass that string from the onAction
method (MainMenu.java) to another method called
setSelectedMenuItem(String context) inside SideMenu.java without getting
a NullPointerException. If I use @Component annotation then I need to
nest <t:mainMenu><div class="sidemenu"/></t:mainmenu> then it will work.
But because my sidemenu component sits further down in my Layout.tml
page, how can I do this ?

Thanks again for the assistance. 



-----Original Message-----
From: Otho [mailto:taar93@googlemail.com] 
Sent: Friday, June 12, 2009 2:55 PM
To: Tapestry users
Subject: Re: Two Menu Components

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 <el...@easypay.co.za>

> 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:taar93@googlemail.com]
> 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 <el...@easypay.co.za>
>
> > 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: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Two Menu Components

Posted by Otho <ta...@googlemail.com>.
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 <el...@easypay.co.za>

> 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:taar93@googlemail.com]
> 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 <el...@easypay.co.za>
>
> > 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: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

RE: Two Menu Components

Posted by Eldred Mullany <el...@easypay.co.za>.
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:taar93@googlemail.com] 
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 <el...@easypay.co.za>

> 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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Two Menu Components

Posted by Otho <ta...@googlemail.com>.
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 <el...@easypay.co.za>

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