i dont think this is a limitation at all

the button that submits the url is immediate right? that means the form processing doesnt happen - and this is the intended behavior.

so the form components hang on to their raw input (the input the browser sent) instead of refreshing it from the model - and this is also intended otherwise if validation failed you would see whatever value was in the model instead of whatever you just typed in when the page refreshed. there is just no way for wicket to do this automatically because it cannot see inside your brain.

for your particular usecase i see a simple and elegant solution:
the form where you enter the url - that can be a separate form that populates a model for another form that contains the rest of the fields...that way i think everything will work smoothly.

also, we have a builtin way to visit components - see form.visitFormComponents which is nicer then the loop you have and will also work its way recursively through the hierarchy so even components burried in panels will be reached.

-Igor



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

Reply via email to