掲示板

Issue with @ManagedBean injection with LIferay 6.2 Faces + Primefaces

7年前 に Tulsi Rai によって更新されました。

Issue with @ManagedBean injection with LIferay 6.2 Faces + Primefaces

New Member 投稿: 18 参加年月日: 13/02/05 最新の投稿
Hello,
We are trying to build a new liferay 6.2 project with JSF/Primefaces frontend technology. I ran into issue with accessing the managed bean from the xhtml. Here's what we are using -
  • liferay-plugins-sdk-6.2
  • liferay-portal-6.2-ce-ga6
  • java 7.*
  • Liferay IDE


The issue is that I don't have access to the managed bean named as "simple" in my view.xhtml as the #{simple.greeting} call would not return any thing and nothing happens while clicking on Submit and Cancel buttons. In fact, the @PostConstruct init() method does not seem to have invoked at all as I don't see the message being printed in the console.

Can someone please give me some idea as to what going on here?
Thank you.
Tulsi

Here are my program files -
SimpleBean.java

package com.lifery.jsf.beans;

import java.awt.event.ActionEvent;

import javax.annotation.ManagedBean;
import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;

@ManagedBean(value="simple")
@ViewScoped
public class SimpleBacking {
	
	private String message;
	private String name;
	 
	
	@PostConstruct
	public void init(){
		System.out.println("Initializing...");
		message = "Welcome to Liferay JSF!";
	}
	
	public String greeting(){		
		return message;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public void processAction(ActionEvent actionEvent){
		System.out.println("Processing with - " + name);
	}

	
	public void cancelAction(ActionEvent actionEvent){
		System.out.println("Cancelling...");
	}

}


view.xhtml


<!--?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>
		<h:outputtext value="#{i18n['liferay-jsf-rnd-hello-world']}" />
		Greeting - <h:outputtext value="#{simple.greeting}" />
		<h:panelgrid>
			<p:calendar></p:calendar>
		</h:panelgrid>
		<h:panelgrid columns="2">
			<h:outputlabel value="Name:" />
			<h:inputtext value="#{simple.name}" />
		</h:panelgrid>
		<h:panelgrid columns="2">
			<p:commandbutton value="Submit" actionListener="#{simple.processAction}" />
			<p:commandbutton value="Cancel" actionListener="#{simple.cancelAction}" />
		</h:panelgrid>
		
	</h:body>
</f:view>


faces-config.xml

<!--?xml version="1.0"?-->

<faces-config version="2.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd">
	<lifecycle>
		<phase-listener>com.liferay.faces.util.lifecycle.DebugPhaseListener</phase-listener>
	</lifecycle>
</faces-config>


liferay-portlet.xml

<!--?xml version="1.0"?-->


<liferay-portlet-app>
	<portlet>
		<portlet-name>liferay-jsf-rnd</portlet-name>
		<icon>/icon.png</icon>
		<requires-namespaced-parameters>false</requires-namespaced-parameters>
		<ajaxable>false</ajaxable>
		<header-portlet-css>/css/main.css</header-portlet-css>
		<css-class-wrapper>liferay-jsf-rnd-portlet</css-class-wrapper>
	</portlet>
	<role-mapper>
		<role-name>administrator</role-name>
		<role-link>Administrator</role-link>
	</role-mapper>
	<role-mapper>
		<role-name>guest</role-name>
		<role-link>Guest</role-link>
	</role-mapper>
	<role-mapper>
		<role-name>power-user</role-name>
		<role-link>Power User</role-link>
	</role-mapper>
	<role-mapper>
		<role-name>user</role-name>
		<role-link>User</role-link>
	</role-mapper>
</liferay-portlet-app>

portlet.xml

<!--?xml version="1.0"?-->

<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd" version="2.0">
	<portlet>
		<portlet-name>liferay-jsf-rnd</portlet-name>
		<display-name>Liferay JSF</display-name>
		<portlet-class>javax.portlet.faces.GenericFacesPortlet</portlet-class>
		<init-param>
			<name>javax.portlet.faces.defaultViewId.view</name>
			<value>/views/view.xhtml</value>
		</init-param>
		<expiration-cache>0</expiration-cache>
		<supports>
			<mime-type>text/html</mime-type>
		</supports>
		<portlet-info>
			<title>Liferay JSF</title>
			<short-title>Liferay JSF</short-title>
			<keywords>Liferay JSF</keywords>
		</portlet-info>
		<security-role-ref>
			<role-name>administrator</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>guest</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>power-user</role-name>
		</security-role-ref>
		<security-role-ref>
			<role-name>user</role-name>
		</security-role-ref>
	</portlet>
</portlet-app>
thumbnail
7年前 に Philip White によって更新されました。

RE: Issue with @ManagedBean injection with LIferay 6.2 Faces + Primefaces

Junior Member 投稿: 76 参加年月日: 15/03/11 最新の投稿
Hello Tulsi,

You should be able to try our primefaces demo from here:
https://web.liferay.com/community/liferay-projects/liferay-faces/demos#primefaces-applicant-portlet

The source code for the demo will show you how to access something in your bean like this:
https://github.com/liferay/liferay-faces-bridge-impl/blob/4.x/demo/primefaces-applicant-portlet/src/main/webapp/WEB-INF/views/applicant.xhtml#L20

you can also use this archetype in order to quickly create a primefaces portlet to start a new JSF project that has the correct jars you will need:
mvn archetype:generate \
  -DarchetypeGroupId=com.liferay.faces.archetype \
  -DarchetypeArtifactId=com.liferay.faces.archetype.primefaces.portlet \
  -DarchetypeVersion=3.0.1 \
  -DgroupId=com.mycompany \
  -DartifactId=com.mycompany.my.primefaces.portlet


For an example of PostConstruct, you can try the export pdf demo.

Let us know if those examples work in your environment. If there are any error messages, please let us know what they are.

Hope that helps!

Phil
7年前 に Tulsi Rai によって更新されました。

RE: Issue with @ManagedBean injection with LIferay 6.2 Faces + Primefaces

New Member 投稿: 18 参加年月日: 13/02/05 最新の投稿
Thanks Philip.

I finally got it working.
I still have one question - since its an Ant based project, the Liferay IDE produces ivy.xml with the older version of jars as shown below, is it possible to override those older version to the current version? How can I do so?

How can I upgrade the primefaces from 3.5 to 6.0?

<dependency name="org.primefaces.primefaces" org="com.liferay" rev="3.5" />


<!--?xml version="1.0"?-->

<ivy-module version="2.0" xmlns:m2="http://ant.apache.org/ivy/maven" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nonamespaceschemalocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
	<info module="portlet_primefaces_tmpl" organisation="com.liferay">
		<extends extendType="configurations,description,info" location="../../ivy.xml" module="com.liferay.sdk" organisation="com.liferay" revision="latest.integration" />
	</info>

	<dependencies defaultconf="default">
		<dependency name="jboss-el" org="org.jboss.el" rev="2.0.1.GA" />
		<dependency name="jsf-api" org="com.sun.faces" rev="2.1.21" />
		<dependency name="jsf-impl" org="com.sun.faces" rev="2.1.21" />
		<dependency name="liferay-faces-bridge-api" org="com.liferay.faces" rev="3.2.4-ga5" />
		<dependency name="liferay-faces-bridge-impl" org="com.liferay.faces" rev="3.2.4-ga5" />
		<dependency name="liferay-faces-portal" org="com.liferay.faces" rev="3.2.4-ga5" />
		<dependency name="liferay-faces-util" org="com.liferay.faces" rev="3.2.4-ga5" />
		<dependency name="org.primefaces.primefaces" org="com.liferay" rev="3.5" />
		<dependency conf="test->default" name="arquillian-junit-container" org="org.jboss.arquillian.junit" rev="1.1.6.Final" />
		<dependency conf="test->default" name="arquillian-tomcat-remote-7" org="org.jboss.arquillian.container" rev="1.0.0.CR6" />
		<dependency conf="test->default" name="com.liferay.ant.arquillian" org="com.liferay" rev="1.0.0-SNAPSHOT" />
	</dependencies>
</ivy-module>


Thank you.
Tulsi
thumbnail
7年前 に Philip White によって更新されました。

RE: Issue with @ManagedBean injection with LIferay 6.2 Faces + Primefaces

Junior Member 投稿: 76 参加年月日: 15/03/11 最新の投稿
Hi again Tulsi,

Thank you for letting us know that you are using Ivy. Unfortunately, our archetypes and version scheme are not released with an ivy.xml. So, what you will need to do is use the archetype portlet at liferayfaces.org or generate a maven archetype using this command:
$ mvn archetype:generate \
  -DarchetypeGroupId=com.liferay.faces.archetype \
  -DarchetypeArtifactId=com.liferay.faces.archetype.primefaces.portlet \
  -DarchetypeVersion=3.0.1 \
  -DgroupId=com.mycompany \
  -DartifactId=com.mycompany.my.primefaces.portlet

The Primefaces 6 jar will be automatically included by that command as well as all of the correct groupIds, artifactIds, and versions (GAVs) for the bridge jars that you need to start using with liferay 6.2. Then, you will need to manually edit your ivy.xml file to use those GAVs from either the pom.xml or the build.gradle files generated by mvn. It looks like you will need these GAVs for what you are trying to do:

dependencies {
    compile group: 'org.primefaces', name: 'primefaces', version:'6.0'
    compile group: 'commons-fileupload', name: 'commons-fileupload', version:'1.3.1'
    compile group: 'commons-io', name: 'commons-io', version:'2.4'
    compile group: 'com.liferay.faces', name: 'com.liferay.faces.bridge.ext', version:'3.0.0'
    compile group: 'com.liferay.faces', name: 'com.liferay.faces.bridge.impl', version:'4.0.0'
    compile group: 'log4j', name: 'log4j', version:'1.2.14'
    runtime group: 'org.glassfish', name: 'javax.faces', version:'2.2.13'
    providedCompile group: 'javax.faces', name: 'javax.faces-api', version:'2.2'
}

Hope that helps!

Phil
7年前 に Tulsi Rai によって更新されました。

RE: Issue with @ManagedBean injection with LIferay 6.2 Faces + Primefaces

New Member 投稿: 18 参加年月日: 13/02/05 最新の投稿
Phil, Thanks for your guidance. I sill have an issue updating the library versions. I started a new thread specially focusing on this particular issue -
https://web.liferay.com/community/forums/-/message_boards/message/85243095

Hope you can guide me.

Thank you.
Tulsi
thumbnail
7年前 に Philip White によって更新されました。

RE: Issue with @ManagedBean injection with LIferay 6.2 Faces + Primefaces

Junior Member 投稿: 76 参加年月日: 15/03/11 最新の投稿
Tulsi,

Thank you for trying our suggestions and telling us step-by-step how you arrived at the current issue that you are having now. You are SO close! All you have to do now is go into your 6.2 version of liferay's webapps directory and remove your older (non-working) deployed portlet (then re-deploy).

to be more clear, you only needed to do the following steps:
cd ${LIFERAY_6.2_HOME}/tomcat/webapps
rm ${old_primefaces_portlet}
cp ${new_primefaces_portlet} ${LIFERAY_6.2_HOME}/deploy/.


Let us know if this solved your issue!

Phil
7年前 に Tulsi Rai によって更新されました。

RE: Issue with @ManagedBean injection with LIferay 6.2 Faces + Primefaces

New Member 投稿: 18 参加年月日: 13/02/05 最新の投稿
First off, THANK YOU Phil for guiding me with so many responses to resolve my issue.
Thank You emoticon

I accomplished my project goal - set up a project based on Liferay 6.2 + Primefaces 6 (the latest version).
Now my ivy looks like this -

<!--?xml version="1.0"?-->

<ivy-module version="2.0" xmlns:m2="http://ant.apache.org/ivy/maven" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nonamespaceschemalocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
	<info module="portlet_primefaces_tmpl" organisation="com.liferay">
		<extends extendType="configurations,description,info" location="../../ivy.xml" module="com.liferay.sdk" organisation="com.liferay" revision="latest.integration" />
	</info>

	<dependencies defaultconf="default">
		<dependency org="log4j" name="log4j" rev="1.2.14" />
		<dependency org="commons-fileupload" name="commons-fileupload" rev="1.3.1" />
		<dependency org="commons-io" name="commons-io" rev="2.4" />
		<dependency org="org.glassfish" name="javax.faces" rev="2.2.13" />
		<dependency org="javax.faces" name="javax.faces-api" rev="2.2" />
		<dependency org="com.liferay.faces" name="com.liferay.faces.bridge.ext" rev="3.0.0" />
		<dependency org="com.liferay.faces" name="com.liferay.faces.bridge.impl" rev="4.0.0" />
		<dependency org="com.liferay.faces" name="com.liferay.faces.bridge.api" rev="4.0.0" />
		<dependency org="org.primefaces" name="primefaces" rev="6.0" />
		<dependency org="com.microsoft.sqlserver" name="sqljdbc4" rev="4.0" /> 		
	</dependencies>
</ivy-module>


With the ivy.xml udpate, and deleting the previously deployed jar, I had one more issue as shown below -

Compiling 2 source files to C:\apps\liferay-plugins-sdk-6.2\portlets\payroll-portlet\docroot\WEB-INF\service-classes
    [javac] Annotation processing got disabled, since it requires a 1.6 compliant JVM
    [javac] ----------
    [javac] 1. ERROR in C:\apps\liferay-plugins-sdk-6.2\portlets\payroll-portlet\docroot\WEB-INF\service\com\agia\payroll\sample\model\Student.java (at line 1)
    [javac] 	/**
    [javac] 	^
    [javac] The type java.util.Map$Entry cannot be resolved. It is indirectly referenced from required .class files
    [javac] ----------
    [javac] ----------
    [javac] 2. ERROR in C:\apps\liferay-plugins-sdk-6.2\portlets\payroll-portlet\docroot\WEB-INF\service\com\agia\payroll\sample\service\StudentLocalServiceClp.java (at line 354)
    [javac] 	ClpSerializer.translateInput(orderByComparator)
    [javac] 	^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    [javac] The type java.util.Comparator cannot be resolved. It is indirectly referenced from required .class files


So I had to have the Jdk 1.6.x and the above issue was resolved!
Then I had the following issue -

Caused by: com.sun.faces.config.ConfigurationException: It appears the JSP version of the container is older than 2.1 and unable to locate the EL RI expression factory, com.sun.el.ExpressionFactoryImpl.  If not using JSP or the EL RI, make sure the context initialization parameter, com.sun.faces.expressionFactory, is properly set.
	at com.sun.faces.config.ConfigureListener.registerELResolverAndListenerWithJsp(ConfigureListener.java:694)
	at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:243)
	... 13 more


So I had to update the web.xml from version 2.5 to version 3.0. I replaced the

<!--?xml version="1.0"?-->

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
	.  .  .
</web-app>


to


<!--?xml version="1.0" encoding="UTF-8"?-->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
     .  .  . 
</web-app>


Now All is good emoticon The liferay portlet project is running with the following -
  • Liferay 6.2
  • JDK 1.6.0_45
  • Primefaces 6.0


Now I have a completetly different issue which I think I should post it in a new thread.
As you know the project is up and running with the default database that Liferay needs. But I would like to configure to use a different database for housing the project specific tables. And as you can guess, I did find a few links but ran into an issue implementing it. So I will post it into a new thread with its own topic. Hope you will find sometime to give me a pointer or two.

Thank you again.
Tulsi