Thanks for all your support. I managed to figure out what I was doing wronge and got it working. A fix to the way I was using ComponentResources.createEventLink() as well as updating my @OnEvent to use "value" parameter instead of "component" did the trick.
Cheers, Marcel Howard Lewis Ship wrote: > > It is subtle and powerful, and you missed one minor detail. > > On Mon, Nov 3, 2008 at 1:57 PM, Robert Zeigler <[EMAIL PROTECTED]> wrote: > >> As a follow-up: >> >> Tutorials show this binding done >>>> through the @OnEvent annotation and specifying the event name via the >>>> "component" attribute in the annotation or the "id" attribute of the >>>> element. >>>> >>> >> This is not quite correct. >> The component attribute of the @OnEvent annotation identifies which >> /component/ generates the event, but not which event is generated. >> It's the "value" attribute that specifies which event to listen to: >> >> .tml: >> <t:eventlink t:id="mycomp" event="myevent">Click Me</t:eventlink> >> >> .java: >> @OnEvent(value="myevent",component="mycomp") >> void someHandler() { >> } > > > This will not be called because EventLink triggers the provided event not > on > itself, but on its container. Omit the component attribute for this to > work > as written. > > >> >> >> Or, if you prefer convention-over-configuration: >> .java: >> void onMyeventFromMycomp() { >> ... >> } >> >> Or even: >> void onMyevent() { >> ... >> } >> > > This will work because it intercepts the event notification fired on the > page (the container of the EventLink instance). > > I've been asked which to use: EventLink or ActionLink. I think, possibly, > if I had created EventLink first, I would not have created ActionLink. > > That being said, ActionLink is useful when you have many one-off > components > with individual logic on each ... it's easier since you specify (in the > template) a unique component id, which you would do anyway. You just have > to match that id against an event handler method name. > > EventLink is when you have multiple components in the template that should > trigger the same behavior. You can usually omit the component id, but you > have to carefully coordinate the event name in the template and in the > Java > class (either inside the @OnEvent annotation, or > as part of the event handler method name). > > > > >> >> HTH, >> >> Robert >> >> >> On Nov 3, 2008, at 11/31:07 PM , Robert Zeigler wrote: >> >> Hi Marcel, >>> >>> The binding of the listener to the event is done automatically by >>> tapestry >>> based either on the @OnEvent annotation or by naming convention. >>> >>> The context argument is simply used to allow for additional information >>> to >>> be encoded into the url which will be provided to the handler in the >>> form of >>> method parameters. >>> For example: >>> >>> .html: >>> ${myLink} My Link >>> >>> .java: >>> @Inject >>> private ComponentResources resources; >>> public Link getMyLink() { >>> return resources.createEventLink("myevent","value1"); >>> } >>> >>> @Inject >>> private ComponentSource componentSource; >>> >>> Object onMyevent(String name) { >>> //do something interesting. Here, we look up a page based on the page >>> name provided in name. >>> return componentSource.getPage(name); >>> } >>> >>> >>> And that's it. Now when you click "MyLink", the "onMyevent" method will >>> be called, passing in "value1" as the value of the "name" parameter. >>> >>> * The values in context will be converted to and from strings via the >>> ValueEncoder service & contributions. >>> * Events always bubble in T5, so your handler has to be either at the >>> level of the component which has the link, or in a class that wraps that >>> component. That is, suppose the following page structure: >>> >>> page x >>> - component a >>> - event link, event is "foo". >>> - event link, event is "bar". >>> >>> The handler for the "foo" event must be in either component a or in page >>> x. The handler for "bar" must be in page x. A handler for the "bar" >>> event >>> in component a won't be called by clicking the event link of page x. >>> >>> HTH, >>> >>> Robert >>> >>> >>> On Nov 3, 2008, at 11/312:05 PM , Marcel Sammut wrote: >>> >>> >>>> I'm aware of the large gap between 3 and 5 and may require some >>>> redesign >>>> on >>>> my part. That is why I'm using native tapestry links. In 5.0.15, the >>>> ComponentResources class has the createActionLink deprecated in favor >>>> of >>>> createEventLink. There are only 2 difference between ActionLink and >>>> EventLink according to the API, the way it is controlled and the way it >>>> is >>>> triggered. >>>> >>>> I do want to use an EventLink in my situation, and do this through >>>> ComponentResources.createEventLink(). The tutorials show you how to >>>> use >>>> the >>>> ActionLink in a template, whereas in my case, the component is created >>>> via >>>> Java code. Perhaps I do not understand what the "context" argument in >>>> the >>>> createEventLink() method is used for. I believe that the first >>>> argument >>>> would be the name of the method to invoke? How do you identify the >>>> handler >>>> of the event when creating the EventLink? Tutorials show this binding >>>> done >>>> through the @OnEvent annotation and specifying the event name via the >>>> "component" attribute in the annotation or the "id" attribute of the >>>> element. >>>> >>>> How would I bind these properties using a pure Java implementation? My >>>> previous T3 components never had a template file, and rendered purly in >>>> Java. >>>> >>>> Thanks >>>> - Marcel >>>> >>>> >>>> >>>> Peter Stavrinides wrote: >>>> >>>>> >>>>> Hi Marcel >>>>> >>>>> Tapestry 5 is not like 3, most of the boilerplate code is gone, it >>>>> appears >>>>> to me that you are trying to do too much... have you gone through the >>>>> tutorials yet? I think you will be pleasantly surprised how simple yet >>>>> powerful T5 is. You also haven't quite grasped the difference between >>>>> ActionLink and EventLink and PageLink (it sounds like you want an >>>>> EventLink) >>>>> >>>>> cheers >>>>> Peter >>>>> >>>>> Thanks! >>>>> I seem to be able to render the anchor component based on the Link >>>>> being >>>>> created from the ComponentResources.createActionLink(). However, the >>>>> action >>>>> does not seem to be fired when I hook up the event using the @OnEvent >>>>> annotation. The anchor is rendered using the MarkupWriter.element() >>>>> method >>>>> using the Link object to define the href attribute. >>>>> >>>>> Note, that the creating and rendering of the action anchor is done >>>>> purely >>>>> in >>>>> Java...no template. >>>>> >>>>> My anchor renders the following url: >>>>> mypage.pagelayout/activate Activate >>>>> >>>>> There is a page called Home/MyPage and on this page is a component >>>>> called >>>>> PageLayout which is an extension of my Layout component. In the >>>>> PageLayout >>>>> component, I have my "activate" event handler as follows: >>>>> @OnEvent(component="activate") >>>>> public Object activate() { >>>>> ... >>>>> } >>>>> >>>>> Any idea why the activate event is not being called and how I can hook >>>>> the >>>>> event to the action? >>>>> >>>>> Thanks Once Again. >>>>> Marcel >>>>> >>>>> >>>>> Howard Lewis Ship wrote: >>>>> >>>>>> >>>>>> ${createURL} click me >>>>>> >>>>>> You just have to provide getCreateURL() as a wrapper around >>>>>> ComponentResources.createActionLink(). >>>>>> >>>>>> You don't instantiate a component, just @Inject the >>>>>> ComponentResources. >>>>>> >>>>>> On Fri, Oct 31, 2008 at 5:24 PM, Marcel Sammut <[EMAIL PROTECTED]> >>>>>> wrote: >>>>>> >>>>>>> >>>>>>> Thanks for the quick response. My delima is that I need to have a >>>>>>> reference >>>>>>> to the link in the .tml template. I was hoping to just use a pure >>>>>>> Java >>>>>>> implementation to let the developer configure the menu via code. >>>>>>> In order to do this, I believe I have to inject the >>>>>>> ComponentResources >>>>>>> object of my container when instantiating the AbstractLink >>>>>>> component. >>>>>>> Any >>>>>>> idea to do that? >>>>>>> >>>>>>> Thanks, >>>>>>> Marcel >>>>>>> >>>>>>> >>>>>>> Robert Zeigler wrote: >>>>>>> >>>>>>>> >>>>>>>> Why not just use ComponentResources.createActionLink and >>>>>>>> ComponentResources.createPageLink? >>>>>>>> >>>>>>>> .tml: >>>>>>>> $somelink Link Text >>>>>>>> .java: >>>>>>>> >>>>>>>> @Inject >>>>>>>> private ComponentResources resources; >>>>>>>> >>>>>>>> public String getSomeLink() { >>>>>>>> return >>>>>>>> >>>>>>>> resources.createPageLink("mypage",true,contextValue1,contextValue2,...); >>>>>>>> } >>>>>>>> >>>>>>>> >>>>>>>> Robert >>>>>>>> >>>>>>>> On Oct 31, 2008, at 10/315:04 PM , Marcel Sammut wrote: >>>>>>>> >>>>>>>> >>>>>>>>> Greetings, >>>>>>>>> I'm looking at porting my 3.0 tapestry web application to v5 and >>>>>>>>> I'm >>>>>>>>> trying >>>>>>>>> to build a menu component which accepts a parameter of type >>>>>>>>> ArrayList that >>>>>>>>> contains a list of AbstractLink objects. These items get rendered >>>>>>>>> in a menu >>>>>>>>> layout etc. The page that this menu component exists on will >>>>>>>>> create, at >>>>>>>>> runtime, the set of desired menu item and pass them to the menu >>>>>>>>> component. >>>>>>>>> >>>>>>>>> This sounds straight forward, however, I am unable to determin how >>>>>>>>> to >>>>>>>>> instantiate, for example, a new instance of a ActionLink. In the >>>>>>>>> previous >>>>>>>>> version (3.0), I simply rendered the anchor myself and generated >>>>>>>>> the >>>>>>>>> URi in >>>>>>>>> a custom implementation. I was hoping that in T5, I would be able >>>>>>>>> to use >>>>>>>>> the internal Link components since they do pretty much what I was >>>>>>>>> doing in >>>>>>>>> 3.0. >>>>>>>>> >>>>>>>>> Is there a way, in code, to create a new ActionLink component and >>>>>>>>> have it >>>>>>>>> act as the model for another component to be rendered? >>>>>>>>> >>>>>>>>> Your thoughts are much appreciated. >>>>>>>>> - Marcel >>>>>>>>> -- >>>>>>>>> View this message in context: >>>>>>>>> >>>>>>>>> http://www.nabble.com/-T5--Creating-Links-At-Runtime-tp20274715p20274715.html >>>>>>>>> Sent from the Tapestry - User mailing list archive at Nabble.com. >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> --------------------------------------------------------------------- >>>>>>>>> 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] >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>> -- >>>>>>> View this message in context: >>>>>>> >>>>>>> http://www.nabble.com/-T5--Creating-Links-At-Runtime-tp20274715p20275943.html >>>>>>> Sent from the Tapestry - User mailing list archive at Nabble.com. >>>>>>> >>>>>>> >>>>>>> --------------------------------------------------------------------- >>>>>>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>>>>>> For additional commands, e-mail: [EMAIL PROTECTED] >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Howard M. Lewis Ship >>>>>> >>>>>> Creator Apache Tapestry and Apache HiveMind >>>>>> >>>>>> --------------------------------------------------------------------- >>>>>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>>>>> For additional commands, e-mail: [EMAIL PROTECTED] >>>>>> >>>>>> >>>>>> >>>>>> >>>>> -- >>>>> View this message in context: >>>>> >>>>> http://www.nabble.com/-T5--Creating-Links-At-Runtime-tp20274715p20286038.html >>>>> Sent from the Tapestry - User mailing list archive at Nabble.com. >>>>> >>>>> >>>>> --------------------------------------------------------------------- >>>>> 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] >>>>> >>>>> >>>>> >>>>> >>>> -- >>>> View this message in context: >>>> http://www.nabble.com/-T5--Creating-Links-At-Runtime-tp20274715p20307367.html >>>> Sent from the Tapestry - User mailing list archive at Nabble.com. >>>> >>>> >>>> --------------------------------------------------------------------- >>>> 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] >>> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> > > > -- > Howard M. Lewis Ship > > Creator Apache Tapestry and Apache HiveMind > > -- View this message in context: http://www.nabble.com/-T5--Creating-Links-At-Runtime-tp20274715p20314854.html Sent from the Tapestry - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]