Hi Rüdiger,

Although at the end of your e-mail I thought "yes, he's right!" there is 
one thing you missed: the label does not have to have the same text as 
the name of the field.

For example, in my current application I have the following components 
on a search form:
Component:        label-housenumber  [field-from] [field-till]
Text/fieldname:    House number        [housenumber from] [housenumber till]

The label is coupled to the first field. As you can see the label is 
different from the name of the first field.
The only thing is, it is a bit weird I need to set a resource model on 
the field to get the text in the label.

Still, it would be nice to default to what you described. You could 
create an issue for it (with code to have it more quickly).
You can find Jira here: http://issues.apache.org/jira/browse/WICKET

Regards,
     Erik.



Rüdiger Schulz schreef:
> Hello everybody,
>
> I just wanted to dive a little into wicket i18n, and stumbled upon this:
>
> Say I have page with this simple form:
>
> Form form = new Form("form");
> add(form);
>               
> FeedbackPanel feedback = new FeedbackPanel("feedback");
> form.add(feedback);
>       
> TextField tx = new TextField("text");
> tx.setRequired(true);
> form.add(tx);
>
> and corresponding properties file for the page:
>
> form.text=FormTexti18n
>
> When I submit the empty form, I get the message:
>
> field 'FormTexti18n' is required.
>
> So, my label from the properties is used for the validation message. So
> far, so good.
>
> Now I'd like to have a label for the TextField, displaying the same
> string from the properties. Also, a normal Label is not enough for me,
> I'd like to change its CSS style depending on having an error.
>
> So I start with this:
>
> SimpleFormComponentLabel label =
>       new SimpleFormComponentLabel("textLabel", tx);
> form.add(label);
>
> Now I get an error:
>
> java.lang.IllegalStateException: Provided form component does not have a
> label set. Use FormComponent.setLabel(IModel) to set the model that will
> feed this label
>      at
> wicket.markup.html.form.SimpleFormComponentLabel.<init>(SimpleFormComponentLabel.java:46)
>
> Okay, this error tells me what to do, and I could do a
>
> tx.setLabel(new ResourceModel("form.textLabel"));
>
> And everything works fine. But ... :-)
>
> Is this really necessary? This ResourceModel is only required for the
> SimpleFormComponentLabel, I already have label through the properties!
>
> The JavaDoc FormComponent#getModel() says
>
> "The value will be made available to the validator property by means of
> ${label}."
>
> Which it does, but I'm wondering why SimpleFormComponentLabel can't do
> this the same way as the validator? Or is this one of those issues which
> will be gone with the changes in 2.0?
>
> greetings,
>
>
> Rüdiger
>
>   

-- 
Erik van Oosten
http://www.day-to-day-stuff.blogspot.com/


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to