Hi, Igor:

>nstead of throwing the exception call error(message) on the page and
return an empty list from the model

So I register a error to the page in the model but the feedback message
doesn't show.  Here is a small sample to demonstrate:

HomePage.html:

<html>
<head></head>
    <span wicket:id="message">message will be here</span>
    <form wicket:id="form">
        <input type="text" wicket:id="word"/>
        <input type="submit" value="Enter" wicket:id="submitButton"/>
    </form>
    <span wicket:id="feedback">FEEDBACK</span>
</html>


HomePage.java

import org.apache.wicket.PageParameters;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxFallbackButton;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

public class HomePage extends WebPage {

    private static final long serialVersionUID = 1L;

    private String word;

    public HomePage(final PageParameters parameters) {

        add(new
FeedbackPanel("feedback").setOutputMarkupPlaceholderTag(true));
        // if the word 'blowup' is entered, this register a error message to
the page
        IModel model = new Model() {
            private static final long serialVersionUID = 1L;
            @Override public Object getObject() {
                if (word != null && word.equals("blowup")) {
                    word = "-b-l-o-w-u-p-";
                    HomePage.this.fatal("This message is from model.");
                    return "BAD THING HAPPENED IN MODEL";
                } else {
                    return "The word is: \"" + (word == null ? " n u l l " :
word) + "\"";
                }
            }
        };
        add(new Label("message", model).setOutputMarkupId(true));
        Form form = new Form("form", new CompoundPropertyModel(this));
        add(form);
        form.add(new TextField("word").setRequired(true));
        AjaxFallbackButton submitButton = new
AjaxFallbackButton("submitButton", form) {
            private static final long serialVersionUID = 1L;
            @Override protected void onSubmit(AjaxRequestTarget target, Form
f) {
                if (word != null && word.equals("blowup")) {
                    HomePage.this.error("This message is from onSubmit.
There should also be a message from model");
                }
                if (target != null) {
                    target.addComponent(HomePage.this.get("feedback"));
    // clear error feedback if any
                    target.addComponent(HomePage.this.get("message"));
                }
            }

            @Override protected void onError(AjaxRequestTarget target, Form
f) {
                target.addComponent(HomePage.this.get("feedback"));
// show updated error feedback
            }
        };
        form.add(submitButton);
    }
}



Enter the word 'blowup' and the Model registers a error message to the page,
this message doesn't show.


On Tue, Mar 18, 2008 at 12:19 PM, Igor Vaynberg <[EMAIL PROTECTED]>
wrote:

> On Tue, Mar 18, 2008 at 11:48 AM, Matthew Young <[EMAIL PROTECTED]> wrote:
> >  Do you mean this:
> >
> >         WebMarkupContainer img = new WebMarkupContainer("thumbnail") {
> >             private static final long serialVersionUID = 1L;
> >             @Override protected void onComponentTag(final ComponentTag
> tag){
> >                 super.onComponentTag(tag);
> >                 tag.put("src", thumbnailUrl);
> >             }
> >         };
>
> yep
>
> >  2) When something goes wrong in Flickr, I throw a RuntimeException
> which
> >  blows up in ListView's model.getObject().  I want to Ajax update the
> >  feedbackPanel to show some error message. How can this be done?
>
> instead of throwing the exception call error(message) on the page and
> return an empty list from the model
>
> -igor
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to