I am doing as follows.

------------------------------------
public class ErrorResponse {

    private int _statusCode;
    private String _message;

    public ErrorResponse(int statusCode, String message) {
        super();
        _statusCode = statusCode;
        _message = message;
    }

    public int getStatusCode() { return _statusCode; }
    public String getMessage() { return _message; }

public static final ErrorResponse NOT_FOUND = new ErrorResponse (404, null);
}
------------------------------------

------------------------------------
public class ErrorResponseResultProcessor implements ComponentEventResultProcessor<ErrorResponse> {

    public ActionResponseGenerator processComponentEvent(
final ErrorResponse errorResponse, Component component, String methodDescripion) {

        return new ActionResponseGenerator() {
public void sendClientResponse(Response response) throws IOException { response.sendError(errorResponse.getStatusCode(), errorResponse.getMessage());
            }
        };
    }
}
------------------------------------

Add contributeComponentEventResultProcessor method to AppModule.java
------------------------------------
public void contributeComponentEventResultProcessor(
MappedConfiguration<Class, ComponentEventResultProcessor> configuration) {

configuration.add(ErrorResponse.class, new ErrorResponseResultProcessor());
}
------------------------------------

Test.java:
------------------------------------
public class Test{
    ErrorResponse onActivate(Object[] parameters) {
        return ErrorResponse.NOT_FOUND;
    }
}
------------------------------------


On 2007/12/25, at 17:50, osamuo wrote:


Hi,

How can I tell T5 to send an 404 error?

Is the following code right way to show 404 error page on T5?
Because I got an error after calling "sendError()" in the code.


Test.java:
------------------------------------
public class Test{
  @Inject
  private Response response;

  void onActivate( Object[] parameters ) throws IOException{
    //if( parameters == null || parameters.length != 2 ){
    response.sendError( 404, null );
    return;
    //}
  }
}
------------------------------------

Error:
------------------------------------
[ERROR] RequestExceptionHandler Processing of request failed with uncaught
exception: STREAM
java.lang.IllegalStateException: STREAM
        at org.mortbay.jetty.Response.getWriter(Response.java:571)
        at
org.apache.tapestry.internal.services.ResponseImpl.getPrintWriter (ResponseImpl.java:47)
        at $Response_1171072b273.getPrintWriter($Response_1171072b273.java)
        at $Response_1171072b240.getPrintWriter($Response_1171072b240.java)
        at
org.apache.tapestry.internal.services.PageResponseRendererImpl.renderP ageResponse(PageResponseRendererImpl.java:58)
        at
$PageResponseRenderer_1171072b261.renderPageResponse ($PageResponseRenderer_1171072b261.java)
        at
org.apache.tapestry.internal.services.PageRenderRequestHandlerImpl.han dle(PageRenderRequestHandlerImpl.java:87)
        at
$PageRenderRequestHandler_1171072b25d.handle ($PageRenderRequestHandler_1171072b25d.java)
        at
org.apache.tapestry.internal.services.PageRenderDispatcher.dispatch (PageRenderDispatcher.java:66)
        at $Dispatcher_1171072b25f.dispatch($Dispatcher_1171072b25f.java)
        at $Dispatcher_1171072b253.dispatch($Dispatcher_1171072b253.java)
        at
org.apache.tapestry.services.TapestryModule$12.service (TapestryModule.java:905)
------------------------------------


--
View this message in context: http://www.nabble.com/T5%3A-404-http- error-tp14493888p14493888.html
Sent from the Tapestry - User mailing list archive at Nabble.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]

Reply via email to