Foren
Portlets won't be shown
Marc Weisenburger, geändert vor 9 Jahren.
Portlets won't be shown
New Member Beiträge: 5 Beitrittsdatum: 07.04.15 Neueste Beiträge
Hello
I'm developing some Portlets with JSF Primefaces.
But sometimes the Portlets wont be shown and there is only empty space.
This happens just sometimes, without any reproducible reasons.
Any Idea for this Issue?
Following Log:
For Those Reasons, are there any Error-Handling methods?
If my Portlet will throw an exception, I just wan't to show a self-defined Error-Message or something.
Thanks
I'm developing some Portlets with JSF Primefaces.
But sometimes the Portlets wont be shown and there is only empty space.
This happens just sometimes, without any reproducible reasons.
Any Idea for this Issue?
Following Log:
20:32:18,246 ERROR [RuntimePageImpl-4][render_portlet_jsp:132] null
java.lang.NullPointerException
at org.primefaces.component.chart.renderer.PieRenderer.encodeData(PieRenderer.java:34)
at org.primefaces.component.chart.renderer.BasePlotRenderer.render(BasePlotRenderer.java:29)
at org.primefaces.component.chart.ChartRenderer.encodeScript(ChartRenderer.java:98)
at org.primefaces.component.chart.ChartRenderer.encodeEnd(ChartRenderer.java:67)
For Those Reasons, are there any Error-Handling methods?
If my Portlet will throw an exception, I just wan't to show a self-defined Error-Message or something.
Thanks
Vernon Singleton, geändert vor 9 Jahren.
RE: Portlets won't be shown
Expert Beiträge: 315 Beitrittsdatum: 14.01.13 Neueste Beiträge
Hi Marc,
As far as the error you posted, it appears to be occurring during some method chaining on this line here, which might not be easy to surround with a try catch since it is inside the PrimeFaces renderer.
So, it appears that you want to be able to customize what happens when you get an unexpected exception. For this, you can implement a custom exception handler which decorates the one provided by your JSF implementation. You can declare an ExceptionHandlerFactory in the faces config for your portlet "to show a self-defined Error-Message", as you say, and you can also extend ExceptionHandlerWrapper as follows:
Here is a nice answer from BalusC showing what you might try when you handle an ajax exception "to show a self-defined Error-Message".
PrimeFaces also provides an ajaxExceptionHandler component which may or may not be helpful. It would be quite difficult to test all combinations of component libraries and exception handlers on the Liferay portal, so other people on this forum would benefit if you are able to post the results of your findings when using any custom exception handlers with Liferay.
Hope that helps,
Vernon
As far as the error you posted, it appears to be occurring during some method chaining on this line here, which might not be easy to surround with a try catch since it is inside the PrimeFaces renderer.
So, it appears that you want to be able to customize what happens when you get an unexpected exception. For this, you can implement a custom exception handler which decorates the one provided by your JSF implementation. You can declare an ExceptionHandlerFactory in the faces config for your portlet "to show a self-defined Error-Message", as you say, and you can also extend ExceptionHandlerWrapper as follows:
// MyExceptionHandlerFactory.java
import javax.faces.context.ExceptionHandler;
import javax.faces.context.ExceptionHandlerFactory;
public class MyExceptionHandlerFactory extends ExceptionHandlerFactory {
private ExceptionHandlerFactory wrappedExceptionHandlerFactory;
public MyExceptionHandlerFactory(ExceptionHandlerFactory exceptionHandlerFactory) {
this.wrappedExceptionHandlerFactory = exceptionHandlerFactory;
}
@Override
public ExceptionHandler getExceptionHandler() {
ExceptionHandler exceptionHandler = wrappedExceptionHandlerFactory.getExceptionHandler();
exceptionHandler = new MyExceptionHandler(exceptionHandler);
return exceptionHandler;
}
}
// MyExceptionHandler.java
import javax.faces.context.ExceptionHandler;
import javax.faces.context.ExceptionHandlerWrapper;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.SystemEvent;
public class MyExceptionHandler extends ExceptionHandlerWrapper {
private ExceptionHandler wrappedExceptionHandler;
public MyExceptionHandler(ExceptionHandler exceptionHandler) {
this.wrappedExceptionHandler = exceptionHandler;
}
@Override
public void handle() throws FacesException {
// your code goes here
wrappedExceptionHandler.handle();
}
@Override
public ExceptionHandler getWrapped() {
return wrappedExceptionHandler;
}
}
Here is a nice answer from BalusC showing what you might try when you handle an ajax exception "to show a self-defined Error-Message".
PrimeFaces also provides an ajaxExceptionHandler component which may or may not be helpful. It would be quite difficult to test all combinations of component libraries and exception handlers on the Liferay portal, so other people on this forum would benefit if you are able to post the results of your findings when using any custom exception handlers with Liferay.
Hope that helps,
Vernon
Marc Weisenburger, geändert vor 9 Jahren.
RE: Portlets won't be shown
New Member Beiträge: 5 Beitrittsdatum: 07.04.15 Neueste Beiträge
Thank you,
I will try this way and will give your my Response!
I will try this way and will give your my Response!
Juan Gonzalez, geändert vor 9 Jahren.
RE: Portlets won't be shown
Liferay Legend Beiträge: 3089 Beitrittsdatum: 28.10.08 Neueste Beiträge
Hi Marc,
the good approach usually is to find out which things are wrong first, instead of "capturing" all the errors withouth knowing why are they being thrown.
Can you post some snippets of your portlet? In this case it would be good to see your managed bean method where the pie model is created, and the XHTML part too.
the good approach usually is to find out which things are wrong first, instead of "capturing" all the errors withouth knowing why are they being thrown.
Can you post some snippets of your portlet? In this case it would be good to see your managed bean method where the pie model is created, and the XHTML part too.
Marc Weisenburger, geändert vor 9 Jahren.
RE: Portlets won't be shown
New Member Beiträge: 5 Beitrittsdatum: 07.04.15 Neueste Beiträge
My Managed Bean:
my Portlet looks like:
@SessionScoped
@ManagedBean
public class OpenClosedViewBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = -6393291273408020985L;
private PieChartModel pieModel;
private String projektId;
public String getProjektId() {
return projektId;
}
public void setProjektId(String projektId) {
this.projektId = projektId;
}
private String studenthskaId;
public String getStudenthskaId() {
return studenthskaId;
}
public void setStudenthskaId(String studenthskaId) {
System.out.println("setter" + studenthskaId);
this.studenthskaId = studenthskaId;
}
public PieChartModel getPieModel() {
createPieModel();
return pieModel;
}
public void setPieModel(PieChartModel pieModel) {
this.pieModel = pieModel;
}
private List<field> getAllFieldsForProjekt() {
System.out.println("get all fields");
String thisProjectID = ProjectLocalServiceUtil
.getProjectIdForProjectName(projektId);
List<issue> allIssues = IssueLocalServiceUtil
.getAllIssuesForProjectId(thisProjectID);
List<field> allFields = FieldLocalServiceUtil
.getAllFieldsForIsses(allIssues);
System.out.println("recived all fields");
return allFields;
}
private void createPieModel() {
System.out.println("create PieModel");
System.out.println("studentId: " + studenthskaId);
List<field> allFields = null;
if(projektId != null){
allFields = FieldLocalServiceUtil.getAllFieldsforProject(projektId);
} else {
allFields = FieldLocalServiceUtil.getAllFieldsForAssignee(studenthskaId);
}
pieModel = new PieChartModel();
pieModel.setLegendPosition("w");
pieModel.setTitle("Issues from Team");
pieModel.setDataFormat("value");
pieModel.setShowDataLabels(true);
int open = 0;
int closed = 0;
for (int i = 0; i < allFields.size(); i++) {
if (allFields.get(i).getStatusId() == 1) {
open += 1;
} else if (allFields.get(i).getStatusId() == 6) {
closed += 1;
}
}
pieModel.set("Open: " + open, open);
System.out.println("OPEN " + open);
pieModel.set("Closed " + closed, closed);
System.out.println("Closed " + closed);
}
}
</field></field></issue></field>
my Portlet looks like:
<!--?xml version="1.0"?-->
<f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui" xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head />
<h:body>
<p:chart type="pie" model="#{openClosedViewBean.pieModel}" responsive="true" />
</h:body>
</f:view>
Juan Gonzalez, geändert vor 9 Jahren.
RE: Portlets won't be shown
Liferay Legend Beiträge: 3089 Beitrittsdatum: 28.10.08 Neueste Beiträge
Hi Marc,
I see you're using a @SessionScoped bean for tasks that @RequestScoped seems more appropiate. In order to "simulate" that, just change your private createPieModel so it returns a PieModel, and then return that value instead of the ManagedBean pieModel:
I see you're using a @SessionScoped bean for tasks that @RequestScoped seems more appropiate. In order to "simulate" that, just change your private createPieModel so it returns a PieModel, and then return that value instead of the ManagedBean pieModel:
public PieChartModel getPieModel() {
return createPieModel();
}