tapestry-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Petter Måhlén <petter.mah...@jadestone.se>
Subject RE: NullPointerException in cleanupAfterRender()
Date Wed, 05 Jul 2006 14:57:17 GMT
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 HashMap<Class, 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:petter.mahlen@jadestone.se] 
> 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="form@Form" 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">
> 
>     <description>edits 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: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Mime
View raw message