EL expression is not being evaluated

UI Components for JSF
Post Reply
janiemort
Posts: 5
Joined: 25 Jul 2013, 20:52

22 Jul 2016, 22:35

I'm using Primefaces 6.0, running on WebLogic Server 12.2.1 with Mojarra 2.2.13 and Java 1.8.0_72.

I have a JSF page that is working and I am now adding a menu in the index.xhmtl to call the working JSF page.

My index.xhtml includes another xhtml file (header.xhtml). Both index.xhtml and header.xhtml have EL expressions in them and both share the same managed bean (MenuView). When I run it, the MainView backing bean is never being instantiated.

Following is the index.xhtml:

Code: Select all

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">


<h:head>
	<title>Provisioner</title>
</h:head>

<h:body>

	<ui:include src="/header.xhtml" />

	<h:form>
		<p:panelMenu style="width:800px">
			<p:submenu label="Application Configuration">
				<p:menuitem value="Configure WebLogic Domain" url="#" disabled="#{!menuView.isMWAdmin}" />
			</p:submenu>
			<p:submenu label="Internal Data Management">
				<p:menuitem value="Domain Types" outcome="/domainTypeList.xhtml" />
			</p:submenu>
		</p:panelMenu>
	</h:form>

</h:body>
</html>

The header.xhtml:

Code: Select all

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

	<p:panel>
		<p:panelGrid columns="2" styleClass="ui-noborder">
			<h:graphicImage value="/resources/images/usfoodsLogo.png"></h:graphicImage>
			<h1>US Foods Middleware Software Provisioner</h1>
		</p:panelGrid>
		<p:panel>
			<p:panelGrid columns="2" styleClass="ui-noborder" >
				<f:facet name="header">
					<h:outputLabel value="Logged in as: " />
					<h:outputText value="#{menuView.currentUser}" />
				</f:facet>
			</p:panelGrid>
			<p:panelGrid columns="2" styleClass="ui-noborder" >
				<f:facet name="header">
					<h:outputLabel value="Current Environment: " />
					<h:outputText value="#{menuView.currentEnv}" />
				</f:facet>
			</p:panelGrid>
		</p:panel>
	</p:panel>

</ui:composition>

The backing bean code:

Code: Select all

package com.usf.provisioner.view;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

import com.usf.provisioner.util.ApplicationProperties;

@ManagedBean
public class MenuView implements Serializable {
	
	private static final long serialVersionUID = -1391369095648565176L;
	private String currentUser;
	private boolean isMWAdmin;
	private boolean isUSFProvisionerAdmin;
	private String currentEnv;
			
	public MenuView() {
		super();
		
		HttpServletRequest req = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
		currentUser = req.getUserPrincipal().getName();
		
		isMWAdmin = req.isUserInRole("MWAdmin");
		isUSFProvisionerAdmin = req.isUserInRole("USFProvisionerAdmin");
		
		currentEnv = ApplicationProperties.envProperties.getProperty("env-name");
	}
		

	public String getCurrentUser() {
		return currentUser;
	}

	public void setCurrentUser(String currentUser) {
		this.currentUser = currentUser;
	}

	public boolean isMWAdmin() {
		return isMWAdmin;
	}

	public void setMWAdmin(boolean isMWAdmin) {
		this.isMWAdmin = isMWAdmin;
	}

	public boolean isUSFProvisionerAdmin() {
		return isUSFProvisionerAdmin;
	}

	public void setUSFProvisionerAdmin(boolean isUSFProvisionerAdmin) {
		this.isUSFProvisionerAdmin = isUSFProvisionerAdmin;
	}


	public String getCurrentEnv() {
		return currentEnv;
	}


	public void setCurrentEnv(String currentEnv) {
		this.currentEnv = currentEnv;
	}
	
	

}

I left the security measure off of the Domain Types menu item so that I could test that feature and it still works.

A little more background information: This used to work with Primefaces 5.2, WebLogic Server 12.1.3, Mojarra 2.2.0 and Java 1.8.0_61.

I have searched this forum and others, but have not found a solution. Any help is appreciated.

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

26 Jul 2016, 21:01

Hmmm, the constructor calls super(), but the bean implements Serializable. Is it possible that your constructor is failing because of the call to super()? MenuView class is a descendant of what class?

Code: Select all

@ManagedBean
public class MenuView implements Serializable {
   
   ...

   public MenuView() {
      super();
      
   ...

   }
Also, it may be best for you to use @PostConstruct method instead of Java bean Constructor event when using managed beans.

Hmmm, 'menuView' referenced in f:facet, below.

Code: Select all

            <f:facet name="header">
               <h:outputLabel value="Logged in as: " />
               <h:outputText value="#{menuView.currentUser}" />
            </f:facet>

Code: Select all

            <f:facet name="header">
               <h:outputLabel value="Current Environment: " />
               <h:outputText value="#{menuView.currentEnv}" />
            </f:facet>
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

janiemort
Posts: 5
Joined: 25 Jul 2013, 20:52

16 Aug 2016, 00:25

Thanks for the response. Sorry for delay, I was on vacation.

I removed the constructor and used @PostConstruct on init() method.

I still have the same problem. None of the EL expressions are being evaluated.

Is there any type of debug that can be enabled to troubleshoot this?

I tried setting breakpoints, but the execution does not stop on them.

User avatar
andyba
Expert Member
Posts: 2473
Joined: 31 Mar 2011, 16:27
Location: Steinfeld, near Bremen/Osnabrück, DE
Contact:

16 Aug 2016, 14:00

You need to scope the bean, try @ViewScoped to start with.

Don't use @ManagedBeans when you can use CDI, change @ManagedBean to @Named and keep the scope.
PF 4.x (Elite versions), PF 5, Pf 5.1, PF 6.0
Glassfish 4.1, Mojarra 2.x, Java 8, Payara 4.1.1.
If you haven't read the forum rules read them now

smokeybandit
Posts: 277
Joined: 08 Jul 2013, 17:53

16 Aug 2016, 14:05

andyba wrote:You need to scope the bean, try @ViewScoped to start with.

Don't use @ManagedBeans when you can use CDI, change @ManagedBean to @Named and keep the scope.
He does have it scoped. @ManagedBean defaults to RequestScoped

smokeybandit
Posts: 277
Joined: 08 Jul 2013, 17:53

16 Aug 2016, 14:16

What does "not being evaluated" mean? Is it possible the values are just all null?

janiemort
Posts: 5
Joined: 25 Jul 2013, 20:52

17 Aug 2016, 21:10

I actually had added @ViewScoped a while back.

I tried changing to @Named, but get the same result.

By not being evaluated, I mean that the getCurrentUser and getCurrentEnv methods on the MenuView class are never called. In fact, the init() is never called.

Here is the latest version of the MenuView class:

Code: Select all

package com.usf.provisioner.view;

import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

import com.usf.provisioner.util.ApplicationProperties;

@ManagedBean
@ViewScoped
public class MenuView implements Serializable {
	
	private static final long serialVersionUID = -1391369095648565176L;
	private String currentUser;
	private boolean isMWAdmin;
	private boolean isUSFProvisionerAdmin;
	private String currentEnv;
	private Logger logger = Logger.getLogger("com.usf.provisioner.view.MenuView");

			
	@PostConstruct
	public void init()
	{
		
		HttpServletRequest req = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
		currentUser = req.getUserPrincipal().getName();
		
		isMWAdmin = req.isUserInRole("MWAdmin");
		isUSFProvisionerAdmin = req.isUserInRole("USFProvisionerAdmin");
		
		currentEnv = ApplicationProperties.envProperties.getProperty("env-name");
		
		logger.log(Level.INFO, "Current user is " + currentUser);
		
	}
		

	public String getCurrentUser() {
		return currentUser;
	}

	public void setCurrentUser(String currentUser) {
		this.currentUser = currentUser;
	}

	public boolean isMWAdmin() {
		return isMWAdmin;
	}

	public void setMWAdmin(boolean isMWAdmin) {
		this.isMWAdmin = isMWAdmin;
	}

	public boolean isUSFProvisionerAdmin() {
		return isUSFProvisionerAdmin;
	}

	public void setUSFProvisionerAdmin(boolean isUSFProvisionerAdmin) {
		this.isUSFProvisionerAdmin = isUSFProvisionerAdmin;
	}


	public String getCurrentEnv() {
		return currentEnv;
	}


	public void setCurrentEnv(String currentEnv) {
		this.currentEnv = currentEnv;
	}
	
	

}

And here is the latest index.xhtml and header.xhtml. NOTE: I left the security off of the Internal Data Management-->Domain Types option so I can click it and it works fine other than the header which contains the current user and current environment attributes.

Code: Select all

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">


<h:head>
	<title>US Foods Middleware Software Provisioner</title>
</h:head>

<h:body>

	<ui:include src="/header.xhtml" />

	<h:form>
		<p:panelMenu style="width:800px">
			<p:submenu label="Application Configuration">
				<p:menuitem value="Configure WebLogic Domain" url="#" disabled="#{!menuView.isMWAdmin}" />
			</p:submenu>
			<p:submenu label="Internal Data Management">
				<p:menuitem value="Domain Types" outcome="/domainTypeList.xhtml" />
			</p:submenu>
		</p:panelMenu>
	</h:form>

</h:body>
</html>

header.xhtml

Code: Select all

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

	<p:panel>
		<p:panelGrid columns="2" styleClass="ui-noborder">
			<h:graphicImage value="/resources/images/usfoodsLogo.png"></h:graphicImage>
			<h1>US Foods Middleware Software Provisioner</h1>
		</p:panelGrid>
		<p:panel>
			<p:panelGrid columns="2" styleClass="ui-noborder" >
				<f:facet name="header">
					<h:outputLabel value="Logged in as: " />
					<h:outputText value="#{menuView.currentUser}" />
				</f:facet>
			</p:panelGrid>
			<p:panelGrid columns="2" styleClass="ui-noborder" >
				<f:facet name="header">
					<h:outputLabel value="Current Environment: " />
					<h:outputText value="#{menuView.currentEnv}" />
				</f:facet>
			</p:panelGrid>
		</p:panel>
	</p:panel>

</ui:composition>

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 58 guests