in a real app people will be invested in fixing the issue and not
having someone else do their homework for them :)
like i said, right now we consider errors in models unrecoverable - eg
you go to an error page. seemed to satisfy everyone for 3? years that
wicket has been out.
that said, you can get a little creative and come up with something.
stuff below should work with regular requests, havent tested it with
ajax yet.
-igor
public abstract static class ErrorAwareModelAdapter
implements
IModel,
IComponentAssignedModel,
IWrapModel
{
private boolean error = false;
private final IModel delegate;
private Component component;
public ErrorAwareModelAdapter(IModel delegate)
{
this.delegate = delegate;
}
/** gets value that should be returned from
getobject() if exception is thrown */
protected Object getErrorResult()
{
return null;
}
/** handles the error - such as
component.getsession().error(e.getmessage()); */
protected void handleError(RuntimeException e)
{
}
@Override
public Object getObject()
{
if (error)
{
error = false;
return getErrorResult();
}
else
{
try
{
return delegate.getObject();
}
catch (RuntimeException e)
{
error = true;
handleError(e);
component.getPage().detach();
throw new
AbstractRestartResponseException()
{
};
}
}
}
@Override
public void setObject(Object object)
{
delegate.setObject(object);
}
@Override
public void detach()
{
delegate.detach();
}
@Override
public IWrapModel wrapOnAssignment(Component component)
{
this.component = component;
return this;
}
@Override
public IModel getWrappedModel()
{
return delegate;
}
}
On Thu, Mar 20, 2008 at 2:48 PM, Matthew Young <[EMAIL PROTECTED]> wrote:
> Then what? In real app, the model is calling some flakey remote service that
> can fail. Is there no way to show error message on the same page? That the
> only thing is put up a different error page?
>
>
>
> On Thu, Mar 20, 2008 at 1:29 PM, Matej Knopp <[EMAIL PROTECTED]> wrote:
>
> > This doesn't work because the model.getObject method is only called
> > when the value is pulled out of the model, which is on label render.
> > Even if you refresh it on ajax request, it might be too late because
> > the feedback panel retrieves the feedback messages in onBeforeRender
> > (before actual rendering).
> >
> > -Matej
> >
> > On Wed, Mar 19, 2008 at 10:04 PM, Matthew Young <[EMAIL PROTECTED]> wrote:
> > > I register an error to the page in the model but the feedback message
> > > doesn't show in FeedbackPanel. Only the error message register in
> > > onSubmit() event handler shows. Please have a look. Thanks!
> > >
> > > 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 ...
> > >
> > > 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 model 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"));
> > > 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);
> > > }
> > > }
> > >
> >
> >
> >
> > --
> > Resizable and reorderable grid components.
> > http://www.inmethod.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]