12 Replies Latest reply on May 4, 2009 8:55 AM by mvg kumar

    Need help in Richfaces suggestionbox

    mvg kumar Newbie

      Hi all,

      I am new to Richfaces and JSF. I want to develop the application in JSF which uses auto complete suggestion box. I tried richfaces suggestionbox to do that and I encountered the following error


      javax.servlet.ServletException: /suggestionBox.jsp(22,20) '#{richFacesBean.autocomplete}' java.lang.NullPointerException
      javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
      org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
      org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
      org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
      org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
      org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

      root cause

      org.apache.jasper.el.JspELException: /suggestionBox.jsp(22,20) '#{richFacesBean.autocomplete}' java.lang.NullPointerException
      org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:77)
      org.richfaces.component.UISuggestionBox.setupValue(UISuggestionBox.java:492)
      org.richfaces.component.UISuggestionBox.broadcast(UISuggestionBox.java:424)
      javax.faces.component.UIData.broadcast(UIData.java:854)
      org.richfaces.component.UISuggestionBox.broadcast(UISuggestionBox.java:421)
      org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
      org.ajax4jsf.component.AjaxViewRoot.broadcastAjaxEvents(AjaxViewRoot.java:340)
      org.ajax4jsf.application.AjaxViewHandler.processAjaxEvents(AjaxViewHandler.java:216)
      org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:169)
      com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
      com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
      com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
      javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
      org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
      org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
      org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
      org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
      org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

      root cause

      java.lang.NullPointerException
      org.my.richfaces.RichFacesBean.autocomplete(RichFacesBean.java:100)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      java.lang.reflect.Method.invoke(Method.java:597)
      org.apache.el.parser.AstValue.invoke(AstValue.java:172)
      org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
      org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
      org.richfaces.component.UISuggestionBox.setupValue(UISuggestionBox.java:492)
      org.richfaces.component.UISuggestionBox.broadcast(UISuggestionBox.java:424)
      javax.faces.component.UIData.broadcast(UIData.java:854)
      org.richfaces.component.UISuggestionBox.broadcast(UISuggestionBox.java:421)
      org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
      org.ajax4jsf.component.AjaxViewRoot.broadcastAjaxEvents(AjaxViewRoot.java:340)
      org.ajax4jsf.application.AjaxViewHandler.processAjaxEvents(AjaxViewHandler.java:216)
      org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:169)
      com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
      com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
      com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
      javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
      org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
      org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
      org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
      org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
      org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)


      My code is

      <%@taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
      <%@taglib uri="http://richfaces.org/rich" prefix="rich"%>

      <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
      <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>

      <%@page contentType="text/html" pageEncoding="UTF-8"%>
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd">



      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      JSP Page


      <f:view>
      <h:form>
      <h:inputText value="#{richFacesBean.text}" id="input">
      <a4j:support event="onkeyup" reRender="radio"/>
      </h:inputText>
      <rich:suggestionbox id="radio" fetchValue="#{suggest.Name}" width="50" height="50" for="input" suggestionAction="#{richFacesBean.autocomplete}"
      var="suggest">
      <h:column>
      <h:outputText id="radio" value="#{suggest.Name}"/>
      </h:column>
      </rich:suggestionbox>
      </h:form>
      </f:view>





      package org.my.richfaces;

      import java.util.ArrayList;
      import java.util.List;
      import org.richfaces.component.html.HtmlSuggestionBox;


      public class RichFacesBean {

      private String text;
      private String button;
      private ArrayList autocomplete;
      private ArrayList capitals;
      private User user;
      HtmlSuggestionBox myList = new HtmlSuggestionBox();
      public User getUser() {
      return user;
      }

      public void setUser(User user) {
      this.user = user;
      }

      public ArrayList getCapitals() {
      return capitals;
      }

      public void setCapitals(ArrayList capitals) {
      this.capitals = capitals;
      }

      public String addCapital(User user) {
      capitals.add(user);
      return null;
      }

      public RichFacesBean() {
      }

      public String getText() {
      return text;
      }

      public void setText(String text) {
      this.text = text;
      }

      public String getButton() {
      return button;
      }

      public void setButton(String button) {
      this.button = button;
      }

      public List autocomplete(Object suggest) {
      String pref = (String)suggest;
      ArrayList result = new ArrayList();

      Iterator iterator = getCapitals().iterator();
      while (iterator.hasNext()) {
      User elem = ((User) iterator.next());
      if ((elem.getName() != null && elem.getName().toLowerCase().indexOf(pref.toLowerCase()) == 0) || "".equals(pref))
      {
      result.add(elem);
      }
      }
      return result;
      }

      public void setAutocomplete(ArrayList autocomplete) {
      this.autocomplete = autocomplete;
      }

      class User
      {
      public String Name;
      ArrayList result = new ArrayList();

      public User(String name)
      {
      Name=name;
      }

      public String getName() {
      return Name;
      }

      public void setName(String itsName) {
      this.Name = itsName;
      }

      public ArrayList getResult()
      {
      return result;
      }

      public void setResult(ArrayList result) {
      this.result = result;
      }
      }
      }

      Please help me to solve this. Though it appears to me as a minor error. I am unable to solve this. I use Netbeans 6.5 as my IDE and Firefox as my browser. I installed Richfaceslibrary version 2 and RichfacesSupport version 2 in my netbeans.

        • 1. Re: Need help in Richfaces suggestionbox
          Nick Belaevski Master

          Hello,

          capitals list is not initialized.

          • 2. Re: Need help in Richfaces suggestionbox
            mvg kumar Newbie

            Hi nbelaevski,

            Thank you for the very quick reply. Yeah I initialized the capitals now. But now when I input text no changes occur. I checked in the Tomcat log in netbeans and no error in there too!

            pl help.

            • 3. Re: Need help in Richfaces suggestionbox
              Nick Belaevski Master

              Try removing this:

              <a4j:support event="onkeyup" reRender="radio"/>


              • 4. Re: Need help in Richfaces suggestionbox
                mvg kumar Newbie

                Thank you for the suggestion, I will work with it and get back to you soon

                • 5. Re: Need help in Richfaces suggestionbox
                  mvg kumar Newbie

                  As I told, I worked with your suggestion and I got the following errror.


                  javax.servlet.ServletException: /suggestionBox.jsp(23,28) '#{suggest.Name}' Property 'Name' not found on type org.my.richfaces.RichFacesBean$User
                  javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
                  org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                  org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                  org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
                  org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
                  org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

                  root cause

                  org.apache.jasper.el.JspPropertyNotFoundException: /suggestionBox.jsp(23,28) '#{suggest.Name}' Property 'Name' not found on type org.my.richfaces.RichFacesBean$User
                  org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:104)
                  javax.faces.component.UIOutput.getValue(UIOutput.java:173)
                  com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:189)
                  com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:320)
                  com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:200)
                  javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
                  org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:286)
                  org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
                  org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:284)
                  org.ajax4jsf.renderkit.compiler.ChildElement.encode(ChildElement.java:54)
                  org.ajax4jsf.renderkit.compiler.ElementBase.encode(ElementBase.java:105)
                  org.ajax4jsf.renderkit.compiler.ElementBase.encode(ElementBase.java:105)
                  org.ajax4jsf.renderkit.compiler.ChildrensElement.encode(ChildrensElement.java:125)
                  org.ajax4jsf.renderkit.compiler.ElementBase.encode(ElementBase.java:105)
                  org.ajax4jsf.renderkit.compiler.ElementBase.encode(ElementBase.java:105)
                  org.ajax4jsf.renderkit.compiler.ChildrensElement.encode(ChildrensElement.java:125)
                  org.ajax4jsf.renderkit.compiler.ElementBase.encode(ElementBase.java:105)
                  org.ajax4jsf.renderkit.compiler.ElementBase.encode(ElementBase.java:105)
                  org.ajax4jsf.renderkit.compiler.ElementBase.encode(ElementBase.java:105)
                  org.ajax4jsf.renderkit.compiler.RootElement.encode(RootElement.java:64)
                  org.richfaces.renderkit.html.SuggestionBoxRenderer.encodeChildren(SuggestionBoxRenderer.java:327)
                  javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
                  org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
                  org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:124)
                  org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:67)
                  org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:115)
                  org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:67)
                  org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:115)
                  org.ajax4jsf.renderkit.AjaxContainerRenderer.encodeAjax(AjaxContainerRenderer.java:123)
                  org.ajax4jsf.component.AjaxViewRoot.encodeAjax(AjaxViewRoot.java:677)
                  org.ajax4jsf.component.AjaxViewRoot.encodeChildren(AjaxViewRoot.java:548)
                  javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
                  com.sun.faces.application.ViewHandlerImpl.doRenderView(ViewHandlerImpl.java:245)
                  com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:176)
                  org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
                  org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
                  com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
                  com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
                  com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
                  javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
                  org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                  org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                  org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
                  org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
                  org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)


                  If I changed the value of

                  <h:outputText id="radio" value="#{suggest.Name}"/>


                  from #{suggest.Name} to #{suggest} suggestionbox shows the object name and if I change the value to any names like value="mvg", it also get displayed in the suggestionbox. Pl help.

                  • 6. Re: Need help in Richfaces suggestionbox
                    Ilya Shaikovsky Master

                    you should use not #{suggest.Name} but #{suggest.name}

                    • 7. Re: Need help in Richfaces suggestionbox
                      Nick Belaevski Master

                      You are using expressions incorrectly. Should be "suggest.name".

                      • 8. Re: Need help in Richfaces suggestionbox
                        mvg kumar Newbie

                        Hi nbelaevski and ilya,

                        Thank you for the tip. Sorry to say, I tried that and ended up in the following error

                        javax.servlet.ServletException: /suggestionBox.jsp(23,28) '#{suggest.name}' Property 'name' not readable on type java.lang.String
                        javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
                        org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                        org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                        org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
                        org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
                        org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

                        root cause

                        org.apache.jasper.el.JspPropertyNotFoundException: /suggestionBox.jsp(23,28) '#{suggest.name}' Property 'name' not readable on type java.lang.String
                        org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:104)
                        javax.faces.component.UIOutput.getValue(UIOutput.java:173)
                        com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:189)
                        com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:320)
                        com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:200)
                        javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
                        org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:286)
                        org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:262)
                        org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:284)
                        org.ajax4jsf.renderkit.compiler.ChildElement.encode(ChildElement.java:54)
                        org.ajax4jsf.renderkit.compiler.ElementBase.encode(ElementBase.java:105)
                        org.ajax4jsf.renderkit.compiler.ElementBase.encode(ElementBase.java:105)
                        org.ajax4jsf.renderkit.compiler.ChildrensElement.encode(ChildrensElement.java:125)
                        org.ajax4jsf.renderkit.compiler.ElementBase.encode(ElementBase.java:105)
                        org.ajax4jsf.renderkit.compiler.ElementBase.encode(ElementBase.java:105)
                        org.ajax4jsf.renderkit.compiler.ChildrensElement.encode(ChildrensElement.java:125)
                        org.ajax4jsf.renderkit.compiler.ElementBase.encode(ElementBase.java:105)
                        org.ajax4jsf.renderkit.compiler.ElementBase.encode(ElementBase.java:105)
                        org.ajax4jsf.renderkit.compiler.ElementBase.encode(ElementBase.java:105)
                        org.ajax4jsf.renderkit.compiler.RootElement.encode(RootElement.java:64)
                        org.richfaces.renderkit.html.SuggestionBoxRenderer.encodeChildren(SuggestionBoxRenderer.java:327)
                        javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
                        org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282)
                        org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:124)
                        org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:67)
                        org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:115)
                        org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxChildren(AjaxChildrenRenderer.java:67)
                        org.ajax4jsf.renderkit.AjaxChildrenRenderer.encodeAjaxComponent(AjaxChildrenRenderer.java:115)
                        org.ajax4jsf.renderkit.AjaxContainerRenderer.encodeAjax(AjaxContainerRenderer.java:123)
                        org.ajax4jsf.component.AjaxViewRoot.encodeAjax(AjaxViewRoot.java:677)
                        org.ajax4jsf.component.AjaxViewRoot.encodeChildren(AjaxViewRoot.java:548)
                        javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
                        com.sun.faces.application.ViewHandlerImpl.doRenderView(ViewHandlerImpl.java:245)
                        com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:176)
                        org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
                        org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
                        com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
                        com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
                        com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
                        javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
                        org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                        org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                        org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)
                        org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)
                        org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)


                        • 9. Re: Need help in Richfaces suggestionbox
                          Ilya Shaikovsky Master

                          bean property should not be started from Capital letter according to Java Bean spec.
                          So, change the "Name" property declaration in your bean with "name".

                          • 10. Re: Need help in Richfaces suggestionbox
                            mvg kumar Newbie

                            Hi Ilya,

                            Thank you for the patience. As you said I changed 'Name' to 'name' and changed class declaration from

                            class User


                            to
                            public class User


                            using this url
                            http://forums.sun.com/thread.jspa?threadID=5305781

                            and the suggestion box is now getting displayed. Thanks again for helping me and thank you nbelaevski also for helping me

                            • 11. Re: Need help in Richfaces suggestionbox
                              Nick Belaevski Master

                              Ilya is not correct. You can call bean property how do you like, only accessor and mutator methods should be named according to standard.

                              • 12. Re: Need help in Richfaces suggestionbox
                                mvg kumar Newbie

                                Thank you nbelaevski for the tip.