Re: [T5] way to check if the application is entering or exiting from a page
Hi Jonathan, thank you for your suggestion. Yes, @Persist(flash) works fine for one object of for a set of objects that are always readed and showed into the page during the page rendering. And it's fine for a CRUD page that shows only the entity to manage. To learn T5, I was sperimenting a CRUD page composed by: 1) the list of objects to view / edit / delete rendered by the grid component. This list is alwasy visible. 2) over the grid, a zone that shows the data of selected entity using BeanDisplay or BeanEditor, depending if the user clicks the view or the edit link of the selected grid row. The entity data at #2 is displayed only if the user selects an entity from the above grid. When the user navigates the grid the application doesn't show any entity data. My goal was to provide the user an unique page to show all the entities, to view an existant entity or to create a new one from the same page, without leaving it. I was using the flash persistence mechanism to store both the entity list managed by the grid and the single entity selected by the user. This to avoid to make other queries to the database to retrieve that data when the user executes an action on that page (on the rewind phase, as I call it - but it's not the correct term). I noticed that when the application was not going to show a selected entity (#2), and the user selected another entity from the grid list, the application started to loose the synchronization between the grid's selected entity and the entity data showed below... it started to show the data of the old entity instead of the data of the new one. From my understanding, the value of a page property that uses @Persist(flash) is discarded from the session only after the application reads it to restore that property. So I think the old entity value was not discarded from the session because the application didn't show its data into the page. Obviously, this was my code fault ;^) I fixed the problem removing the @Persist(flash) annotation on the selected entity property and refactoring a bit the db initialization code. Luca Jonathan Barker wrote: Luca, Check the Form documentation for prepareForRender() and prepareForSubmit(). They can be better places to do heavy initialization than onActivate(). Also, take a look at @Persist(flash) which is meant to retain information for only one additional cycle (like the render after a form submit). You may find this is satisfactory for your cache. Jonathan -Original Message- From: Luca Fossato [mailto:[EMAIL PROTECTED] Sent: Friday, April 18, 2008 10:24 AM To: Tapestry users Subject: Re: [T5] way to check if the application is entering or exiting from a page Hi Chris, thank you. Sorry, I didn't explain well. I intended from an html page point of view. Example: I have a page with a form. I'd like to track its lifecycle both for the rewind and render phase (I use T4 rewind term to indicate that the application is exiting from a page, and render to indicate the application is entering into the page) Here's an example log of the page lifecycle when I press the submit button of its form: --- cut here --- page is rendered; click the submit button of the form: [TRANSACTION] transaction begin... myPage : pageAttached myPage : onActivate ** db initialization... myPage : onSuccessFromForm myPage: onPassivate (1 time) [TRANSACTION] closed the entity manager... myPage : pageDetached form submit was successfull; T5 redirects to the same page; [TRANSACTION] transaction begin... myPage : pageAttached myPage : onActivate ** db initialization... myPage: onPassivate (x times) [TRANSACTION] closed the entity manager... myPage : pageDetached --- cut here --- It seems to me that pageDetached is executed for both rewind and render phases. I'd like to know if there is an API or a strategy that I can use in onActivate method (or another initialization method) to know if I am exiting or entering the page. For example, I'd like to enter into a page and use onActivate() to initialize business data from the db and store it into a cache (session). Then, when I press the submit button of the form contained into the page, T5 will re-execute onActivate() again. At that moment, I'd like to know if I am in the rewind phase. If so, I could get the data from the cache (and then remove it from the cache, too) When T5 re-enters into the page and re-executes onActivate() (3rd time), I will check if the page is in render phase. If so I will query the db again to get fresh data. Regards, Luca - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [T5] way to check if the application is entering or exiting from a page
Hi Geoff, yes, I read those threads and I modeled my CRUD page using the suggestions listed on your Mk VI page. Thank you. As I was trying to explain to Jonathan Barker in my previous mail (ah, my poor english ;^) , my CRUD page already used @Persist(flash) to store the entity to modify. The problem was I was trying to do too much things in a single page thinking that the flash persistence could do the job (well, it works fine, but I had some conditions that were not compatible with that kind of persistence strategy). Anyway, I'm going to study Tapestry JumpStart to better understand T5 behaviour and page lifecycle. Regards, Luca Geoff Callender wrote: Hi Luka, It's probably best to ditch the mental model of rewind and render in T5. I think what you're after is covered in this thread on Edit page best practice: http://thread.gmane.org/gmane.comp.java.tapestry.user/56176/focus=57580 It's discussed and demonstrated in Tapestry JumpStart: http://files.doublenegative.com.au/jumpstart/ Don't forget that action links throw a curved ball at your page: they cause a sequence of Action-Redirect-Render, so your onActivate() will probably get called twice before the page is displayed - once by the previous page's action handler method and then by the T5 framework after the redirect. The best practice above takes this into account. There's a JIRA issue that flowed from it too: https://issues.apache.org/jira/browse/TAPESTRY-2138 Cheers, Geoff - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: T5 actionlink, ajax zone and user onclick handler
Hi Chris, thank you ! I will read your article and I will try to use the mixin to implement the confirmation dialog for my delete actionLink. Give me some days to digest all this stuff and to implement it into my test application ;^) Regards, Luca Chris Lewis wrote: Hi Lucca, I'd been looking for a good example to use to write a wiki explaining the integration javascript by Tapestry, and your request gave me what I was looking for. Check out the article here: http://wiki.apache.org/tapestry/Tapestry5AndJavaScriptExplained (project source: http://thegodcode.net/tapestry5/jsclarity-project.zip). Apart from discussing in detail how T5 integrates JS, it shows how to create a mixin that can be added to link components. The mixin attaches js code to the component, so that when the link is clicked the user is presented with a confirmation box. Canceling the box cancels the click, while OK allows it to proceed as normal. This should be useful for those looking to add click confirmation functionality, but in your case I'm not sure if it will help. I ask you to try and see, but the problem will be how T5 attaches the js handlers for the ajax code (that is, they may fire before the confirmation code). Anyway, I think it will be helpful to those looking for such an explanation, and I hope it helps you. chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
[T5] way to check if the application is entering or exiting from a page
Hi, in Tapestry 5 is there a way to determine if the application is entering or exiting from a page (like the T4 api : event.getRequestCycle().isRewinding() ) ? Thank you, Luca - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [T5] way to check if the application is entering or exiting from a page
Hi Chris, thank you. Sorry, I didn't explain well. I intended from an html page point of view. Example: I have a page with a form. I'd like to track its lifecycle both for the rewind and render phase (I use T4 rewind term to indicate that the application is exiting from a page, and render to indicate the application is entering into the page) Here's an example log of the page lifecycle when I press the submit button of its form: --- cut here --- page is rendered; click the submit button of the form: [TRANSACTION] transaction begin... myPage : pageAttached myPage : onActivate ** db initialization... myPage : onSuccessFromForm myPage: onPassivate (1 time) [TRANSACTION] closed the entity manager... myPage : pageDetached form submit was successfull; T5 redirects to the same page; [TRANSACTION] transaction begin... myPage : pageAttached myPage : onActivate ** db initialization... myPage: onPassivate (x times) [TRANSACTION] closed the entity manager... myPage : pageDetached --- cut here --- It seems to me that pageDetached is executed for both rewind and render phases. I'd like to know if there is an API or a strategy that I can use in onActivate method (or another initialization method) to know if I am exiting or entering the page. For example, I'd like to enter into a page and use onActivate() to initialize business data from the db and store it into a cache (session). Then, when I press the submit button of the form contained into the page, T5 will re-execute onActivate() again. At that moment, I'd like to know if I am in the rewind phase. If so, I could get the data from the cache (and then remove it from the cache, too) When T5 re-enters into the page and re-executes onActivate() (3rd time), I will check if the page is in render phase. If so I will query the db again to get fresh data. Regards, Luca On Fri, Apr 18, 2008 at 2:46 PM, Chris Lewis [EMAIL PROTECTED] wrote: Luca, I think what you want is the page life cyle method PageDetached. See: http://tapestry.apache.org/tapestry5/tapestry-core/guide/lifecycle.html sincerely, chris Luca Fossato wrote: Hi, in Tapestry 5 is there a way to determine if the application is entering or exiting from a page (like the T4 api : event.getRequestCycle().isRewinding() ) ? Thank you, Luca - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- http://thegodcode.net - 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]
T5 actionlink, ajax zone and user onclick handler
Hi all, I'm playing with actionlink and zones to understand T5 ajax functions (Tapestry 5.0.11). I'd like to define an actionlink like this one: t:actionlink t:id=deleteLink context=myContext t:zone=zoneToUpdate onclick=confirm('are you sure to delete this record ?');delete/t:actionlink where the onclick handler uses a javascript confirmation dialog to ask to the user if he/she wants to delete the selected record. It seems to me the Tapestry.linkZone js function eats the user onclick handler and set its own - so it is not possible to execute any js code prior to invoke the ajax call. Is it correct or am I missing something ? I tried to fix this behaviour, modifying a bit the Tapestry.linkZone function (just an experiment): --- cut here --- /** Convert a form or link into a trigger of an Ajax update that * updates the indicated Zone. */ linkZone : function(element, zoneDiv) { // ... original code until Otherwise, assume it's just an ordinary link. comment... // Otherwise, assume it's just an ordinary link. var onClickValue = element.getAttribute(onclick); if (onClickValue != null) { element.setAttribute(tapestry5_onbeforeajax, onClickValue); } var handler = function(event) { var onBeforeAjaxRes = true; var onBeforeAjaxValue = element.getAttribute(tapestry5_onbeforeajax); if (onBeforeAjaxValue != null) { onBeforeAjaxRes = eval(onBeforeAjaxValue); } // execute the Ajax request only if the original onclick attribute was not set or if the evaluation // of the related function returned true; if (onBeforeAjaxRes === undefined || onBeforeAjaxRes) new Ajax.Request(element.href, { onSuccess : successHandler }); return false; }; element.onclick = handler; }, // end of linkZone function --- cut here --- that is a 10 minutes fix, so probably it's not the best solution. Anyway it seems to work fine for my experiment ;^) To block the execution of the ajax call, do NOT use a return statement inside the onclick handler. Example: t:actionlink t:id=deleteLink t:zone=zoneToUpdate onclick=return myFunction(myParam);delete/t:actionlink use this instead: t:actionlink t:id=deleteLink t:zone=zoneToUpdate onclick=myFunction(myParam);delete/t:actionlink because eval() returns the value of the last expression evaluated. http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Functions:eval Does this stuff make sense for you ?? ;^) Thank you, Luca Fossato - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]