Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Vassilis Petropoulos
BridgeContextImpl dispatch
December 21, 2012 7:41 AM
Answer

Vassilis Petropoulos

Rank: Junior Member

Posts: 26

Join Date: April 10, 2012

Recent Posts

Hi,

i need to configure an ExceptionHandler in order to manage runtime exceptions. Especially, i want to display my own messages and not liferay's default message(xPortlet is currently unavailable). For this, i created an error.xhtml page having my own content and try 'render' it like this:

try {
JSFUtils.getExternalContext().dispatch("/error.xhtml");
JSFUtils.getFacesContext().responseComplete();
} catch (IOException e) {}

the problem is that an empty page is rendered. Looking at source code, it seems that there are issues calling BridgeContextImpl.dispatch on liferay.

Is there any other workaround?

regards,
Vassilis
Neil Griffin
RE: BridgeContextImpl dispatch
December 21, 2012 11:41 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2335

Join Date: July 26, 2005

Recent Posts

You should be able to call FacesContext.getCurrentInstance().getExternalContext().redirect("/error.xhtml");

The subsequent call to responseComplete() should not be there though.

If you simply call redirect, then do you see any error messages in the app server log?
Vassilis Petropoulos
RE: BridgeContextImpl dispatch
December 24, 2012 1:48 AM
Answer

Vassilis Petropoulos

Rank: Junior Member

Posts: 26

Join Date: April 10, 2012

Recent Posts

Hi,

thanks for your always quick response!

unfortunately, it did not work as expected. The problem here is that output already produced on page where exception was raised is still present. For example,
consider the following:

x.xhtml
<h:outputText value="mpla mpla" />
<h:outputText value="#{myBean.someMethod}" /> <!--someMethod throws runtime exception-->

error.xhtml
<h:outputText value="an error occured" />

the generated output is 'mpla mpla an error occured' instead of 'an error occured'

regards,
Vassilis
Neil Griffin
RE: BridgeContextImpl dispatch
December 26, 2012 10:12 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2335

Join Date: July 26, 2005

Recent Posts

Some questions for you:

1. Are you using the exception-handler-factory feature in WEB-INF/faces-config.xml to provide your own exception handler, or is this a simple try/catch block in a getter method?

2. Is the exception happening in a model-bean getter method when the portal page is initially rendering during the RENDER_PHASE of the portlet lifecycle, or at some other time like the RESOURCE_PHASE (using f:ajax)?

3. Do you want to redirect to a different portal page URL, or to a different JSF view?

Suggestion:

I haven't tried this, and so I don't know if this would work, but in order to get rid of the "mpla mpla" markup, you could try doing the following before calling redirect(String);

1FacesContext facesContext = FacesContext.getCurrentInstance();
2MimeResponse mimeResponse = (MimeResponse) facesContext.getExternalContext().getResponse();
3mimeResponse.resetBuffer(); // Try this first
4/* mimeResponse.reset(); */ // But if it doesn't work, try this one
Vassilis Petropoulos
RE: BridgeContextImpl dispatch
December 27, 2012 1:57 AM
Answer

Vassilis Petropoulos

Rank: Junior Member

Posts: 26

Join Date: April 10, 2012

Recent Posts

great, it worked!

regarding your questions:
1. Are you using the exception-handler-factory feature in WEB-INF/faces-config.xml to provide your own exception handler, or is this a simple try/catch block in a getter method?
own exception handler

2. Is the exception happening in a model-bean getter method when the portal page is initially rendering during the RENDER_PHASE of the portlet lifecycle, or at some other time like the RESOURCE_PHASE (using f:ajax)?
during the RENDER_PHASE

3. Do you want to redirect to a different portal page URL, or to a different JSF view?
different JSF view

regards,
Vassilis
Neil Griffin
RE: BridgeContextImpl dispatch
December 27, 2012 3:53 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2335

Join Date: July 26, 2005

Recent Posts

That is great news, so glad to hear that it is working. emoticon