You could turn things around and do the validation manually. Like:

final TextField titleField = new RequiredTextField("title", new
PropertyModel(model, "title"));
form.add(new TextField("url", new PropertyModel(model, "url")));
form.add(titleField);
form.add(new Button("fetchUrl") {
   @Override
   protected void onSubmit() {
        if (model.getTitle() == null) {
            titleField.error(Arrays.asList(new String[]{"your.message.key"}));
            // or simply titleField.error("title is required"); or
something similar
            return;
        }
        buildForm(model.getUrl());
    }
}

Or consider using IFormValidator and see if that is a better fit.

Eelco



On 6/1/06, Gianugo Rabellino <[EMAIL PROTECTED]> wrote:
> Might be a wicked use case, but I can't find an elegant way of making
> it work. My app has a form where users add  a web link together with
> some metadata. I'd like to present the user with a button so that,
> once the web link field is filled in, pressing the button fetches the
> page and tries to pre-fill the form with data such as title,
> language, author and so on. I thought something like this would have
> worked:
>
>         form.add(new TextField("url", new PropertyModel(model, "url")));
>         form.add(new RequiredTextField("title", new PropertyModel
> (model, "title")));
>
>         form.add(new Button("fetchUrl") {
>              @Override
>              protected void onSubmit() {
>                  buildForm(model.getUrl());
>              }
>          }.setDefaultFormProcessing(false);
>         [ ... more fields follow ... ]
>
> This failed miserably: the title field is required, so the form
> doesn't validate and the model doesn't contain a thing. My first
> attempt, then, has been grabbing the raw input:
>
>         form.add(new Button("fetchUrl") {
>              @Override
>              protected void onSubmit() {
>                  buildForm(((FormComponent) getParent().get("url"))
>                          .getRawInput());
>              }
>          }.setDefaultFormProcessing(false);
>
> This worked, and I was able to proceed to my buildForm method, which
> does his HttpClient homework just fine and populates the model object
> accordingly.
>
> Unfortunately, I wasn't done at all: my model was correctly
> populated, but, and here is what I don't understand, my form fields
> were blank (mind you, a info(model.getTitle()) was showing the right
> information in the feedbackPanel). After trying a combination of
> render(), renderComponent() and friends, I found the modelChanged()
> event and thought I'd fire it on the form, but that wasn't quite
> enough. In the end I had to walk the form fields one by one to notify
> them about the model being changed:
>
>          Iterator components = form.iterator();
>          while (components.hasNext()) {
>              Component element = (Component) components.next();
>              element.modelChanged();
>
>          }
>
> Now, while I do have a working solution/hack, I don't quite like the
> way I've got there. Have I been missing something obvious? Is there a
> better way to perform partial form processing on Wicket?
>
> Thanks for your support,
>
> --
> Gianugo Rabellino
>
>
> -------------------------------------------------------
> All the advantages of Linux Managed Hosting--Without the Cost and Risk!
> Fully trained technicians. The highest number of Red Hat certifications in
> the hosting industry. Fanatical Support. Click to learn more
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
> _______________________________________________
> Wicket-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>


_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to