You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jim Goodwin <jw...@gmail.com> on 2011/03/25 18:40:15 UTC
Trouble with DropDownChoice
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Choice of Resource for my Image component
Posted by Ian Marshall <Ia...@GMail.com>.
Hello Jim,
Could I ask you to post this in a separate topic? This one is for my choice
of resource for my Image component.
Cheers,
Ian
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Choice-of-Resource-for-my-Image-component-tp3342289p3406000.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Trouble with DropDownChoice
Posted by Sven Meier <sv...@meiers.net>.
Hi,
if you don't provide a model explicitly, a component will try to look up
one from its parent components.
Most of the time you use a CompoundPropertyModel, in this case the
example in the javadoc is valid:
form = new Form("form", new CompoundPropertyModel(this));
form.add(new DropDownChoice("selected", letters);
Hope this helps
Sven
On 03/25/2011 08:00 PM, Jim Goodwin wrote:
> On 3/25/2011 1:54 PM, Jered Myers wrote:
>> 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.
>>
> Ah. I get it. Thank you Jered.
>
> As a side question then, does this mean that the example cited in the
> DropDownChoice javadoc does not work? Because it only did:
>
>
> form.add(new DropDownChoice("site", SITES));
>
> So wouldn't it fail the same way?
>
> /jg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Trouble with DropDownChoice
Posted by Jim Goodwin <jw...@gmail.com>.
On 3/25/2011 1:54 PM, Jered Myers wrote:
> 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.
>
Ah. I get it. Thank you Jered.
As a side question then, does this mean that the example cited in the
DropDownChoice javadoc does not work? Because it only did:
form.add(new DropDownChoice("site", SITES));
So wouldn't it fail the same way?
/jg
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Trouble with DropDownChoice
Posted by Jered Myers <je...@maplewoodsoftware.com>.
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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org