Thanks you both for your suggestions. I will try it tomorrow and come back if i got more questions :-)

Thanks
Per

Am 26.11.2012 16:49, schrieb Stefan Renz:
Hi,

we had a similar requirement, so we did the following:

instead of throwing a AbortWithHttpErrorCodeException, we throw a
semantic exception. In your case, throw MissingSubsiteException( "your
message" ).

How to make Wicket aware of such an exception and implement a proper
reaction/response?

In your application's #init()-Method, add a RequestCycleListener (e.g.
extends org.apache.wicket.request.cycle.AbstractRequestCycleListener)
which implements #onException() to dispatch to a particular error page
depending on the exception passed in. AFAIK, this is regular Wicket
stuff and nothing terribly internal (right?).


We have a bunch of error pages which are regular WebPages with
#isErrorPage() returning true. Those are triggered via the mentioned
RequestCycleListener by means of a
org.apache.wicket.request.handler.PageProvider, which can be used to
initialize the page just as you may need it. For example, by passing the
exception's message, or the exception itself to also display the stack
trace.

Such an error page can also set a status code by using #getResponse() in
#onBeforeRender(), i.e. set a HttpResponseCode.SC_BAD_REQUEST for
missing parameters.

I hope this helps,
bye
     Stefan

Martin Grigorov wrote:
Hi,

See ErrorAttributes.java.
By Servlet spec several request attributes are available when the web
container does error dispatching.


On Mon, Nov 26, 2012 at 3:14 PM, Per Newgro <per.new...@gmx.ch> wrote:

Hi,

i'm looking for a way to display the cause of a 404 send by myself on my
custom error page.

In a behavior i do
<code>
throw new
AbortWithHttpErrorCodeException(HttpServletResponse.SC_NOT_FOUND, "Missing
subsite in behavior");
</code>

It is displayed in my custom error page

<code>
@MountPath("404.html")
public class PageNotFound extends AbstractErrorPage {

         public PageNotFound() {
                 super();
         }

         @Override
         protected void setHeaders(WebResponse response) {
                 response.setStatus(HttpServletResponse.SC_NOT_FOUND);
         super.setHeaders(response);
         }
}
</code>

But i wouuld like to display the cause of the 404 to. If i debug i can see
the cause deep inside the response. But i can't imagine that i have to
rebuild the path to the cause by myself.

Thanks for helping me
Per

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to