You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "burnstone@burnstone.ch" <bu...@burnstone.ch> on 2009/08/04 07:33:47 UTC
Problems with CheckGroup
Hi all
I'm trying to use CheckGroup, but encounter some problems. First, my code:
class NameValueListView<T extends ParameterValueProvider<?>> extends
ListView<T> {
<U> void displayItem(ListItem<T> listItem, ParameterValueProvider<U>
parameter) {
...
List<U> enumItems = new ArrayList<U>(parameter.getEnumCodes());
addMultiSelectPanelListItem(listItem, enumItems, labelModel, new
PropertyModel<Collection<U>>(parameter,
"valueList"), parameter);
}
<U> void addMultiSelectPanelListItem(ListItem<T> listItem,
List<U> enumItems, IModel<String> labelModel,
IModel<Collection<U>> model,
final ParameterValueProvider<U> parameter) {
CheckGroup<U> comp = new CheckGroup<U>("value");
comp.setType(parameter.getType());
comp.setRequired(!parameter.isOptional());
comp.setLabel(labelModel);
ListView<U> enumListView = new ListView<U>("values", enumItems) {
@Override
protected void populateItem(ListItem<U> item) {
item.add(new Check<U>("check", item.getModel()));
item.add(new Label("value",
item.getDefaultModelObjectAsString()));
}
};
enumListView.setReuseItems(true);
comp.add(enumListView);
// Add panel
MultiCheckBoxPanel<U> panelMCB = new
MultiCheckBoxPanel<U>(COMPONENT_ID, comp);
listItem.add(panelMCB);
}
}
ParameterValueProvider has the mehtods {get,set}Value[List].
The html looks like this:
<html xmlns:wicket>
<wicket:panel>
<span wicket:id="value">
<span wicket:id="values">
<input type="checkbox" wicket:id="check" />
<span wicket:id="value"></span>
<br/>
</span>
</span>
</wicket:panel>
</html>
So far, so good. Values are getting displayed and the correct check
boxes are selected. However, when submitting the form, I get an exception:
---------------------------------------------------
WicketMessage: Method onFormSubmitted of interface
org.apache.wicket.markup.html.form.IFormSubmitListener targeted at
component [MarkupContainer [Component id = cardDetailForm]] threw an
exception
Root cause:
java.lang.ClassCastException: java.lang.String
at
org.apache.wicket.markup.html.form.CheckGroup.updateModel(CheckGroup.java:171)
at
org.apache.wicket.markup.html.form.Form$FormModelUpdateVisitor.component(Form.java:225)
at
org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:514)
at
org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:493)
at
org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:493)
at
org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:493)
at
org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:493)
at
org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrder(FormComponent.java:465)
at
org.apache.wicket.markup.html.form.Form.internalUpdateFormComponentModels(Form.java:2051)
at
org.apache.wicket.markup.html.form.Form.updateFormComponentModels(Form.java:2019)
at org.apache.wicket.markup.html.form.Form.process(Form.java:984)
at org.apache.wicket.markup.html.form.Form.process(Form.java:911)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:876)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
at
org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at
org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at
org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1241)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1320)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1419)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:456)
at
org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:289)
at
org.mortbay.jetty.servlet.WebApplicationHandler$Chain.doFilter(WebApplicationHandler.java:334)
at
org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:286)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:567)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1807)
at
org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:525)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1757)
at org.mortbay.http.HttpServer.service(HttpServer.java:879)
at org.mortbay.http.HttpConnection.service(HttpConnection.java:789)
at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:960)
at org.mortbay.http.HttpConnection.handle(HttpConnection.java:806)
at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:218)
at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:331)
at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:520)
Complete stack:
org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of
interface org.apache.wicket.markup.html.form.IFormSubmitListener
targeted at component [MarkupContainer [Component id = cardDetailForm]]
threw an exception
at
org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:193)
at
org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at
org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at
org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1241)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1320)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1419)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:456)
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
at
org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
at
org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at
org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1241)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1320)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1419)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:456)
---------------------------------------------------
I then looked at the wicket-examples and saw that CheckGroup was
initialized without a model. This won't work for me, but I tried it
anyway. The only result is:
---------------------------------------------------
"WicketMessage: CheckGroup [41:cardDetailForm:rows:11:panel:value]
contains a null model object, must be an object of type
java.util.Collection"
---------------------------------------------------
I didn't see any other major differences between the example and my code
(uh, okay, except some type parameters and stuff, but well...).
So. Any ideas?
-- chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Problems with CheckGroup
Posted by burnstone <bu...@burnstone.ch>.
burnstone wrote:
> Removing the setType-Call doesn't help.
Sorry, after some more debugging and then testing The Right Thing (tm) I
have to say this statement is wrong. Removing the call to setType()
fixes my problem.
Well.
Thanks for holding my hand, anyway :)
-- chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Problems with CheckGroup
Posted by Igor Vaynberg <ig...@gmail.com>.
so the next step is to step into convertinput() and see why its
returning a string instead of a collection.
-igor
On Tue, Aug 4, 2009 at 1:20 AM, burnstone<bu...@burnstone.ch> wrote:
> Debugging the code just tells me the same as the exception does:
>
> CheckGroup.updateModel:
>
> public void updateModel()
> {
> Collection<T> collection = getModelObject();
> if (collection == null)
> {
> collection = getConvertedInput();
> setDefaultModelObject(collection);
> }
> else
> {
> modelChanging();
> collection.clear();
> collection.addAll(getConvertedInput()); <-----
> modelChanged();
> }
> }
>
>
> getConvertedInput() returns a String instead of a collection instance. This
> just has to be wrong, because it returns T, the parameter of
> FormComponent<T>, and CheckGroup extends FormComponent<Collection<T>>.
>
> Removing the setType-Call doesn't help.
>
> Martin Makundi wrote:
>>
>> Have you tried to debug the code where you get the exception? I
>> suspect that you just have some data types mixed.
>>
>> Maybe it is just this: comp.setType(parameter.getType()); Is that
>> necessary?
>>
>> **
>> Martin
>>
>
> ---------------------------------------------------------------------
> 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: Problems with CheckGroup
Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Can you make a quickstart of it an send me?
**
Martin
2009/8/4 burnstone <bu...@burnstone.ch>:
> Debugging the code just tells me the same as the exception does:
>
> CheckGroup.updateModel:
>
> public void updateModel()
> {
> Collection<T> collection = getModelObject();
> if (collection == null)
> {
> collection = getConvertedInput();
> setDefaultModelObject(collection);
> }
> else
> {
> modelChanging();
> collection.clear();
> collection.addAll(getConvertedInput()); <-----
> modelChanged();
> }
> }
>
>
> getConvertedInput() returns a String instead of a collection instance. This
> just has to be wrong, because it returns T, the parameter of
> FormComponent<T>, and CheckGroup extends FormComponent<Collection<T>>.
>
> Removing the setType-Call doesn't help.
>
> Martin Makundi wrote:
>>
>> Have you tried to debug the code where you get the exception? I
>> suspect that you just have some data types mixed.
>>
>> Maybe it is just this: comp.setType(parameter.getType()); Is that
>> necessary?
>>
>> **
>> Martin
>>
>
> ---------------------------------------------------------------------
> 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: Problems with CheckGroup
Posted by burnstone <bu...@burnstone.ch>.
Debugging the code just tells me the same as the exception does:
CheckGroup.updateModel:
public void updateModel()
{
Collection<T> collection = getModelObject();
if (collection == null)
{
collection = getConvertedInput();
setDefaultModelObject(collection);
}
else
{
modelChanging();
collection.clear();
collection.addAll(getConvertedInput()); <-----
modelChanged();
}
}
getConvertedInput() returns a String instead of a collection instance.
This just has to be wrong, because it returns T, the parameter of
FormComponent<T>, and CheckGroup extends FormComponent<Collection<T>>.
Removing the setType-Call doesn't help.
Martin Makundi wrote:
> Have you tried to debug the code where you get the exception? I
> suspect that you just have some data types mixed.
>
> Maybe it is just this: comp.setType(parameter.getType()); Is that necessary?
>
> **
> Martin
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Problems with CheckGroup
Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Have you tried to debug the code where you get the exception? I
suspect that you just have some data types mixed.
Maybe it is just this: comp.setType(parameter.getType()); Is that necessary?
**
Martin
2009/8/4 burnstone <bu...@burnstone.ch>:
> Martin Makundi wrote:
>>
>> What is U? In my understanding Check(box) operates on a Boolean value
>> so the classcast exception might be there (btw. I always use
>> CheckBox.. I never tried Check..).
>
> <U> is just the parameter type, in this case a String, but could be an
> Integer or Float as well.
>
> The example code in wicket-examples uses Integers, btw.
>
> ---------------------------------------------------------------------
> 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: Problems with CheckGroup
Posted by burnstone <bu...@burnstone.ch>.
Martin Makundi wrote:
> What is U? In my understanding Check(box) operates on a Boolean value
> so the classcast exception might be there (btw. I always use
> CheckBox.. I never tried Check..).
<U> is just the parameter type, in this case a String, but could be an
Integer or Float as well.
The example code in wicket-examples uses Integers, btw.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Problems with CheckGroup
Posted by Martin Makundi <ma...@koodaripalvelut.com>.
What is U? In my understanding Check(box) operates on a Boolean value
so the classcast exception might be there (btw. I always use
CheckBox.. I never tried Check..).
**
Martin
2009/8/4 burnstone@burnstone.ch <bu...@burnstone.ch>:
> Hi all
>
> I'm trying to use CheckGroup, but encounter some problems. First, my code:
>
> class NameValueListView<T extends ParameterValueProvider<?>> extends
> ListView<T> {
>
> <U> void displayItem(ListItem<T> listItem, ParameterValueProvider<U>
> parameter) {
> ...
> List<U> enumItems = new ArrayList<U>(parameter.getEnumCodes());
> addMultiSelectPanelListItem(listItem, enumItems, labelModel, new
> PropertyModel<Collection<U>>(parameter,
> "valueList"), parameter);
> }
>
> <U> void addMultiSelectPanelListItem(ListItem<T> listItem,
> List<U> enumItems, IModel<String> labelModel,
> IModel<Collection<U>> model,
> final ParameterValueProvider<U> parameter) {
>
> CheckGroup<U> comp = new CheckGroup<U>("value");
> comp.setType(parameter.getType());
> comp.setRequired(!parameter.isOptional());
> comp.setLabel(labelModel);
>
> ListView<U> enumListView = new ListView<U>("values", enumItems) {
> @Override
> protected void populateItem(ListItem<U> item) {
> item.add(new Check<U>("check", item.getModel()));
> item.add(new Label("value",
> item.getDefaultModelObjectAsString()));
> }
> };
> enumListView.setReuseItems(true);
> comp.add(enumListView);
>
> // Add panel
> MultiCheckBoxPanel<U> panelMCB = new
> MultiCheckBoxPanel<U>(COMPONENT_ID, comp);
> listItem.add(panelMCB);
> }
> }
>
> ParameterValueProvider has the mehtods {get,set}Value[List].
>
> The html looks like this:
> <html xmlns:wicket>
> <wicket:panel>
> <span wicket:id="value">
> <span wicket:id="values">
> <input type="checkbox" wicket:id="check" />
> <span wicket:id="value"></span>
> <br/>
> </span>
> </span>
> </wicket:panel>
> </html>
>
> So far, so good. Values are getting displayed and the correct check boxes
> are selected. However, when submitting the form, I get an exception:
>
> ---------------------------------------------------
> WicketMessage: Method onFormSubmitted of interface
> org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component
> [MarkupContainer [Component id = cardDetailForm]] threw an exception
>
> Root cause:
>
> java.lang.ClassCastException: java.lang.String
> at
> org.apache.wicket.markup.html.form.CheckGroup.updateModel(CheckGroup.java:171)
> at
> org.apache.wicket.markup.html.form.Form$FormModelUpdateVisitor.component(Form.java:225)
> at
> org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:514)
> at
> org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:493)
> at
> org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:493)
> at
> org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:493)
> at
> org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:493)
> at
> org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrder(FormComponent.java:465)
> at
> org.apache.wicket.markup.html.form.Form.internalUpdateFormComponentModels(Form.java:2051)
> at
> org.apache.wicket.markup.html.form.Form.updateFormComponentModels(Form.java:2019)
> at org.apache.wicket.markup.html.form.Form.process(Form.java:984)
> at org.apache.wicket.markup.html.form.Form.process(Form.java:911)
> at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:876)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at
> org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
> at
> org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
> at
> org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
> at
> org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1241)
> at org.apache.wicket.RequestCycle.step(RequestCycle.java:1320)
> at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1419)
> at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
> at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:456)
> at
> org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:289)
> at
> org.mortbay.jetty.servlet.WebApplicationHandler$Chain.doFilter(WebApplicationHandler.java:334)
> at
> org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:286)
> at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:567)
> at org.mortbay.http.HttpContext.handle(HttpContext.java:1807)
> at
> org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:525)
> at org.mortbay.http.HttpContext.handle(HttpContext.java:1757)
> at org.mortbay.http.HttpServer.service(HttpServer.java:879)
> at org.mortbay.http.HttpConnection.service(HttpConnection.java:789)
> at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:960)
> at org.mortbay.http.HttpConnection.handle(HttpConnection.java:806)
> at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:218)
> at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:331)
> at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:520)
>
> Complete stack:
>
> org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of
> interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at
> component [MarkupContainer [Component id = cardDetailForm]] threw an
> exception
> at
> org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:193)
> at
> org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
> at
> org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
> at
> org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1241)
> at org.apache.wicket.RequestCycle.step(RequestCycle.java:1320)
> at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1419)
> at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
> at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:456)
>
> java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at
> org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
> at
> org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
> at
> org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
> at
> org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1241)
> at org.apache.wicket.RequestCycle.step(RequestCycle.java:1320)
> at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1419)
> at org.apache.wicket.RequestCycle.request(RequestCycle.java:545)
> at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:456)
> ---------------------------------------------------
>
> I then looked at the wicket-examples and saw that CheckGroup was initialized
> without a model. This won't work for me, but I tried it anyway. The only
> result is:
>
> ---------------------------------------------------
> "WicketMessage: CheckGroup [41:cardDetailForm:rows:11:panel:value] contains
> a null model object, must be an object of type java.util.Collection"
> ---------------------------------------------------
>
> I didn't see any other major differences between the example and my code
> (uh, okay, except some type parameters and stuff, but well...).
>
> So. Any ideas?
>
> -- chris
>
> ---------------------------------------------------------------------
> 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