You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by dpmihai <dp...@yahoo.com> on 2012/04/25 10:58:43 UTC
Wicket 1.5 ListMultipleChoice add Serializable values
Hi.
I have a code that was working in 1.4 but it shows an error message in
wicket 1.5.
I have a TextField, an AjaxSubmitLink and a ListMultipleChoice. When I click
the submit link I want to add the value from text field to the list.
ArrayList<Serializable> list = new ArrayList<Serializable>();
list.add("1");
list.add("2");
list.add("3");
listModel = new Model<ArrayList<Serializable>>(list);
Form form = new Form("form");
final FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
feedbackPanel.setOutputMarkupId(true);
form.add(feedbackPanel);
final TextField<String> textField = new TextField<String>("txtValue", new
PropertyModel<String>(this, "objectModel"));
final Model<ArrayList<Serializable>> choiceModel = new
Model<ArrayList<Serializable>>();
final ListMultipleChoice listChoice = new ListMultipleChoice("listChoice",
choiceModel, listModel);
listChoice.setMaxRows(100);
listChoice.setOutputMarkupId(true);
AjaxSubmitLink addLink = new AjaxSubmitLink("addElement", form) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
if (objectModel == null) {
return;
}
ArrayList<Serializable> model = listModel.getObject();
if (objectModel instanceof String) {
try {
if (!model.contains(objectModel)) {
model.add(objectModel);
}
} catch (NumberFormatException ex) {
error("Invalid value type.");
}
}
if (target != null) {
target.add(listChoice);
}
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
target.add(form);
}
};
form.add(textField);
form.add(listChoice);
form.add(addLink);
add(form);
In Wicket 1.5 I get : "'4' is not a valid Serializable."
I have to use Serializable because I have more components text field, date
field to take the value.
I I use String instead of Serializable, it works.
What is wrong in wicket 1,5?
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-1-5-ListMultipleChoice-add-Serializable-values-tp4585991p4585991.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: Wicket 1.5 ListMultipleChoice add Serializable values
Posted by dpmihai <dp...@yahoo.com>.
A DateTimeField does not need the converter to populate a Serializable model:
final DateTimeField txtTime = new DateTimeField("txtTime",
new PropertyModel<Date>(this, "objectModel"));
But there are other bugs with it
(https://issues.apache.org/jira/browse/WICKET-4496), so if something will be
done here maybe it will also be necessary to add the converter.
But this is some redundant code. Maybe something will be done in the future.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-1-5-ListMultipleChoice-add-Serializable-values-tp4585991p4586363.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: Wicket 1.5 ListMultipleChoice add Serializable values
Posted by dpmihai <dp...@yahoo.com>.
Yes Decebal. You are right. If I have a TextField of some type but my model
is a generic one (in my case objectModel is of type Serializable), I have to
overwrite getConverter method like:
final TextField<String> textField = new TextField<String>("txtValue",
new PropertyModel<String>(this, "objectModel")) {
@Override
public <C> IConverter<C> getConverter(Class<C> type) {
return new AbstractConverter() {
public Object convertToObject(String value, Locale locale) {
return value;
}
@Override
protected Class getTargetType() {
return String.class;
}
};
}
};
This was not necessary in wicket 1.4. Something was changed in converters
area in wicket 1.5
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-1-5-ListMultipleChoice-add-Serializable-values-tp4585991p4586325.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: Wicket 1.5 ListMultipleChoice add Serializable values
Posted by Decebal Suiu <de...@asf.ro>.
Maybe you must override TextField.getConverter() because the text field
component cannot knows to convert text to object/serializable.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-1-5-ListMultipleChoice-add-Serializable-values-tp4585991p4586299.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: Wicket 1.5 ListMultipleChoice add Serializable values
Posted by dpmihai <dp...@yahoo.com>.
I forgot to say my object model from TextField is
private Serializable objectModel;
I do not understand how a String is not Serializable?
This code worked on wicket 1.4 without problems. I think something is done
different in wicket framework.
Can you tell me what class throws this error message?
A code like you suggested :
ArrayList<? extends Serializable> list = new ArrayList<Serializable>();
list.add("1");
doesn't even compile.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-1-5-ListMultipleChoice-add-Serializable-values-tp4585991p4586221.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: Wicket 1.5 ListMultipleChoice add Serializable values
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
It is pure Java, not Wicket: ArrayList<? extends Serializable>
On Wed, Apr 25, 2012 at 11:58 AM, dpmihai <dp...@yahoo.com> wrote:
> Hi.
>
> I have a code that was working in 1.4 but it shows an error message in
> wicket 1.5.
>
> I have a TextField, an AjaxSubmitLink and a ListMultipleChoice. When I click
> the submit link I want to add the value from text field to the list.
>
> ArrayList<Serializable> list = new ArrayList<Serializable>();
> list.add("1");
> list.add("2");
> list.add("3");
> listModel = new Model<ArrayList<Serializable>>(list);
>
> Form form = new Form("form");
>
> final FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
> feedbackPanel.setOutputMarkupId(true);
> form.add(feedbackPanel);
>
> final TextField<String> textField = new TextField<String>("txtValue", new
> PropertyModel<String>(this, "objectModel"));
>
> final Model<ArrayList<Serializable>> choiceModel = new
> Model<ArrayList<Serializable>>();
> final ListMultipleChoice listChoice = new ListMultipleChoice("listChoice",
> choiceModel, listModel);
> listChoice.setMaxRows(100);
> listChoice.setOutputMarkupId(true);
>
> AjaxSubmitLink addLink = new AjaxSubmitLink("addElement", form) {
>
> @Override
> protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
> if (objectModel == null) {
> return;
> }
> ArrayList<Serializable> model = listModel.getObject();
> if (objectModel instanceof String) {
> try {
> if (!model.contains(objectModel)) {
> model.add(objectModel);
> }
> } catch (NumberFormatException ex) {
> error("Invalid value type.");
> }
> }
>
> if (target != null) {
> target.add(listChoice);
> }
> }
>
> @Override
> protected void onError(AjaxRequestTarget target, Form<?> form) {
> target.add(form);
> }
>
> };
>
> form.add(textField);
> form.add(listChoice);
> form.add(addLink);
> add(form);
>
> In Wicket 1.5 I get : "'4' is not a valid Serializable."
> I have to use Serializable because I have more components text field, date
> field to take the value.
> I I use String instead of Serializable, it works.
>
> What is wrong in wicket 1,5?
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-1-5-ListMultipleChoice-add-Serializable-values-tp4585991p4585991.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
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org