1

I have this code in a .xhtml file:

<h:inputText id="userName" value="#{userEntity.userName}"
             title="${bundle['signup.createuser.username']}"
             maxlength="#{jsfConst.userNameMaxFieldSize}">
</h:inputText>

But the maxlength property is never set when deploying the war file in Embedded Glassfish 4.0. I deploy the very same war file to Glassfish 4.0 installation and it works fine.

I a using this Glassfish dependency in my POM:

<dependency>
    <groupId>org.glassfish.main.extras</groupId>
    <artifactId>glassfish-embedded-all</artifactId>
    <version>4.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.jboss.arquillian.container</groupId>
    <artifactId>arquillian-glassfish-embedded-3.1</artifactId>
    <version>1.0.0.CR3</version>
    <scope>test</scope>
</dependency>

And this is the jsfConst.java file:

@ManagedBean
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class JsfConst {
    public int getEmailFieldSize() {
        return Const.emailFieldSize;
    }

    public int getUserNameMaxFieldSize() {
        return Const.userNameMaxFieldSize;
    }
}

My question is, what am I missing with Embedded Glassfish that makes it fail to enable the EL?

UPDATE:

This is the web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
    <error-page>
        <exception-type>com.sun.faces.context.FacesFileNotFoundException</exception-type>
        <location>/pagenotfound.jsp</location>
    </error-page>
    <error-page>
        <exception-type>javax.faces.application.ViewExpiredException</exception-type>
        <location>/sessionexpired.jsp</location>
    </error-page>
    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>
</web-app>
Joe Almore
  • 4,036
  • 9
  • 52
  • 77
  • That class has a strange mix of annotations. In first place, did you intend it to be an EJB managed bean or a JSF managed bean? (note: both cannot, although your current annotation setup implies this desire) – BalusC Mar 27 '14 at 08:01
  • Hi @BalusC, a JSF managed bean, why? I see, so both should not be used together, I should remove the `@Singleton`. Anyhow, I have tried all combinations of annotations and none of them work in Embedded Glassfish 4. But it seems like a missing dependency or something is causing this, at one time I thought it could be the `Mojarra-2.2.0` it uses. – Joe Almore Mar 27 '14 at 14:59
  • You should be using `@ManagedBean @ApplicationScoped` both from `javax.faces.bean` package. Alternatively, if you have a `/WEB-INF/beans.xml` (and thus, your webapp is CDI enabled), a `@Named @ApplicationScoped` from respectively `javax.injext` and `javax.enterprise.context` packages. No other annotations. – BalusC Mar 27 '14 at 15:01
  • @BalusC, OK, but that still does not enable the EL in Embedded Glassfish 4. Any idea why? – Joe Almore Mar 27 '14 at 15:11
  • Is `value` evaluating? If so, EL is working fine and the problem is in `JsfConst`. If not, what does your web.xml look like? – Peter G Apr 01 '14 at 15:33
  • Hi @PeterG, what do you mean by "Is `value` evaluating?" What `value` do you mean exactly? I really do not think it is the `JsfConst`, it is just a normal `ManagedBean` with constant properties. – Joe Almore Apr 01 '14 at 15:46
  • You mentioned that `maxlength="#{jsfConst.userNameMaxFieldSize}"` is not evaluating, but you didn't say whether `value="#{userEntity.userName}"` evaluates. If another expression evaluates, that proves EL is enabled and working, just not for JsfConst, right? – Peter G Apr 01 '14 at 15:50
  • @PeterG, nope, I also tried `value="#{jsfConst.userNameMaxFieldSize}"` and does not work either. I really have not tried with other `class`; the `#{userEntity.userName}` property couldn't be tested because `maxlength` is always 0, but let me try with another class. – Joe Almore Apr 01 '14 at 15:56
  • @PeterG, yes, you are right, it is not evaluating for `JsfConst`, the other ManagedBeans are evaluated normally, in fact, I copied the property `jsfConst.userNameMaxFieldSize` to the `userEntity` and it works from there, but not from `JsfConst`. Any idea why? – Joe Almore Apr 01 '14 at 16:45
  • It could be a number of things. If you've fixed your annotations like @BalusC suggested, and that really is the entirety of your JsfConst class... it could be a classloading issue. Did you really name the file `jsfConst.java`? It should be `JsfConst.java`. That's the only other weird thing I notice, based on what you've shared. – Peter G Apr 01 '14 at 17:03
  • @PeterG, yes, I fixed the annotations as @BalusC suggested, and the name of the file is correct `JsfConst.java`, but it still does not recognize the file as a `ManagedBean`. – Joe Almore Apr 01 '14 at 17:19
  • @PeterG, Ohh god!!, I found it! I can't believe I missed this detail. You know, I am using **Arquillian** for integration testing, but in **Arquillian**, you need to declare all classes that comprehends the `war` file to deploy and test, and guess what? The `JsfConst.class` wasn't in the list. Just added the `JsfConst` file to the `ShrinkWrap.create(WebArchive.class, "createUser.war").addClass(JsfConst.class)` and now it works. – Joe Almore Apr 01 '14 at 17:33

1 Answers1

0

In Arquillian, you need to declare all classes that comprise the WAR file to deploy and test. Just register JsfConst in the WAR using ShrinkWrap.create(WebArchive.class, "createUser.war").addClass(JsfConst.class)

Peter G
  • 1,613
  • 10
  • 10