Foros de discusión
@PostConstruct not being called on Tomcat 7
Eric COQUELIN, modificado hace 9 años.
@PostConstruct not being called on Tomcat 7
Expert Mensajes: 254 Fecha de incorporación: 3/11/13 Mensajes recientes
Hi,
I'm new on Liferay and have decided to go with Liferay 6.2 GA2 + Tomcat 7 + JSF 2
I created my first portlet project and try to perform simple JSF operations. So far, it fails: @PostConstruct is not called. I'm sure of that because logs are being displayed for the constructor not for the @PostConstruct method.
In my XHTML file, I've got:
Then, my bean is as follows:
Dependencies in my pom are the followings:
I had a look at https://www.liferay.com/fr/community/wiki/-/wiki/Main/Upgrading+Mojarra+in+Apache+Tomcat and tried to follow the procedure but it did not give any result. I reverted back to include jsf-api and impl in the war itself (as you can notice in the maven file)
I saw that issue as well https://issues.liferay.com/browse/LPS-34863 but it is related to JBoss and not Tomcat. Note that I downloaded the bundled version of Liferay with Tomcat.
In the logs, I can see regularely this kind of message:
19:06:34,289 DEBUG [ExtELResolver:71] Unable to resolve variable [organizationBean] value=null
I hope someone can help me in this forum.
I'm new on Liferay and have decided to go with Liferay 6.2 GA2 + Tomcat 7 + JSF 2
I created my first portlet project and try to perform simple JSF operations. So far, it fails: @PostConstruct is not called. I'm sure of that because logs are being displayed for the constructor not for the @PostConstruct method.
In my XHTML file, I've got:
<ui:repeat value="#{organizationBean.organizations}" var="org">
<li>
<div class="media">
<a class="pull-left" href="#">
<img class="media-object" src="#{request.contextPath}/images/sample_man.jpg">
</a>
<div class="media-body">
<h4 class="media-heading">#{org}</h4>
<div class="media">
Directeur Marketing
</div>
</div>
</div>
</li>
</ui:repeat>
Then, my bean is as follows:
@ViewScoped
@ManagedBean(name="organizationBean")
public class OrganizationBean {
private static final Log logger = LogFactoryUtil.getLog(OrganizationBean.class);
private String name;
private List<organization> organizations;
public OrganizationBean() {
logger.debug("init OrganizationBean...");
this.name="Eric 127";
}
@PostConstruct
public void init() throws PortalException, SystemException {
LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
User currentUser = liferayFacesContext.getUser();
organizations = OrganizationLocalServiceUtil.getOrganizations(currentUser.getUserId(), 0, 100, null);
if (organizations != null || !organizations.isEmpty()) {
logger.debug("found " + organizations.size() + " organizations");
} else {
logger.debug("no organization found for " + currentUser.getFullName());
}
}
public void create() throws PortalException, SystemException {
LiferayFacesContext liferayFacesContext = LiferayFacesContext.getInstance();
User currentUser = liferayFacesContext.getUser();
logger.debug("adding organization " + name + " from " + currentUser.getFullName());
Organization org = OrganizationLocalServiceUtil.addOrganization(currentUser.getUserId(), OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID, name, false);
logger.debug("new organization created: " + org.getOrganizationId());
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the organizations
*/
public List<organization> getOrganizations() {
return organizations;
}
/**
* @param organizations the organizations to set
*/
public void setOrganizations(List<organization> organizations) {
this.organizations = organizations;
}
}</organization></organization></organization>
Dependencies in my pom are the followings:
<dependencies>
<dependency>
<groupid>commons-fileupload</groupid>
<artifactid>commons-fileupload</artifactid>
<version>1.2.2</version>
</dependency>
<dependency>
<groupid>commons-io</groupid>
<artifactid>commons-io</artifactid>
<version>1.3.2</version>
</dependency>
<dependency>
<groupid>com.liferay.faces</groupid>
<artifactid>liferay-faces-alloy</artifactid>
<version>3.2.4-ga5</version>
</dependency>
<dependency>
<groupid>com.liferay.faces</groupid>
<artifactid>liferay-faces-bridge-impl</artifactid>
<version>3.2.4-ga5</version>
</dependency>
<dependency>
<groupid>com.liferay.faces</groupid>
<artifactid>liferay-faces-portal</artifactid>
<version>3.2.4-ga5</version>
</dependency>
<dependency>
<groupid>com.liferay.portal</groupid>
<artifactid>portal-service</artifactid>
<version>6.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupid>com.liferay.portal</groupid>
<artifactid>util-java</artifactid>
<version>6.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupid>com.sun.faces</groupid>
<artifactid>jsf-api</artifactid>
<version>2.1.21</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupid>com.sun.faces</groupid>
<artifactid>jsf-impl</artifactid>
<version>2.1.21-m</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupid>javax.el</groupid>
<artifactid>el-api</artifactid>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupid>javax.annotation</groupid>
<artifactid>jsr250-api</artifactid>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupid>javax.portlet</groupid>
<artifactid>portlet-api</artifactid>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupid>org.jboss.seam</groupid>
<artifactid>jboss-el</artifactid>
<version>2.0.0.GA</version>
<exclusions>
<exclusion>
<artifactid>el-api</artifactid>
<groupid>javax.el</groupid>
</exclusion>
</exclusions>
</dependency>
</dependencies>
I had a look at https://www.liferay.com/fr/community/wiki/-/wiki/Main/Upgrading+Mojarra+in+Apache+Tomcat and tried to follow the procedure but it did not give any result. I reverted back to include jsf-api and impl in the war itself (as you can notice in the maven file)
I saw that issue as well https://issues.liferay.com/browse/LPS-34863 but it is related to JBoss and not Tomcat. Note that I downloaded the bundled version of Liferay with Tomcat.
In the logs, I can see regularely this kind of message:
19:06:34,289 DEBUG [ExtELResolver:71] Unable to resolve variable [organizationBean] value=null
I hope someone can help me in this forum.
Archivos adjuntos:
Eric COQUELIN, modificado hace 9 años.
RE: @PostConstruct not being called on Tomcat 7 (Respuesta)
Expert Mensajes: 254 Fecha de incorporación: 3/11/13 Mensajes recientes
To all,
I found out what I did wrong.
First of all, the @PostConstruct method should never throw any exception. I removed the exception and now, it is being called.
Secondly, the "add" submit button was not in a <h:form> but a single <form>. That's why it didn't call the method.
Now, it seems to work.
Thank you to those who read that post and tried to understand what was wrong ;)
Regards,
I found out what I did wrong.
First of all, the @PostConstruct method should never throw any exception. I removed the exception and now, it is being called.
Secondly, the "add" submit button was not in a <h:form> but a single <form>. That's why it didn't call the method.
Now, it seems to work.
Thank you to those who read that post and tried to understand what was wrong ;)
Regards,
Neil Griffin, modificado hace 9 años.
RE: @PostConstruct not being called on Tomcat 7
Liferay Legend Mensajes: 2655 Fecha de incorporación: 27/07/05 Mensajes recientes
Thanks for reporting back with the good news.