You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Russell Morrisey <rm...@csc.com> on 2007/08/31 21:17:52 UTC

Dynamic message for "required" validation in 1.3

Hello, all,

Wicket-1.3.0-SNAPSHOT

I'm trying to customize the "required" error message automatically based 
on the field name. The field I'm working with is on a custom panel called 
IssueStatusPanel, and I have:

IssueStatusPanel.properties:
statusDate.Required=Status date is required!

What I would like to have is something like:
statusDate.Required={status} date is required!

Where {status} is the name of the label associated with that item.

My panel uses a ListView, with a Label for each status:

//-------------------------------------------------------------
//Edited down this code for clarity (I hope!)
statuses = new ListView("statuses", new IssueStatusModel()) {
        ...
        protected void populateItem(ListItem item) {
 
                Radio radio = new Radio("status", [radioModel]);
                setupAjaxRadio(...);
                item.add(radio);
                item.add(new Label("statusLabel", new 
PropertyModel(item.getModel(), "cycleStatus.description")));
                ...
 
                final DateTextField statusDate = new 
StatusDateTextField("statusDate", ...);
                statusDate.setRequired(true); //*Here is the validation I 
am trying to customize*
                item.add(statusDate);
                ...
        }
}
//-------------------------------------------------------------

I want the text from cycleStatus.description to appear as {status} in my 
validation.

I think I would want to implement AbstractValidator#
variablesMap(IValidatable validatable), but I see that "required" no 
longer uses a validator in 1.3.  Is there another route I can take, or do 
I have to implement a custom validator that does the same function as a 
required check? Do I need to have a label or label model attached to my 
DateTextField in order to use it as a field name?

I am a little new to wicket's validations, so maybe there is a nice clean 
solution that I'm just not seeing.

Any help is appreciated.  Let me know if I need to provide any more 
information to show what I'm trying to do. Thanks!
Russell Morrisey
Computer Sciences Corporation

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
NOTE: Regardless of content, this e-mail shall not operate to bind CSC to 
any order or other contract unless pursuant to explicit written agreement 
or government initiative expressly permitting the use of e-mail for such 
purpose.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Re: Dynamic message for "required" validation in 1.3

Posted by Igor Vaynberg <ig...@gmail.com>.
and formcomponent.setlabel(imodel)

-igor


On 8/31/07, Igor Vaynberg <ig...@gmail.com> wrote:
>
> statusDate.Required=${label} date is required!
>
> -igor
>
>
>
> On 8/31/07, Russell Morrisey <rmorrisey@csc.com > wrote:
> >
> > Hello, all,
> >
> > Wicket-1.3.0-SNAPSHOT
> >
> > I'm trying to customize the "required" error message automatically based
> >
> > on the field name. The field I'm working with is on a custom panel
> > called
> > IssueStatusPanel, and I have:
> >
> > IssueStatusPanel.properties:
> > statusDate.Required=Status date is required!
> >
> > What I would like to have is something like:
> > statusDate.Required={status} date is required!
> >
> > Where {status} is the name of the label associated with that item.
> >
> > My panel uses a ListView, with a Label for each status:
> >
> > //-------------------------------------------------------------
> > //Edited down this code for clarity (I hope!)
> > statuses = new ListView("statuses", new IssueStatusModel()) {
> >         ...
> >         protected void populateItem(ListItem item) {
> >
> >                 Radio radio = new Radio("status", [radioModel]);
> >                 setupAjaxRadio(...);
> >                 item.add(radio);
> >                 item.add(new Label("statusLabel", new
> > PropertyModel(item.getModel(), "cycleStatus.description")));
> >                 ...
> >
> >                 final DateTextField statusDate = new
> > StatusDateTextField("statusDate", ...);
> >                 statusDate.setRequired(true); //*Here is the validation
> > I
> > am trying to customize*
> >                 item.add(statusDate);
> >                 ...
> >         }
> > }
> > //-------------------------------------------------------------
> >
> > I want the text from cycleStatus.description to appear as {status} in my
> >
> > validation.
> >
> > I think I would want to implement AbstractValidator#
> > variablesMap(IValidatable validatable), but I see that "required" no
> > longer uses a validator in 1.3.  Is there another route I can take, or
> > do
> > I have to implement a custom validator that does the same function as a
> > required check? Do I need to have a label or label model attached to my
> > DateTextField in order to use it as a field name?
> >
> > I am a little new to wicket's validations, so maybe there is a nice
> > clean
> > solution that I'm just not seeing.
> >
> > Any help is appreciated.  Let me know if I need to provide any more
> > information to show what I'm trying to do. Thanks!
> > Russell Morrisey
> > Computer Sciences Corporation
> >
> >
> > --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> > NOTE: Regardless of content, this e-mail shall not operate to bind CSC
> > to
> > any order or other contract unless pursuant to explicit written
> > agreement
> > or government initiative expressly permitting the use of e-mail for such
> > purpose.
> > --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> >
> >
>
>

Re: Dynamic message for "required" validation in 1.3

Posted by Igor Vaynberg <ig...@gmail.com>.
statusDate.Required=${label} date is required!

-igor



On 8/31/07, Russell Morrisey <rm...@csc.com> wrote:
>
> Hello, all,
>
> Wicket-1.3.0-SNAPSHOT
>
> I'm trying to customize the "required" error message automatically based
> on the field name. The field I'm working with is on a custom panel called
> IssueStatusPanel, and I have:
>
> IssueStatusPanel.properties:
> statusDate.Required=Status date is required!
>
> What I would like to have is something like:
> statusDate.Required={status} date is required!
>
> Where {status} is the name of the label associated with that item.
>
> My panel uses a ListView, with a Label for each status:
>
> //-------------------------------------------------------------
> //Edited down this code for clarity (I hope!)
> statuses = new ListView("statuses", new IssueStatusModel()) {
>         ...
>         protected void populateItem(ListItem item) {
>
>                 Radio radio = new Radio("status", [radioModel]);
>                 setupAjaxRadio(...);
>                 item.add(radio);
>                 item.add(new Label("statusLabel", new
> PropertyModel(item.getModel(), "cycleStatus.description")));
>                 ...
>
>                 final DateTextField statusDate = new
> StatusDateTextField("statusDate", ...);
>                 statusDate.setRequired(true); //*Here is the validation I
> am trying to customize*
>                 item.add(statusDate);
>                 ...
>         }
> }
> //-------------------------------------------------------------
>
> I want the text from cycleStatus.description to appear as {status} in my
> validation.
>
> I think I would want to implement AbstractValidator#
> variablesMap(IValidatable validatable), but I see that "required" no
> longer uses a validator in 1.3.  Is there another route I can take, or do
> I have to implement a custom validator that does the same function as a
> required check? Do I need to have a label or label model attached to my
> DateTextField in order to use it as a field name?
>
> I am a little new to wicket's validations, so maybe there is a nice clean
> solution that I'm just not seeing.
>
> Any help is appreciated.  Let me know if I need to provide any more
> information to show what I'm trying to do. Thanks!
> Russell Morrisey
> Computer Sciences Corporation
>
>
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> NOTE: Regardless of content, this e-mail shall not operate to bind CSC to
> any order or other contract unless pursuant to explicit written agreement
> or government initiative expressly permitting the use of e-mail for such
> purpose.
>
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>