2 Replies Latest reply on May 13, 2008 10:08 PM by Shervin Asgari

    Free text search problem

    Shervin Asgari Master

      Hello.


      I am trying to have a textbox, where I want to be able to search for a Person. I want the textbox to search for firstname, lastname and ssn.


      But whatever I do, I cannot retrieve the search parameter the user inputs. I have tried to put a person object with @In and @Out in my action, and bind that to the output text, but then I got a property not found exception.
      My method findPersons always returns fritext is empty.


      SearchRegister.xhtml:



      <ui:define name="body">
          <h:messages globalOnly="true" styleClass="message" id="globalMessages"/>
      
           <h:form id="personSearch" styleClass="edit">
              <rich:simpleTogglePanel label="Person search parameters" switchType="ajax">
                  <s:decorate template="../layout/display.xhtml">
                      <ui:define name="label">Person</ui:define>
                      <h:inputText id="fritekstPerson" value="" title="fritekstPerson" />
                  </s:decorate>
              </rich:simpleTogglePanel>
              
              <div class="actionButtons">
                  <h:commandButton id="search" value="Search" action="#{searchRegisterManager.findPersons}"/>
              </div>
          </h:form>
      
      
           <rich:panel>
              <f:facet name="header">person search results</f:facet>
          <div class="results" id="person">
          
          <h:outputText value="The person search returned no results." 
                     rendered="#{empty personerList}"/>
      
          <rich:dataTable id="person" var="person" value="#{personerList}">
              <h:column>
                  <f:facet name="header">personId</f:facet>
                  #{person.personId}
              </h:column>
              <h:column>
                  <f:facet name="header">lastname</f:facet>
                  #{person.lastname}
              </h:column>
              <h:column>
                  <f:facet name="header">firstname</f:facet>
                  #{person.firstname}
              </h:column>
              <h:column>
                  <f:facet name="header">ssn</f:facet>
                  #{person.ssn}
              </h:column>
          </rich:dataTable>
      
          </div>
          </rich:panel>
      
      </ui:define>



      And my SearchRegisterManagerAction.java:



      @Stateful
      @Name("searchRegisterManager")
      @Scope(ScopeType.SESSION)
      public class SearchRegisterManagerAction implements SearchRegisterManager {
      
           @PersistenceContext(type = EXTENDED)
           private EntityManager em;
      
           @In(required = false)
           private String fritekstPerson;
      
           @SuppressWarnings("unused")
           @DataModel
           private List<Person> personerList;
      
           @Logger
           private Log log;
      
           @Factory("personerList")
           @SuppressWarnings("unchecked")
           public void findAllPersons() {
                if (fritekstPerson == null || fritekstPerson.equals("")) {
                     log.info("Søker etter alle personer");
                     personerList = em.createQuery("from " + Person.class.getName() + " p order by p.etternavn").getResultList();
                } else {
                     log.info("Søker etter spesifisert person");
                     personerList = em.createQuery("from " + Person.class.getName() + " p " +
                               "where p.fornavn like '%" + fritekstPerson + "%' " +
                               "OR p.etternavn like '%" + fritekstPerson + "%' " +
                               "OR p.personnummer like '%" + fritekstPerson + "%' " +
                               "order by p.etternavn").getResultList();
                }
      
                for (Person p : personerList) {
                     log.info("Personnr: " + p.getPersonnummer());
                }
           }
      
           public void findPersons() {
                if (fritekstPerson == null || fritekstPerson.equals("")) {
                     log.info("Whut, fritext is empty");
                } else {
                     log.info("Søker etter spesifisert person");
                     personerList = em.createQuery("from " + Person.class.getName() + " p " +
                               "where p.fornavn like '%" + fritekstPerson + "%' " +
                               "OR p.etternavn like '%" + fritekstPerson + "%' " +
                               "OR p.personnummer like '%" + fritekstPerson + "%' " +
                               "order by p.etternavn").getResultList();
                }
           }
           
           @Destroy
           @Remove
           public void destroy() {
           }
      }



      Help is greatly appreciated.

        • 1. Re: Free text search problem
          Mark Michalek Newbie

          It doesn't look like the inputText component is bound to anything.


          <h:inputText id="fritekstPerson" value="" title="fritekstPerson"/>



          The value attribute on the inputText needs to be bound to something. I'm not sure if you can bind directly to a string as your example indicates, though.  Usually, a value binding involves a managed object/seam component and a field on that component.  For example:


          <h:inputText id="fritekstPerson" value="#{personSearchCriteria.searchText}" title="fritekstPerson" />



          With something like:


          @Name("personSearchCriteria")
          public class PersonSearchCriteria {
             private String searchText;
             // getters/setters, etc.   
          }



          If binding directly to a string is possible, I'd be interested in knowing that.

          • 2. Re: Free text search problem
            Shervin Asgari Master

            Yes I know I have to bind to something.
            I tried to bind to a Person object with @In and @Out annotation, but I got a property not found exception when I tried to use it.


            I left the value blank so I could get some help.