You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Zeldor <pg...@gmail.com> on 2010/10/12 20:23:47 UTC

MinimumValidator and Long problem

I have TextField that should take Long value, but on submit it does not
really work...


org.apache.wicket.RequestCycle logRuntimeException: Exception
'java.lang.ClassCastException: java.lang.Integer cannot be cast to
java.lang.Long' occurred during validation
org.apache.wicket.validation.validator.MinimumValidator on component
10:workForm:hire_worker_1
org.apache.wicket.WicketRuntimeException: Exception
'java.lang.ClassCastException: java.lang.Integer cannot be cast to
java.lang.Long' occurred during validation
org.apache.wicket.validation.validator.MinimumValidator on component
10:workForm:hire_worker_1


My code looks like that:

public Work() {
		add(new FeedbackPanel("errorMsg"));
		Form<String> workForm = new Form<String>("workForm", new Model<String>())
{
			private TextField<Long> hire_worker_1 = new
TextField<Long>("hire_worker_1", new Model<Long>());
...
{
...
add(hire_worker_1.add(new MinimumValidator(0))
						.setType(Long.class));
...
}

@Override
		public void onSubmit() {
			long hiring_worker_1 = hire_worker_1.getModelObject();
                        ...
}
	};
	add(workForm);
	}

Eclipse does like "new MinimumValidator<Long>(0)", so what's the solution
for my problem?

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/MinimumValidator-and-Long-problem-tp2992468p2992468.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: MinimumValidator and Long problem

Posted by Zeldor <pg...@gmail.com>.
I have nothing else really, just same more of same stuff, only a Form with
Labels, TextFields and submit method.

Anyway, deprecated NumberValidator.minimum(0) method works without any
problems, are there any disadvantages of using that?

On Wed, Oct 13, 2010 at 12:43 AM, jeremy@wickettraining.com [via Apache
Wicket] <ml...@n4.nabble.com>
> wrote:

> On Tue, Oct 12, 2010 at 5:36 PM, Igor Vaynberg <[hidden email]<http://user/SendEmail.jtp?type=node&node=2992859&i=0>>wrote:
>
>
> > its not a syntax problem. you cant have code outside a method unless
> > its in a static {} block.
> >
> >
> To me, putting code outside a method *is* a syntax problem, typically
> caused
> by inexperience with anonymous inner classes, leading to not enough, or too
>
> many }
>
> --
> Jeremy Thomerson
> http://www.wickettraining.com <http://www.wickettraining.com?by-user=t>
>
>
> ------------------------------
>  View message @
> http://apache-wicket.1842946.n4.nabble.com/MinimumValidator-and-Long-problem-tp2992468p2992859.html
> To unsubscribe from MinimumValidator and Long problem, click here<http://apache-wicket.1842946.n4.nabble.com/template/TplServlet.jtp?tpl=unsubscribe_by_code&node=2992468&code=cGdyb25raWV3aWN6QGdtYWlsLmNvbXwyOTkyNDY4fC0xMTUwMjA4NDM=>.
>
>
>

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/MinimumValidator-and-Long-problem-tp2992468p2993027.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: MinimumValidator and Long problem

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Tue, Oct 12, 2010 at 5:36 PM, Igor Vaynberg <ig...@gmail.com>wrote:

> its not a syntax problem. you cant have code outside a method unless
> its in a static {} block.
>
>
To me, putting code outside a method *is* a syntax problem, typically caused
by inexperience with anonymous inner classes, leading to not enough, or too
many }

-- 
Jeremy Thomerson
http://www.wickettraining.com

Re: MinimumValidator and Long problem

Posted by Igor Vaynberg <ig...@gmail.com>.
its not a syntax problem. you cant have code outside a method unless
its in a static {} block.

-igor

On Tue, Oct 12, 2010 at 3:25 PM, Jeremy Thomerson
<je...@wickettraining.com> wrote:
> On Tue, Oct 12, 2010 at 5:07 PM, Zeldor <pg...@gmail.com> wrote:
>
>>
>> Changing it to :
>>
>> private TextField<Long> hire_worker_1 = new
>> TextField<Long>("hire_worker_1",
>> new Model<Long>());
>>             {
>>            hire_worker_1.setType(Long.class);
>>            }
>>
>> Does not change anything. And is it normal that Eclipse does not let me add
>> anything without enclosing in { }?
>>
>
> Seems like you have a syntax error.... perhaps a problem with an anonymous
> inner class.  You can use Pastebin to paste entire file and we can attempt
> to help.
>
>
>> BTW, is there any easy way to convert nulls to 0 when you submit empty
>> TextFields?
>>
>
> Create an IConverter and override getConverter
>
>
> --
> Jeremy Thomerson
> http://www.wickettraining.com
>

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


Re: MinimumValidator and Long problem

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Tue, Oct 12, 2010 at 5:07 PM, Zeldor <pg...@gmail.com> wrote:

>
> Changing it to :
>
> private TextField<Long> hire_worker_1 = new
> TextField<Long>("hire_worker_1",
> new Model<Long>());
>             {
>            hire_worker_1.setType(Long.class);
>            }
>
> Does not change anything. And is it normal that Eclipse does not let me add
> anything without enclosing in { }?
>

Seems like you have a syntax error.... perhaps a problem with an anonymous
inner class.  You can use Pastebin to paste entire file and we can attempt
to help.


> BTW, is there any easy way to convert nulls to 0 when you submit empty
> TextFields?
>

Create an IConverter and override getConverter


-- 
Jeremy Thomerson
http://www.wickettraining.com

Re: MinimumValidator and Long problem

Posted by Zeldor <pg...@gmail.com>.
Changing it to :

private TextField<Long> hire_worker_1 = new TextField<Long>("hire_worker_1",
new Model<Long>());
            {
            hire_worker_1.setType(Long.class);
            }

Does not change anything. And is it normal that Eclipse does not let me add
anything without enclosing in { }?

BTW, is there any easy way to convert nulls to 0 when you submit empty
TextFields?

On Tue, Oct 12, 2010 at 11:31 PM, jeremy@wickettraining.com [via Apache
Wicket] <ml...@n4.nabble.com>
> wrote:

> Since your model doesn't actually know what type of field it is operating
> on
> (like PropertyModel does), you need to call setType(Long.class) on your
> text
> field.
>
> On Tue, Oct 12, 2010 at 1:23 PM, Zeldor <[hidden email]<http://user/SendEmail.jtp?type=node&node=2992772&i=0>>
> wrote:
>
> >
> > I have TextField that should take Long value, but on submit it does not
> > really work...
> >
> >
> > org.apache.wicket.RequestCycle logRuntimeException: Exception
> > 'java.lang.ClassCastException: java.lang.Integer cannot be cast to
> > java.lang.Long' occurred during validation
> > org.apache.wicket.validation.validator.MinimumValidator on component
> > 10:workForm:hire_worker_1
> > org.apache.wicket.WicketRuntimeException: Exception
> > 'java.lang.ClassCastException: java.lang.Integer cannot be cast to
> > java.lang.Long' occurred during validation
> > org.apache.wicket.validation.validator.MinimumValidator on component
> > 10:workForm:hire_worker_1
> >
> >
> > My code looks like that:
> >
> > public Work() {
> >                add(new FeedbackPanel("errorMsg"));
> >                Form<String> workForm = new Form<String>("workForm", new
> > Model<String>())
> > {
> >                        private TextField<Long> hire_worker_1 = new
> > TextField<Long>("hire_worker_1", new Model<Long>());
> > ...
> > {
> > ...
> > add(hire_worker_1.add(new MinimumValidator(0))
> >                                                .setType(Long.class));
> > ...
> > }
> >
> > @Override
> >                public void onSubmit() {
> >                        long hiring_worker_1 =
> > hire_worker_1.getModelObject();
> >                        ...
> > }
> >        };
> >        add(workForm);
> >        }
> >
> > Eclipse does like "new MinimumValidator<Long>(0)", so what's the solution
>
> > for my problem?
> >
> > --
> > View this message in context:
> >
> http://apache-wicket.1842946.n4.nabble.com/MinimumValidator-and-Long-problem-tp2992468p2992468.html<http://apache-wicket.1842946.n4.nabble.com/MinimumValidator-and-Long-problem-tp2992468p2992468.html?by-user=t>
> > Sent from the Users forum mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=2992772&i=1>
> > For additional commands, e-mail: [hidden email]<http://user/SendEmail.jtp?type=node&node=2992772&i=2>
> >
> >
>
>
> --
> Jeremy Thomerson
> http://www.wickettraining.com <http://www.wickettraining.com?by-user=t>
>
>
> ------------------------------
>  View message @
> http://apache-wicket.1842946.n4.nabble.com/MinimumValidator-and-Long-problem-tp2992468p2992772.html
> To unsubscribe from MinimumValidator and Long problem, click here<http://apache-wicket.1842946.n4.nabble.com/template/TplServlet.jtp?tpl=unsubscribe_by_code&node=2992468&code=cGdyb25raWV3aWN6QGdtYWlsLmNvbXwyOTkyNDY4fC0xMTUwMjA4NDM=>.
>
>
>

-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/MinimumValidator-and-Long-problem-tp2992468p2992825.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: MinimumValidator and Long problem

Posted by Jeremy Thomerson <je...@wickettraining.com>.
Since your model doesn't actually know what type of field it is operating on
(like PropertyModel does), you need to call setType(Long.class) on your text
field.

On Tue, Oct 12, 2010 at 1:23 PM, Zeldor <pg...@gmail.com> wrote:

>
> I have TextField that should take Long value, but on submit it does not
> really work...
>
>
> org.apache.wicket.RequestCycle logRuntimeException: Exception
> 'java.lang.ClassCastException: java.lang.Integer cannot be cast to
> java.lang.Long' occurred during validation
> org.apache.wicket.validation.validator.MinimumValidator on component
> 10:workForm:hire_worker_1
> org.apache.wicket.WicketRuntimeException: Exception
> 'java.lang.ClassCastException: java.lang.Integer cannot be cast to
> java.lang.Long' occurred during validation
> org.apache.wicket.validation.validator.MinimumValidator on component
> 10:workForm:hire_worker_1
>
>
> My code looks like that:
>
> public Work() {
>                add(new FeedbackPanel("errorMsg"));
>                Form<String> workForm = new Form<String>("workForm", new
> Model<String>())
> {
>                        private TextField<Long> hire_worker_1 = new
> TextField<Long>("hire_worker_1", new Model<Long>());
> ...
> {
> ...
> add(hire_worker_1.add(new MinimumValidator(0))
>                                                .setType(Long.class));
> ...
> }
>
> @Override
>                public void onSubmit() {
>                        long hiring_worker_1 =
> hire_worker_1.getModelObject();
>                        ...
> }
>        };
>        add(workForm);
>        }
>
> Eclipse does like "new MinimumValidator<Long>(0)", so what's the solution
> for my problem?
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/MinimumValidator-and-Long-problem-tp2992468p2992468.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
>
>


-- 
Jeremy Thomerson
http://www.wickettraining.com