Fórum

Portlets won't be shown

Marc Weisenburger, modificado 8 Anos atrás.

Portlets won't be shown

New Member Postagens: 5 Data de Entrada: 07/04/15 Postagens Recentes
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:
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
thumbnail
Vernon Singleton, modificado 8 Anos atrás.

RE: Portlets won't be shown

Expert Postagens: 315 Data de Entrada: 14/01/13 Postagens Recentes
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:
// 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, modificado 8 Anos atrás.

RE: Portlets won't be shown

New Member Postagens: 5 Data de Entrada: 07/04/15 Postagens Recentes
Thank you,

I will try this way and will give your my Response!
thumbnail
Juan Gonzalez, modificado 8 Anos atrás.

RE: Portlets won't be shown

Liferay Legend Postagens: 3089 Data de Entrada: 28/10/08 Postagens Recentes
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.
Marc Weisenburger, modificado 8 Anos atrás.

RE: Portlets won't be shown

New Member Postagens: 5 Data de Entrada: 07/04/15 Postagens Recentes
My Managed Bean:

@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 &lt; 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>
thumbnail
Juan Gonzalez, modificado 8 Anos atrás.

RE: Portlets won't be shown

Liferay Legend Postagens: 3089 Data de Entrada: 28/10/08 Postagens Recentes
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:

 public PieChartModel getPieModel() {
      return   createPieModel();
 }