Saving using form zone
Hello, I'm using a form zone to handle saves to the user session, SSO. I have a Create and Update page that both share a single component containing the form data. Prior to converting my form to use a zone update, I use to save the form to the session then reload the update page with previous session data, however when using the zone update, it no longer redirects to the update page. Issues, when saving form with zone update First I found it reruns all methods and creates a new object which causes a loss of all previous SSO data. I then surrounded create new object line with a boolean that was set to false from onSuccess which resolved issue with save, however if you accidentally refreshed browser, all data was lost. Lastly I attempted to persist the boolean and the result of that was the loss ability to actually generate a new object when coming to the create page from existing list page. Any body have any Ideas? sample code if(newObject newObjectUpdate) { objectState.setObject(new Object()); } -- View this message in context: http://tapestry.1045711.n5.nabble.com/Saving-using-form-zone-tp4639355p4639355.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Saving using form zone
George Christman wrote: Prior to converting my form to use a zone update, I use to save the form to the session then reload the update page with previous session data, however when using the zone update, it no longer redirects to the update page. A Zone is used to only update its content. I think in your case, where you always want to forward to a new page (the update page) using a zone is wrong. George Christman wrote: Issues, when saving form with zone update First I found it reruns all methods and creates a new object which causes a loss of all previous SSO data. I then surrounded create new object line with a boolean that was set to false from onSuccess which resolved issue with save, however if you accidentally refreshed browser, all data was lost. Lastly I attempted to persist the boolean and the result of that was the loss ability to actually generate a new object when coming to the create page from existing list page. I haven't fully understood the behavior you're describing, but I think somewhere in your code (maybe activate of page?) you initialize the object. This code is accidentially called after the zone update or when hitting the refresh button. What is the source code of objectState and how do you integrate that into your page/component? - http://www.winfonet.eu -- View this message in context: http://tapestry.1045711.n5.nabble.com/Saving-using-form-zone-tp4639355p4639470.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Saving using form zone
Well the only reason I'm using a Zone update on the form is because I need to save new addrow data contained within a popup box to the user session and then reload the form with select menus containing the addrow data. When I use to submit the request without using the zone update, the page would just reloaded using the update page, it would set the page scroll to the top of the page rather than just staying static when the popup box closed out. That destroyed the UX completely. The Zone update resolves the UX, however comes with the above side effects. The code. Create.class @Property private boolean newObject; void onActivate() { newObject = true; } Component.class @SessionState private ObjectState objectState; @Parameter private boolean newObject; private boolean newObjectUpdate; void onPrepareForRender() { if(newObject !newObjectUpdate) { objectState.setObject(new Object()); } } @OnEvent(value = EventConstants.SELECTED, component = update) Object updateObjectRequest() { objectState.setObject(getObject()); newObjectUpdate = true; return formZone.getBody(); } @CommitAfter @OnEvent(value = EventConstants.SELECTED, component = commit) Object commitObjectRequest() { Session newSession = sessionSource.getSessionFactory().openSession(); Transaction tx = null; try { tx = newSession.beginTransaction(); newSession.saveOrUpdate(getObject()); update.setObject(getObject()); tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback(); } throw e; } finally { newSession.close(); } return update; } public Object getObject() { return objectState.getObject(); } Update.class public void setObject(Object object) { this.object= object; } Class? onActivate(Object object) { if(object!= null) { this.object= object; } else { return Index.class; } return null; } Object onPassivate() { Object value = null; if (object != null) { value = object.getId(); } return value; } void setupRender() { if((objectState.getObject() == null) || (object != null !object .getId().equals(objectState.getObjectt().getId( { objectState.setObject(object); } } -- View this message in context: http://tapestry.1045711.n5.nabble.com/Saving-using-form-zone-tp4639355p4639665.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Saving using form zone
does anybody see anything wrong with doing something like this Previous Page t:PageLink page=purchase_request context=new/ New PurchaseRequest class. Object onActivate(String newPr) { if(new.equalsIgnoreCase(newPr)) { purchaseRequestState.setPurchaseRequest(new PurchaseRequest()); return Purchase_RequestIndex.class; } return null; } void onActivate() { if(purchaseRequestState.getPurchaseRequest() == null) { purchaseRequestState.setPurchaseRequest(new PurchaseRequest()); } } -- View this message in context: http://tapestry.1045711.n5.nabble.com/Saving-using-form-zone-tp4639355p4639844.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Saving using form zone
I'd have a single onActivate(EventContext context) method instead of two. On Wed, 27 Jul 2011 15:45:16 -0300, George Christman gchrist...@cardaddy.com wrote: does anybody see anything wrong with doing something like this Previous Page t:PageLink page=purchase_request context=new/ New PurchaseRequest class. Object onActivate(String newPr) { if(new.equalsIgnoreCase(newPr)) { purchaseRequestState.setPurchaseRequest(new PurchaseRequest()); return Purchase_RequestIndex.class; } return null; } void onActivate() { if(purchaseRequestState.getPurchaseRequest() == null) { purchaseRequestState.setPurchaseRequest(new PurchaseRequest()); } } -- View this message in context: http://tapestry.1045711.n5.nabble.com/Saving-using-form-zone-tp4639355p4639844.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org -- Thiago H. de Paula Figueiredo Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and instructor Owner, Ars Machina Tecnologia da Informação Ltda. Consultor, desenvolvedor e instrutor em Java, Tapestry e Hibernate http://www.arsmachina.com.br - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Saving using form zone
Much better solution, Thanks Thiago. Sorry about all the questions, first really complex backend project. You guys have really helped a ton. -- View this message in context: http://tapestry.1045711.n5.nabble.com/Saving-using-form-zone-tp4639355p4639921.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Saving using form zone
Hi George, I' move @SessionState private ObjectState objectState; away from Component.class and make it a field of both of your page classes. You're using a SSO anyway so there's no point in fumbeling around with acrivation contexts. And this looks a bit awfull void setupRender() { if((objectState.getObject() == null) || (object != null !object .getId().equals(objectState.getObjectt().getId( { objectState.setObject(object); } I'd rewrite that to (Hope I got it correct): void setupRender() { if this.object == null { return; } final YourObjetType stateValue = this.objectState.getObject(); if (stateValue == null { this.objectState.setObject(this.object); return; } if (! stateValue.getId().equals(tihs.object.getId()) { this.objectState.setObject(this.object); } } - http://www.winfonet.eu -- View this message in context: http://tapestry.1045711.n5.nabble.com/Saving-using-form-zone-tp4639355p4640181.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Saving using form zone
Yup I agree, I moved session state away from my component earlier. I suppose your code looks a bit more elegant than my awful looking condition statement :) I'll remember this technique going forward. Thanks! -- View this message in context: http://tapestry.1045711.n5.nabble.com/Saving-using-form-zone-tp4639355p4640244.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: Saving using form zone
If you need ObjectState in your component, use @Parameter. Forgot to mention that in my earlier post. - http://www.winfonet.eu -- View this message in context: http://tapestry.1045711.n5.nabble.com/Saving-using-form-zone-tp4639355p4640463.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org