5 Replies Latest reply on Jun 28, 2011 2:29 PM by smoking81

    Problems starting my first RichFaces application with NetBeans

    smoking81 Newbie

      Hello everybody! I have just downloaded RichFaces 4.0.0 and wanted to create (and start) my first application but I got immediately a lot of problems, so I hope you can help me..

      I am using Netbeans 7 together with Glassfish 3.1 and, in order to start a very simple example, I performed the following actions:

       

      1) Created new Java Web application (java EE 6, JSF 2.0).

      2) downloaded RF 4.0.0 and added a new library "RichFaces" composed of the 4 jar files core-api, core-impl, components-api and components-ui as specified in every guide. I then imported this library in my project

      3) I had to import manually also jsf 2.0 - jsf-api.jar and jsf 2.0 - jsf-impl.jar otherwise the javax.faces.bean package did not get imported (strange but true..).

      4) I then modified my web.xml file by adding:

       

      
      
      <context-param>
      
      
              
      <param-name>org.richfaces.SKIN</param-name>
      
      
              
      <param-value>blueSky</param-value>
      
      
      
      </context-param>
      
      
      
      
      
      
      
      
      <!-- Making the RichFaces skin spread to standard HTML controls -->
      
      
      
      
      <context-param>
      
      
          
      <param-name>org.richfaces.CONTROL_SKINNING</param-name>
      
      
          
      <param-value>enable</param-value>
      
      
      
      </context-param>
      
      
      
      
      

      (I had to remove the filters because glassfish throwed an exception otherwise).

      5) Finally I created my facelet:

      <?xml version='1.0' encoding='UTF-8' ?>
      <!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:rich="http://richfaces.org/rich"
          xmlns:a4j="http://richfaces.org/a4j">
          <body>
      <h:form id="form">
          <rich:panel style="width:50%">
              <h:panelGrid columns="2">
                  <h:outputText value="Name:"/>
                  <h:inputText value="#{echoBean.name}"/>
                  <h:outputText value="Echo:"/>
                  <h:outputText id ="name" value="#{echoBean.name}"/>
                  <h:outputText value="Count: "/>
                  <h:outputText id ="count" value="#{echoBean.count}"/>
              </h:panelGrid>
              <h:commandButton  value="Submit" actionListener="#{echoBean.countListener}"  />
          </rich:panel>
          
      </h:form>
      </body>
      </html>
      

      and my bean:

      @ManagedBean
      @RequestScoped
      public class EchoBean {
      
          /** Creates a new instance of EchoBean */
          public EchoBean() {
          }
          private String name;
          private Integer count;
       //getter and setter
          
          public void countListener(ActionEvent e){
              count = name.length();
          }
      }
      

       

      What happens is:

      a) If I run the code as you see it now, it works but a warning gets displayed: Warning: This page calls for XML namespace http://richfaces.org/rich declared with prefix rich but no taglibrary exists for that namespace.

       

      b) If I replace h:commandButton by a4j:commandButton I get an error: The class 'src.EchoBean' does not have the property 'countListener'.

       

      Can you please help me understand what I did wrong?

       

      Thanks a lot in advance,

      bye,

      Federico

        • 1. Re: Problems starting my first RichFaces application with NetBeans
          Justin Wyer Newbie

          Hi Federico with regards to your first problem you should not have removed anything from your web.xml as the only thing to remove probably would have been

           


          <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>

           

          Make sure that you still have that in your web.xml

           

          Then you need to add dependency jars since you are not using a Maven project you can read which jars you need and where to get them here once you have the jars add them to the Netbeans library your created for Richfaces 4

           

          Your second problem can be solved with actionListener="#{echoBean.countListener()}" as it is a method and not a property (getter & setter).

           

          Message was edited by: Justin Wyer

          • 2. Re: Problems starting my first RichFaces application with NetBeans
            smoking81 Newbie

            hi justin thanks a lot for your kind answer!
            I downloaded the jar files I was missing and now my project includes the following:

                                richfaces-components-api-4.0.0.Final.jar

                                richfaces-components-ui-4.0.0.Final.jar

                                richfaces-core-api-4.0.0.Final.jar

                                richfaces-core-impl-4.0.0.Final.jar

                                guava-r09.jar

                                cssparser-0.9.5.jar

                                sac-1.3.jar

             

            If I change the web.xml and include the Filter tag as shown below I get the following exception:

            GRAVE: WebModule[/WebApplication1]PWC1270: Exception starting filter richfaces

            java.lang.InstantiationException

                at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:124)

                at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4625)

            ......

            Caused by: java.lang.ClassNotFoundException: org.ajax4jsf.Filter

                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1518)

                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1368)

                at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:252)

                at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:120)

                ... 47 more

             

            <?xml version="1.0" encoding="UTF-8"?>

            <web-app version="3.0" 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_3_0.xsd">

                <filter>

                    <display-name>RichFaces Filter</display-name>

                    <filter-name>richfaces</filter-name>

                    <filter-class>org.ajax4jsf.Filter</filter-class>

                </filter>

                <filter-mapping>

                   <filter-name>richfaces</filter-name>

                   <servlet-name>Faces Servlet</servlet-name>

                   <dispatcher>REQUEST</dispatcher>

                   <dispatcher>FORWARD</dispatcher>

                   <dispatcher>INCLUDE</dispatcher>

                </filter-mapping>

                <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>/faces/*</url-pattern>

                </servlet-mapping>

                <session-config>

                    <session-timeout>

                        30

                    </session-timeout>

                </session-config>

                <welcome-file-list>

                    <welcome-file>faces/index.xhtml</welcome-file>

                </welcome-file-list>

                <!-- Plugging the "Blue Sky" skin into the project -->

                <context-param>

                        <param-name>org.richfaces.SKIN</param-name>

                        <param-value>blueSky</param-value>

                </context-param>

             

                <!-- Making the RichFaces skin spread to standard HTML controls -->

                <context-param>

                    <param-name>org.richfaces.CONTROL_SKINNING</param-name>

                    <param-value>enable</param-value>

                </context-param>

            </web-app>

             

            If I remove the <filter> and <filter-mapping>, the deployment succeeds, but all the problems I had yesterday remain unchanged...

            This is my Bean:

            package src;

             

             

            import java.io.Serializable;

            import javax.faces.bean.ManagedBean;

            import javax.faces.bean.SessionScoped;

            import javax.faces.event.ActionEvent;

            @ManagedBean

            @SessionScoped

            public class EchoBean implements Serializable{

             

                public EchoBean() {

                }

                private String name;

                private Integer count;

                public Integer getCount() {

                    return count;

                }

                public void setCount(Integer count) {

                    this.count = count;

                }

                public String getName() {

                    return name;

                }

                public void setName(String name) {

                    this.name = name;

                }

                public void countListener(ActionEvent e){

                    count = name.length();

                }

               

            }

            And this my facelet:

             

            <?xml version='1.0' encoding='UTF-8' ?>

            <!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:rich="http://richfaces.org/rich"

                xmlns:a4j="http://richfaces.org/a4j">

                <body>

            <h:form id="form">

                <rich:panel style="width:50%">

                    <h:panelGrid columns="2">

                        <h:outputText value="Name:"/>

                        <h:inputText value="#{echoBean.name}"/>

                        <h:outputText value="Echo:"/>

                        <h:outputText id ="name" value="#{echoBean.name}"/>

                        <h:outputText value="Count: "/>

                        <h:outputText id ="count" value="#{echoBean.count}"/>

                    </h:panelGrid>

                    <a4j:commandButton value="Submit" actionListener="#{echoBean.countListener()}"  />

                </rich:panel>

               

            </h:form>

            </body>

            </html>

             

            Now the waring is: The form component needs to have a UIForm in its ancestry. Suggestion: enclose the necessary components within <h:form>

            and for the listener I get the following exception when I submit the form:

            GRAVE: JSF1073: javax.faces.event.AbortProcessingException caught during processing of INVOKE_APPLICATION 5 : UIComponent-ClientId=form:j_idt10, Message=Method countListener not found

            GRAVE: Method countListener not found

            javax.faces.event.AbortProcessingException: Method countListener not found

                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:409)

                at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1534)

                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 com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)

                at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)

                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)

                at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:326)

                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:227)

                at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:170)

                at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:822)

                at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:719)

                at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1013)

                at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)

                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:662)

            Caused by: javax.el.MethodNotFoundException: Method countListener not found

                at javax.el.BeanELResolver.findMethod(BeanELResolver.java:717)

                at javax.el.BeanELResolver.invoke(BeanELResolver.java:466)

                at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:254)

                at com.sun.el.parser.AstValue.invoke(AstValue.java:228)

                at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)

                at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:153)

                ... 34 more

             

            Furthermore, NetBeans displays an error message if I try to add reRender="name, count" to a4j:commandButton (which let me think there is a configuration error somewhere...)...

            Do you have any new Idea?

             

            Thanks again

            bye!

            • 3. Re: Problems starting my first RichFaces application with NetBeans
              Nick Belaevski Master

              Hi,

               

              Try actionListener="#{echoBean.countListener}" instead of actionListener="#{echoBean.countListener()}".

               

              Filter is not necessary in RF 4.x.

               

              'reRender' attribute has been renamed to 'render', see documentation for more information.

              • 4. Re: Problems starting my first RichFaces application with NetBeans
                Justin Wyer Newbie

                Hi Federico you don't need the filter stuff Nick is correct that is for RF 3.x and that reRender has been renamed rerender.

                 

                The warning "The form component needs to have a UIForm in its ancestry. Suggestion: enclose the necessary components within <h:form>" is a Mojarra (JSF Implementation) bug you can get rid of it by upgrading your JSF in glassfish:

                 

                download Mojarra 2.1.2 from http://javaserverfaces.java.net/ and replacing jsf-api.jar and jsf-impl.jar in <gf_install_directory>/glassfish/modules/ (backup the old files first).

                 

                or you can do this to get rid of the warning in web.xml change

                 

                    <context-param>

                        <param-name>javax.faces.PROJECT_STAGE</param-name>

                        <param-value>Development</param-value>

                    </context-param>

                 

                to

                 

                    <context-param>

                        <param-name>javax.faces.PROJECT_STAGE</param-name>

                        <param-value>Production</param-value>

                    </context-param>

                 

                Finally give this code a try:

                 

                 

                import java.io.Serializable;
                // Rather use CDI than a JSF ManagedBean.
                import javax.inject.Named;
                import javax.enterprise.context.SessionScoped;
                @Named
                @SessionScoped
                public class EchoBean implements Serializable {
                
                    public EchoBean() {
                    }
                    private String name;
                    private Integer count;
                    public Integer getCount() {
                        return count;
                    }
                    public void setCount(Integer count) {
                        this.count = count;
                    }
                    public String getName() {
                        return name;
                    }
                    public void setName(String name) {
                        this.name = name;
                    }
                    public void calculate() {
                        count = name.length();
                    }
                
                }
                

                 

                 

                <?xml version='1.0' encoding='UTF-8' ?>
                <!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:rich="http://richfaces.org/rich"
                    xmlns:a4j="http://richfaces.org/a4j">
                    <body>
                <h:form id="form">
                    <rich:panel style="width:50%">
                        <h:panelGrid columns="2">
                            <h:outputText value="Name:" />
                            <h:inputText value="#{echoBean.name}" />
                            <h:outputText value="Echo:" />
                            <h:outputText id ="name" value="#{echoBean.name}" />
                            <h:outputText value="Count: " />
                            <h:outputText id ="count" value="#{echoBean.count}" />
                        </h:panelGrid>
                        <a4j:commandButton value="Submit" action="#{echoBean.calculate()}" />
                    </rich:panel>
                
                </h:form>
                </body>
                </html>
                

                 

                Before you run this add beans.xml to your WEB-INF directory:

                <?xml version="1.0" encoding="UTF-8"?>
                <beans 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/beans_1_0.xsd">
                </beans>
                
                1 of 1 people found this helpful
                • 5. Re: Problems starting my first RichFaces application with NetBeans
                  smoking81 Newbie

                  thank you all..!

                  I did not get rid of the warning by updating the jars of mojarra, but I have finally seen the example running! Thanks again!