Validation

3 views
Skip to first unread message

zabian

unread,
Jul 8, 2009, 9:27:08 AM7/8/09
to Wicket Web Beans
Hi, I have a problem with validation on my bean.
I set required:true property in .beanprops file, the red star is
indicating on that field, but it is avoided on validation, method save
allow to save the property even if it's blank.

Any idea?

BTW. Is it going to be some more extended validation mechanism on
further releases?
It would be great if WWB would service HibernateValidator by default.
Regex validation and minlength would be very useful.

Regards,
Wojtek.

zabian

unread,
Jul 9, 2009, 5:03:22 AM7/9/09
to Wicket Web Beans
I've noticed important thing - There is such situation only when I use
bean in context.
Is it bug?

Daniel Toffetti

unread,
Jul 9, 2009, 2:11:26 PM7/9/09
to Wicket Web Beans
Hi zabian,

Could you please build a mínimal test page showing the error ?
It's best if you copy one of the example pages, modify it as needed
and post it here, I'll try to take a look early next week.
Regarding future releases. if I am correct Dan has in mind to
mostly rewrite everything from scratch and taking a different approach
for WWB 2.0. My guess is that WWB 1.x will get just bug fixes and very
minor features only.

hth,

Daniel

zabian

unread,
Jul 10, 2009, 3:57:20 AM7/10/09
to Wicket Web Beans
CompanyEditPage.java:
public class CompanyEditPage extends BasePage {

Form form ;

public CompanyEditPage(final Object bean, Page returnPage, final
boolean viewOnly) {

BeanMetaData meta;
EditPanel editPanel = new EditPanel("beanForm", bean, returnPage);

if (viewOnly){
meta = new BeanMetaData(Company.class, "view", editPanel, null,
false);
} else {
meta = new BeanMetaData(Company.class, "edit", editPanel, null,
false);
}
add(editPanel = new EditPanel("beanForm", bean, returnPage, meta));
}

public static class EditPanel extends DataBeanEditPanel
{
Page returnPage;

public EditPanel(String id, Object bean, Page returnPage)
{
super(id, bean, returnPage);
this.returnPage = returnPage;
}



public EditPanel(String id, Object bean, Page returnPage,
BeanMetaData beanMetaData) {
super(id, bean, returnPage, beanMetaData);
this.returnPage = returnPage;
}
}
}
__________________________________________

CompanyEditPage$EditPanel.beanprops
Company {
label: Firma;
actions: cancel{label:"${action.cancel}"},
save{label:"${action.save}"};
props: -id, -workers, -units,
name, profile, EMPTY,
alphaID{colspan: 3;},
nip, regon, EMPTY,
krs, telephoneNumber, EMPTY,
address{colspan:2;};
}

Company[view] {
viewOnly: true;
props: -action.save, -action.cancel,
address{colspan:2; fieldType: BeanInCollapsibleField};
}

Company[edit] {
props: -action.back,
name {required:true}, alphaID{maxlength:5};

}

Address{
props: -id, -action.cancel, -action.save,
street{colspan:3;},
street2{colspan:3;},
zipCode, city{colspan:2;};
}

Address[view] {
viewOnly: true;
}

Address[edit] {
}
__________________________________________


So this is my use case, both validations (required, maxlength) are
avoided on save.
Actually it doesn't show any error, just validation doesn't work.
I hope you can tell me what's wrong.
Thanks for commitment.
Regards,
Wojtek

Dan Syrstad

unread,
Jul 10, 2009, 2:29:35 PM7/10/09
to wicket-w...@googlegroups.com
Hi Wojtek:

Actions don't automatically validate. For example, you wouldn't want your Cancel action to validate fields. Since WWB doesn't know the intent of your action, you have to explicitly add code to the action. For example,

    public void save(AjaxRequestTarget target, Form form, TestBean bean)
    {
      
        if (!BeanForm.findBeanFormParent(form).validateRequired()) {
            return; // Errors
        }
      
        info("Saved");
    }

There are several examples that have this code - one is com.googlecode.wicketwebbeans.examples.annotations.AnnotationsOnBeanPage.

-Dan

zabian

unread,
Jul 27, 2009, 6:24:52 AM7/27/09
to Wicket Web Beans
Hi,
sorry for delay at the beginning, but I had a vacation.

I realize that validateRequired is not called by default, but in my
case I use wwb-datbinder and extend default DataBeanEditPanel and I
use inherited save() method where validateRequired is called.

Thanks for commitment,
Wojtek

On 10 Lip, 20:29, Dan Syrstad <dsyrs...@gmail.com> wrote:
> Hi Wojtek:
>
> Actions don't automatically validate. For example, you wouldn't want your
> Cancel action to validate fields. Since WWB doesn't know the intent of your
> action, you have to explicitly add code to the action. For example,
>
>     public void save(AjaxRequestTarget target, Form form, TestBean bean)
>     {
>
>         if (!BeanForm.findBeanFormParent(form).validateRequired()) {
>             return; // Errors
>         }
>
>         info("Saved");
>     }
>
> There are several examples that have this code - one is
> com.googlecode.wicketwebbeans.examples.annotations.AnnotationsOnBeanPage.
>
> -Dan
>

Dan Syrstad

unread,
Jul 27, 2009, 10:00:40 AM7/27/09
to wicket-w...@googlegroups.com
Could you please send a full quick-start example? Can you reproduce this with the wwb-databinder examples?
-Dan

zabian

unread,
Jul 27, 2009, 10:22:25 AM7/27/09
to Wicket Web Beans
I think all what is important I included in code snippet above.
What looks strange for me - i am switch context this way:
EditPanel editPanel = new EditPanel("beanForm", bean, returnPage);

if (viewOnly){
meta = new BeanMetaData(Company.class, "view", editPanel, null,
false);
} else {
meta = new BeanMetaData(Company.class, "edit", editPanel, null,
false);
}

Anyway, I think there is no other way to do it avoiding java api.

Wojtek

On 27 Lip, 16:00, Dan Syrstad <dsyrs...@gmail.com> wrote:
> Could you please send a full quick-start example? Can you reproduce this
> with the wwb-databinder examples?
> -Dan
>

Dan Syrstad

unread,
Jul 27, 2009, 11:48:09 AM7/27/09
to wicket-w...@googlegroups.com
I cannot tell what is wrong from what you sent. It looks like it should work.


Can you reproduce this with the wwb-databinder examples?

-Dan

Reply all
Reply to author
Forward
0 new messages