2

I managed to run WAB package with Primefaces. The problem is that some of the example are working and some of the examples have problems when I try to implement them. I tested this example:

    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"    
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:p="http://primefaces.org/ui"  >
        <h:head>
            <ui:insert name="header">           
                <ui:include src="header.xhtml"/>         
            </ui:insert>
        </h:head>
        <h:body>

            <h1><img src="resources/css/images/icon.png" alt="NVIDIA.com" /> History Center</h1>
            <!-- layer for black background of the buttons -->
            <div id="toolbar" style="margin: 0 auto; width:1180px; height:30px; position:relative;  background-color:black">
                <!-- Include page Navigation -->
                <ui:insert name="Navigation">           
                    <ui:include src="Navigation.xhtml"/>         
                </ui:insert>

            </div>  

            <div id="logodiv" style="position:relative; top:35px; left:0px;"> 
                <h:graphicImage alt="Demo edit form"  style="position:relative; top:-20px; left:9px;"  value="resources/images/logo_linuxz.png" />
            </div>
            <div id="main" style="margin: 0 auto; width:1190px; height:700px; position:absolute;  background-color:transparent; top:105px">

                <div id="mainpage" style="margin: 0 auto; width:1190px; height:500px; position:absolute;  background-color:transparent; top:80px">

                    <div id="settingsHashMap" style="width:350px; height:400px; position:absolute;  background-color:r; top:20px; left:1px">

                        <h:form>

                            <p:growl id="growl" showDetail="true" sticky="true" />

                            <p:panel header="Growl">
                                <h:panelGrid columns="2">
                                    <h:outputText value="Your Name: *" /> 
                                    <p:inputText value="#{LinuxController.text}" required="true" label="Name"/>
                                </h:panelGrid>

                                <p:commandButton value="Save" actionListener="#{LinuxController.save}" update="growl"/>
                            </p:panel>

                        </h:form>


                    </div>   

                </div>  
            </div>

        </h:body>
    </html>

import javax.faces.bean.ViewScoped;

import java.io.Serializable;

import javax.faces.application.FacesMessage;  
import javax.faces.context.FacesContext;  

// Update form example
@Named("LinuxController")
@ViewScoped
public class Linux implements Serializable {

    public Linux() {  
    }  

    private String text;

    public String gettext() {
        return text;
    }
    public void settext(String text) {
        this.text = text;
    }

    public void save(ActionEvent actionEvent) {
        FacesContext context = FacesContext.getCurrentInstance();

        context.addMessage(null, new FacesMessage("Successful", "Hello " + text));
        context.addMessage(null, new FacesMessage("Second Message", "Additional Info Here..."));
    }

}

THis is the POM file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.DX_57</groupId>
    <artifactId>History-Module-57</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>History-Module-57</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>


        <dependency>  
            <groupId>org.primefaces</groupId>  
            <artifactId>primefaces</artifactId>  
            <version>3.3</version>  
            <type>jar</type>

        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
            <version>4.3.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.compendium</artifactId>
            <version>4.2.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>osgi-cdi-api</artifactId>
            <version>3.1-b41</version>
            <type>jar</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.faces</artifactId>
            <version>2.1.9</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>

        </dependency>
    </dependencies>

    <build>
        <pluginManagement>

            <plugins>
                <plugin>
                    <groupId>org.apache.felix</groupId>
                    <artifactId>maven-bundle-plugin</artifactId>
                    <version>2.3.7</version>
                    <extensions>true</extensions>
                    <configuration>
                        <supportedProjectTypes>
                            <supportedProjectType>ejb</supportedProjectType>
                            <supportedProjectType>war</supportedProjectType>
                            <supportedProjectType>bundle</supportedProjectType>
                            <supportedProjectType>jar</supportedProjectType>
                        </supportedProjectTypes>
                        <instructions>
                            <!-- Read all OSGi configuration info from this optional file -->
                            <_include>-osgi.properties</_include>
                            <!-- By default, we don't export anything -->
                            <Export-Package></Export-Package>
                            <DynamicImport-Package>*</DynamicImport-Package>
                            <Import-Package>*;resolution:=optional</Import-Package>
                            <Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency>
                            <Embed-Transitive>true</Embed-Transitive>
                            <Embed-Directory>WEB-INF/lib/</Embed-Directory>
                            <Embed-StripVersion>false</Embed-StripVersion>
                            <Embed-StripGroup>true</Embed-StripGroup>
                            <Bundle-ClassPath>.,WEB-INF/classes</Bundle-ClassPath>
                        </instructions>
                    </configuration>
                    <executions>
                        <execution>
                            <id>bundle-manifest</id>
                            <phase>process-classes</phase>
                            <goals>
                                <goal>manifest</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>bundle-install</id>
                            <phase>install</phase>
                            <goals>
                                <goal>install</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin> 

                <plugin> <!-- Need to use this plugin to build war files -->
                    <artifactId>maven-war-plugin</artifactId>
                    <groupId>org.apache.maven.plugins</groupId>
                    <!-- Use version 2.1-beta-1, as it supports the new property failOnMissingWebXml -->
                    <version>2.2</version>
                    <configuration>
                        <archive>
                            <!-- add bundle plugin generated manifest to the war -->
                            <manifestFile>
                                ${project.build.outputDirectory}/META-INF/MANIFEST.MF
                            </manifestFile>
                            <!-- For some reason, adding Bundle-ClassPath in maven-bundle-plugin
                            confuses that plugin and it generates wrong Import-Package, etc.
                            So, we generate it here.
                            -->
                            <manifestEntries>
                                <Bundle-ClassPath>WEB-INF/classes/
                                </Bundle-ClassPath>
                            </manifestEntries>
                        </archive>
                    <!-- We don't have a web.xml -->
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>6.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <!-- Enable this plugin for all modules -->
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>glassfish-repo</id>
            <name>The Glassfish repository</name>
            <url>http://download.java.net/maven/glassfish/</url>
        </repository>
        <repository>  
            <id>prime-repo</id>  
            <name>PrimeFaces Maven Repository</name>  
            <url>http://repository.primefaces.org</url>  
            <layout>default</layout>  
        </repository>  
    </repositories>
    <description>Module History Module</description>
</project>

I only get error message. I get this error stack in Glassfish:

[#|2012-06-07T15:45:52.438+0300|SEVERE|glassfish3.1.2|javax.faces.event|_ThreadID=339;_ThreadName=Thread-2;|Received 'javax.el.MethodNotFoundException' when invoking action listener '#{LinuxController.save}' for component 'j_idt17'|#]

[#|2012-06-07T15:45:52.439+0300|SEVERE|glassfish3.1.2|javax.faces.event|_ThreadID=339;_ThreadName=Thread-2;|javax.el.MethodNotFoundException: Method not found: com.DX_57.HM_57.Linux@2be5284e.save()
    at com.sun.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:160)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:251)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302)
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)
|#]

[#|2012-06-07T15:45:52.439+0300|SEVERE|glassfish3.1.2|javax.enterprise.resource.webcontainer.jsf.context|_ThreadID=339;_ThreadName=Thread-2;|JSF1073: javax.faces.event.AbortProcessingException caught during processing of INVOKE_APPLICATION 5 : UIComponent-ClientId=j_idt12:j_idt17, Message=Method not found: com.DX_57.HM_57.Linux@2be5284e.save()|#]

[#|2012-06-07T15:45:52.440+0300|SEVERE|glassfish3.1.2|javax.enterprise.resource.webcontainer.jsf.context|_ThreadID=339;_ThreadName=Thread-2;|Method not found: com.DX_57.HM_57.Linux@2be5284e.save()
javax.faces.event.AbortProcessingException: Method not found: com.DX_57.HM_57.Linux@2be5284e.save()
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:182)
    at javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769)
    at javax.faces.component.UICommand.broadcast(UICommand.java:300)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)
Caused by: javax.el.MethodNotFoundException: Method not found: com.DX_57.HM_57.Linux@2be5284e.save()
    at com.sun.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:160)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:251)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302)
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)
    ... 33 more
|#]

What may cause this problem?

UPDATE

I changed he name of the managed bean. It turns out that the framework is searching for the wrong name of the managed bean- avax.el.MethodNotFoundException: Method not found: com.DX_57.HM_57.Linux@c280dca.save(). It should be avax.el.MethodNotFoundException: Method not found: com.DX_57.HM_57.Linux@LinuxController.save() Is this a configuration problem?

user1285928
  • 1,328
  • 29
  • 98
  • 147

1 Answers1

6

That's because ViewScoped is not natively supported in CDI. Either change @Named("LinuxController") to @ManagedBean(name="LinuxController") to make it pure JSF or change ViewScoped to something else like Seam's ConversationalScope or SessionScope (or in your case I think RequestScope is just fine)

P.S. Also check out if you implement right package for ActionEvent, it once took me two hours to discover that I have there java.awt.event.ActionEvent instead the right one from JSF:-)

EDIT

So what exactly did you try?Have you changed the scope of the bean, made it ManagedBean instead of CDI bean, changed method name both in page and in bean?Or you can create another bean with the same signature and try to reproduce the error. Also try to assign some value to the text variable to see if the method getText is working. It's hard to say where could be the problem until you try to narrow down possible options.

SOLUTION

Ok, so I hope I found a solution for you. You should decide if you want to use either CDI or pure JSF. If you want to go with the CDI way, keep the bean annotated as the @Named and use some other scope then ViewScoped. If you choose the JSF way, then change @Named to @ManagedBean and you can keep it ViewScoped. In both cases you should delete managed-bean record in faces-config.xml, it was ment to use with JSF 1.2 before the annotation @ManagedBean, so it's deprecated now (and you can't use both annotation and record in config, you have to choose one of the options).

You also need to improve your imports. As I wrote before, you've had a import of java.awt.ActionEvent but you need javax.faces.event.ActionEvent. Also note if you use CDI, then import all annotations for scopes (RequestScoped, SessionScoped, ...) from javax.enterprise.context.* package (see that ViewScope is missing there) and if want to use JSF with ManagedBean then import everything from javax.faces.bean.*. You can't mix them together, because then you get some strange errors like the one you have.

Here are the changed files.

You should also follow the Java convetion and use CamelCase for naming your methods (i.e. not gettext() but getText()). It's especially important for JSF Expression Language, because you need setters and getters for accessing bean properties on the page and these methods should be written in CamelCase, so the JSF EL can parse them.

Petr Mensik
  • 26,874
  • 17
  • 90
  • 115
  • ViewScoped doesn't work in CDI? I thought that was one of the advantages of CDI vs. Spring, because I know for sure that Spring doesn't allow the use of the ViewScoped functionality. – maple_shaft Jun 07 '12 at 13:11
  • Not Working. Why Glassfish is searching for `com.DX_57.HM_57.Linux@41919ac4.save()`? It should be `com.DX_57.HM_57.LinuxController.save()` – user1285928 Jun 07 '12 at 13:34
  • Try to clean and build your app, also try to search the word Linux with fulltext in the root folder of your project, maybe it's still forgetten in some configuration file somewhere(that happened to me once too). And if nothing work, try to set up new project, it's not that hard now and I doubt that you will get the same error. – Petr Mensik Jun 07 '12 at 19:40
  • @maple_shaft: See this question, it describes the problem well http://stackoverflow.com/questions/9580698/how-to-use-view-scope-in-case-of-cdi-in-jsf-2-0 – Petr Mensik Jun 07 '12 at 19:42
  • I tested to change the scope with session and request but there is not change. May be this is configuration problem. – user1285928 Jun 09 '12 at 13:43
  • Thank you the imported libraries were the problem. – user1285928 Jun 10 '12 at 09:51