You can create a simple PropertyModel to hold the value your form is trying to set. Here is an example:

public  Pageextends  WebPage {
   private  List letters = Arrays.asList(new  String[] {"A","B","C"  }));
   public  String  selected ="B";

   public  Page() {
     Form form =new  Form("form");
     DropDownChoice choice=new  DropDownChoice("ddc",new  
PropertyModel(this,"selected"), letters);
   }
}

The example is from: https://cwiki.apache.org/WICKET/dropdownchoice-examples.html. It is missing the generics if you are working in 1.4.x, but it demonstrates the process well. The model object here is the "selected" string. When the form saves it will set the "selected" string with the value in the drop down.

On 3/25/2011 9:40 AM, Jim Goodwin wrote:
I'm trying to follow the example in the Javadoc for DropDownChoice
which says:

Java:

List SITES = Arrays.asList(new String[] { "The Server Side", "Java Lobby", "Java.Net" });

// Add a dropdown choice component that uses Input's 'site' property to designate the // current selection, and that uses the SITES list for the available options. // Note that when the selection is null, Wicket will lookup a localized string to // represent this null with key: "id + '.null'". In this case, this is 'site.null'
  // which can be found in DropDownChoicePage.properties

  form.add(new DropDownChoice("site", SITES));
  HTML:
<select wicket:id="site">
<option>site 1</option>
<option>site 2</option>
</select>
 I follow this quite closely. The code is inside a form:

            List<String> recCapNames = new ArrayList<String>();
            for (Capability cap : recognizedCaps)
                recCapNames.add(cap.toString());

final DropDownChoice permissionDropDown = new DropDownChoice(
                    "permissionDropdown", recCapNames);
            add(permissionDropDown);

<select wicket:id="permissionDropdown">
<option>P1</option>
<option>P2</option>
</select>


The page renders fine. The dropdown shows the right elements in the list when I pull it down, and allows me to select one, etc. But when I hit any button on the form it pukes,
complaining about trying to setModelObject on a null model.

(I have several buttons on the form, only one of which is related to the DropDownChoice, and they all fail the same way. Their onSubmit() methods never get reached: some sort of general process of form-handling is run first, and that's where the exception happens.)

Stack dump below. Wicket 1.5 RC2.

Any ideas?

Thanks in advance
Jim

Stackdump:

Root cause:

java.lang.IllegalStateException: Attempt to set model object on null model of component: AdministerGroupForm:permissionspanel:permissionpanelform:permissionDropdown at org.apache.wicket.Component.setDefaultModelObject(Component.java:3006) at org.apache.wicket.markup.html.form.FormComponent.updateModel(FormComponent.java:1038) at org.apache.wicket.markup.html.form.Form$FormModelUpdateVisitor.component(Form.java:221) at org.apache.wicket.markup.html.form.Form$FormModelUpdateVisitor.component(Form.java:192) at org.apache.wicket.util.visit.Visits.visitPostOrderHelper(Visits.java:274) at org.apache.wicket.util.visit.Visits.visitPostOrderHelper(Visits.java:263) at org.apache.wicket.util.visit.Visits.visitPostOrder(Visits.java:246) at org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrder(FormComponent.java:384) at org.apache.wicket.markup.html.form.Form.internalUpdateFormComponentModels(Form.java:1669) at org.apache.wicket.markup.html.form.Form.updateFormComponentModels(Form.java:1634)
     at org.apache.wicket.markup.html.form.Form.process(Form.java:807)
at org.apache.wicket.markup.html.form.StatelessForm.process(StatelessForm.java:61) at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:743) at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:685)
     at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.wicket.RequestListenerInterface.internalInvoke(RequestListenerInterface.java:259) at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:215) at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.invokeListener(ListenerInterfaceRequestHandler.java:171) at org.apache.wicket.request.handler.ListenerInterfaceRequestHandler.respond(ListenerInterfaceRequestHandler.java:157) at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:706) at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:63) at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:212) at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:253) at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:138) at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:194) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1323) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:474) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:517) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:935) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:404) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:184) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:870) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
     at org.eclipse.jetty.server.Server.handle(Server.java:346)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:596) at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1068)
     at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:807)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:220) at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:426) at org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:241) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:528)
     at java.lang.Thread.run(Unknown Source)


---------------------------------------------------------------------
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]

Reply via email to