RE: NullPointerException in cleanupAfterRender()
The editPageMap was initialised during pageBeginRender(): @InjectPage(EditItem) public abstract EditItemPage getEditItemPage(); public void pageBeginRender(PageEvent event) { editPageMap = new HashMapClass, EditItemPage(); editPageMap.put(Item.class, getEditItemPage()); Why don't you just use page names as map values instead of page instances? Caching pages in any way is not a good idea... After the doEdit is invoked you wold use the name to instatiate the page needed. If type maps to one page, you'are probably instantiating many pages now on every pageBeginRender call (twice for a request during render/rewind) which is IMHO very ineffecitve. Moreover you will use only one page from all of this superfluously instantiated ones eventually, am I right? Oh, absolutely - I'm a Tapestry noob, and I am playing around with things to find what works and what doesn't. This approach (page injection with annotations) was mentioned in the tutorials, so it's really the only one I was aware of. Initially, I lazy-initialized the HashMap if not null which would make performance less of a problem (but probably still lead to problems with cached page instances, I now understand), but I removed that during the course of simplifying the code to figure out what went wrong. Thanks for the tip about page names! I will look into how to do that, it sounds like the way to go. My other point is probably still relevant, though: it seems as if the following code shows a problem: @InjectPage(EditItem) public abstract EditItemPage getEditItemPage(); public void pageBeginRender(PageEvent event) { IPage invalidInstance = getEditItemPage(); // BAD } public void listenerMethod() { IPage validInstance = getEditItemPage(); // GOOD } That really feels a little weird to me as a programmer. I suppose that it will never be useful to return an invalid instance, so what I was wondering is if it would be at all possible for the getEditItemPage() method to throw an exception or return null if it is called at an inappropriate time in the render cycle? That would make it easier for a programmer to catch his mistake. Thanks, Petter - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
NullPointerException in cleanupAfterRender()
Hi, I've been struggling for some hours now with a weird problem that I don't at all understand where it comes from. I'm using Tapestry 4.0.2, and the stacktrace of the exception, which happens when i try to display the page, is: # org.apache.tapestry.bean.BeanProvider.init(BeanProvider.java:104) # org.apache.tapestry.AbstractComponent.getBeans(AbstractComponent.java:580) # org.apache.tapestry.binding.BeanBinding.getObject(BeanBinding.java:64) # org.apache.tapestry.binding.AbstractBinding.getObject(AbstractBinding.java:8 7) # $Form_10.getDelegate($Form_10.java) # org.apache.tapestry.form.Form.cleanupAfterRender(Form.java:210) # $Form_10.cleanupAfterRender($Form_10.java) # org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:623) # org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:434) Line 104 in BeanProvider is: Infrastructure infrastructure = component.getPage().getRequestCycle().getInfrastructure(); I guess that that could cause an NPE if there was something wrong in the page/component setup. But I can't figure out what it is, despite lots of trial and error with all kinds of alternatives. A small setup that gives me the error is: -- EditItem.html - html head /head body span jwcid=$content$ span jwcid=@Border Edit... form jwcid=[EMAIL PROTECTED] success=listener:doSubmit !-- irrelevant whether i put actual form components here or not -- input type=submit value=Save/ /form p/ a jwcid=@PageLink page=ListAll href=#List All/a /span /span /body /html -- - EditItem.page --- ?xml version=1.0 encoding=UTF-8? !DOCTYPE page-specification PUBLIC -//Apache Software Foundation//Tapestry Specification 4.0//EN http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd; page-specification class=se.jadestone.spirits.wrs.EditItemPage descriptionedits something old/description /page-specification - EditItemPage.java - package se.jadestone.spirits.wrs; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.tapestry.html.BasePage; public class EditItemPage extends BasePage { private static final Log log = LogFactory.getLog(EditItemPage.class); public void doSubmit() { log.debug(doSubmit()); } } - I'm running the application through Eclipse/JettyLauncher/Jetty. Can anybody give me a hint as to what could be going wrong here? There's another form in the application that works, and I can't see what the problem could be. I'm sure it's something stupid that I'm missing. Thanks, Petter - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: NullPointerException in cleanupAfterRender()
Hi again, It struck me that maybe the problem was related to how the page was invoked, and it turned out to be right: public IPage doEdit(int id) { System.out.println(doEdit( + id + )); Entity entity = getEntityLister().getEntity(id); EditItemPage page = editPageMap.get(entity.getClass()); page.setEntity(entity); return page; } The editPageMap was initialised during pageBeginRender(): @InjectPage(EditItem) public abstract EditItemPage getEditItemPage(); public void pageBeginRender(PageEvent event) { editPageMap = new HashMapClass, EditItemPage(); editPageMap.put(Item.class, getEditItemPage()); } Apparently, at that time, the page returned by getEditItemPage() is invalid, or so I would assume. If I do the call to getEditItemPage() in the doSubmit() method, things work as they should. What I was hoping to achieve was a nice way of sending the user to different edit pages depending on which entity type he was trying to edit. If it is in fact the case that methods like getEditItemPage() above do not return valid IPage instances at the time that pageBeginRender() executes, would it be possible for them to identify that and throw an exception instead? Best, Petter -Original Message- From: Petter Måhlén [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 05, 2006 1:37 PM To: 'users@tapestry.apache.org' Subject: NullPointerException in cleanupAfterRender() Hi, I've been struggling for some hours now with a weird problem that I don't at all understand where it comes from. I'm using Tapestry 4.0.2, and the stacktrace of the exception, which happens when i try to display the page, is: # org.apache.tapestry.bean.BeanProvider.init(BeanProvider.java:104) # org.apache.tapestry.AbstractComponent.getBeans(AbstractCompone nt.java:580) # org.apache.tapestry.binding.BeanBinding.getObject(BeanBinding.java:64) # org.apache.tapestry.binding.AbstractBinding.getObject(Abstract Binding.java:87) # $Form_10.getDelegate($Form_10.java) # org.apache.tapestry.form.Form.cleanupAfterRender(Form.java:210) # $Form_10.cleanupAfterRender($Form_10.java) # org.apache.tapestry.AbstractComponent.render(AbstractComponent .java:623) # org.apache.tapestry.AbstractComponent.renderBody(AbstractCompo nent.java:434) Line 104 in BeanProvider is: Infrastructure infrastructure = component.getPage().getRequestCycle().getInfrastructure(); I guess that that could cause an NPE if there was something wrong in the page/component setup. But I can't figure out what it is, despite lots of trial and error with all kinds of alternatives. A small setup that gives me the error is: -- EditItem.html - html head /head body span jwcid=$content$ span jwcid=@Border Edit... form jwcid=[EMAIL PROTECTED] success=listener:doSubmit !-- irrelevant whether i put actual form components here or not -- input type=submit value=Save/ /form p/ a jwcid=@PageLink page=ListAll href=#List All/a /span /span /body /html -- - EditItem.page --- ?xml version=1.0 encoding=UTF-8? !DOCTYPE page-specification PUBLIC -//Apache Software Foundation//Tapestry Specification 4.0//EN http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd; page-specification class=se.jadestone.spirits.wrs.EditItemPage descriptionedits something old/description /page-specification - EditItemPage.java - package se.jadestone.spirits.wrs; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.tapestry.html.BasePage; public class EditItemPage extends BasePage { private static final Log log = LogFactory.getLog(EditItemPage.class); public void doSubmit() { log.debug(doSubmit()); } } - I'm running the application through Eclipse/JettyLauncher/Jetty. Can anybody give me a hint as to what could be going wrong here? There's another form in the application that works, and I can't see what the problem could be. I'm sure it's something stupid that I'm missing. Thanks, Petter - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]