Hello again,

Actually I have created a behavior that automatically add labels and
validation messages for all my formComponents:

  @Override
  public void beforeRender(Component component) {
    FormComponent formComponent = (FormComponent)component;

    if (formComponent.getLabel() == null) {
      logger.error("skipping, because no label set for " + component);
      return;
    }

    formComponent.setOutputMarkupId(true);

    Response response = formComponent.getResponse();

    String markupId = formComponent.getMarkupId();

    if (formComponent instanceof MyDateField) {
      MyDateField dateField = (MyDateField) formComponent;
      markupId = dateField.getInnerMarkupId();
    }

    response.write("<label for=\"" + markupId + "\">");
    response.write(formComponent.getLabel().getObject());

    // render validation message, if there is any
    if (!formComponent.isValid()) {
      String error = getFeedbackMessage(formComponent);
      response.write("<strong>" + error + "</strong>"
      );
    }

    response.write("</label>");
  }

As you can see, I have created a copy of DateField and added a method
for returning the markupid of the 'main' component:

  public String getInnerMarkupId() {
    return dateField.getMarkupId();
  }

Please let me know if there's a better solution.

And whether it would make sense to add this method to
FormComponentPanel so that subclasses can override it to return the
markupid of their 'main' formcomponent ?

regards,
Maarten

On Tue, Jul 22, 2008 at 11:35 AM, Maarten Bosteels
<[EMAIL PROTECTED]> wrote:
> Hello,
>
> How can I add a SimpleFormComponentLabel for an
> org.apache.wicket.extensions.yui.calendar.DateField ?
>
> The problem is that the SimpleFormComponentLabel uses the markupid of
> the DateField itself
> instead of the markupid of the nested DateTextField.
>
> This code
>
>    DateField departure = new DateField("departureDate");
>    departure.setLabel(new Model<String>("Departure"));
>    form.add(departure);
>    form.add(new SimpleFormComponentLabel("departureLabel", departure));
>
> results in the following html:
>
>    <label for="departureDatee">Departure</label>
>    <span id="departureDatee" name="departureDate">
>      <span style="white-space: nowrap;">
>      <input id="dateb" name="departureDate:date" size="8" type="text"
> value=""/>
>      <span class="yui-skin-sam">...
>
> while the first line should be
>
>    <label for="dateb">Departure</label>
>
> But DateField doesn't give me access to the markupid of it's nested
> DateTextField.
>
> Any ideas how to solve this elegantly ?
>
> Maarten
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to