Re: Wicket 1.5 ListMultipleChoice add Serializable values

2012-04-25 Thread dpmihai
A DateTimeField does not need the converter to populate a Serializable model:

final DateTimeField txtTime = new DateTimeField("txtTime",
new PropertyModel(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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Wicket 1.5 ListMultipleChoice add Serializable values

2012-04-25 Thread dpmihai
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 textField = new TextField("txtValue",
new PropertyModel(this, "objectModel")) {
@Override
public  IConverter getConverter(Class 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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Wicket 1.5 ListMultipleChoice add Serializable values

2012-04-25 Thread Decebal Suiu
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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Wicket 1.5 ListMultipleChoice add Serializable values

2012-04-25 Thread dpmihai
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 list = new ArrayList();
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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Wicket 1.5 ListMultipleChoice add Serializable values

2012-04-25 Thread Martin Grigorov
Hi,

It is pure Java, not Wicket: ArrayList

On Wed, Apr 25, 2012 at 11:58 AM, dpmihai  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 list = new ArrayList();
> list.add("1");
> list.add("2");
> list.add("3");
> listModel = new Model>(list);
>
> Form form = new Form("form");
>
> final FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
> feedbackPanel.setOutputMarkupId(true);
> form.add(feedbackPanel);
>
> final TextField textField = new TextField("txtValue", new
> PropertyModel(this, "objectModel"));
>
> final Model> choiceModel = new
> Model>();
> 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 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-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Wicket 1.5 ListMultipleChoice add Serializable values

2012-04-25 Thread dpmihai
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 list = new ArrayList();
list.add("1");
list.add("2");
list.add("3");
listModel = new Model>(list);

Form form = new Form("form");

final FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
feedbackPanel.setOutputMarkupId(true);
form.add(feedbackPanel);

final TextField textField = new TextField("txtValue", new
PropertyModel(this, "objectModel"));

final Model> choiceModel = new
Model>();
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 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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org