Attempt to set the model object to the component zero model

I'm new to Wicket, but googling this problem did not give me anything that made sense. So I hope someone from SO can help.

I have a SiteChoice object that extends the form and a SiteList object that extends DropDownChoice. The SiteChoice class is as follows:

public class SiteChoice extends Form { public SiteChoice(String id) { super(id); addSiteDropDown(); } private void addSiteDropDown() { ArrayList<DomainObj> siteList = new ArrayList<DomainObj>(); // add objects to siteList ChoiceRenderer choiceRenderer = new ChoiceRenderer<DomainObj>("name", "URL"); this.add(new SiteList("siteid",siteList,choiceRenderer)); } } 

Then I just add the SiteChoice object to the a la page object:

  SiteChoice form = new SiteChoice("testform"); add(form); 

My Wicket template has:

When I lift the page, it displays a penalty - the drop-down list displays correctly. When I click Submit, I get this strange error:

 WicketMessage: Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = fittest]] threw an exception Root cause: java.lang.IllegalStateException: Attempt to set model object on null model of component: testform:siteid at org.apache.wicket.Component.setDefaultModelObject(Component.java:3033) at org.apache.wicket.markup.html.form.FormComponent.updateModel(FormComponent.java:1168) at [snip] 

I can not understand what null is. He looked great, so he found objects. What am I missing?

+4
source share
1 answer

Well, you are not showing the code for your SiteList class, but what happens is that something - almost certainly a drop down - does not have a model. Therefore, when the gate calls essentially dropdown.getModel().setModelObject( foo ) ; , it gets a null pointer exception.

My suggestion is that after the old rule of thumb OO, composition preference for inheritance. Your SiteChoice and SiteList classes don't seem to add much, and they make debugging difficult.

Instead, just add DropDownChoice to your form:

  form.add( new DropDownChioce( "siteid", new Model<DomainObject>(), new ChoiceRenderer<DomainObj>("name", "URL") ); 

This is more concise,

+12
source

All Articles