2 Replies Latest reply on Sep 11, 2010 10:34 PM by Hunter Stern

    trying to display components updated by an AJAX request

    Hunter Stern Newbie

      I'm having difficulty displaying a component after it's updated by an AJAX request.  The component is session scoped and is below:









      @Scope(ScopeType.SESSION)
      @Name("searchResultsBean")
      public class SearchResultsBean {
      
          private List<SearchResult> searchResults = new ArrayList<SearchResult>(0);
          private List<SearchFacet> searchFacets = new ArrayList<SearchFacet>(0);
          private List<SearchDateFacet> searchDateFacets = new ArrayList<SearchDateFacet>(0);
      
          public Integer getDreamIdForMatch() {
              return dreamIdForMatch;
          }
      
          public void setDreamIdForMatch(Integer dreamIdForMatch) {
              this.dreamIdForMatch = dreamIdForMatch;
          }
      
          private Integer dreamIdForMatch;
      
          public List getSearchFacets() {
              return searchFacets;
          }
      
          public List getSearchDateFacets() {
              return searchDateFacets;
          }
      
          public List getSearchResults() {
      
              return searchResults;
          }
      
          public void clear() {
              searchResults.clear();
              clearFacets();
          }
      
          public void clearFacets() {
              searchFacets.clear();
          }
      
          public void addFacet(SearchFacet facet) {
              searchFacets.add(facet);
          }
      
          public void addFacet(long count, String facetName, String fq) {
      
              searchFacets.add(new SearchFacet(count, facetName, fq));
          }
      
          public void addDateFacet(SearchDateFacet f) {
              searchDateFacets.add(f);
          }
      
          public void addSearchResult(String id, String name, String description,
                  Date date, String tag) {
      
      
              searchResults.add(new SearchResult(
                      id,
                      name,
                      description,
                      date,
                      tag
                      ));
      
          }
      
      
          public void addDateFacet(long count, String facetName, String fq) {
      
              searchDateFacets.add(new SearchDateFacet(count, facetName, fq));
          }
      
      
      }
      



      The SLSB method that is called by AJAX and updates the SearchResultsBean component is below:




          public boolean matchDream(Integer userId, Integer dreamId) {
      
              //Conversation.instance().setViewId("/DreamMatches2.xhtml");
      
              searchResultsBean.clear();
      
              List<Dream> dreamsForUser = dreamList.getDreamsForUserId(userId);
      
              Dream dream = dreamList.getDream(dreamId);
      
              String queryString =
                      createQuery(solrEscape(dream.getDescription()), dreamsForUser);
      
              //System.out.println("match query: " + queryString);
      
              SolrQuery query = new SolrQuery();
              query.setRows(3);
              
              
              try {
              //query.setQuery(queryTerm);
                  query.setQuery(
                      queryString);
              }
              catch (Exception exc) {
                  log.error("error setting query", exc);
              }
      
              try {
      
                  if (server == null) server = new CommonsHttpSolrServer(solrHost);
              }
              catch (Exception exc) {
                  log.error("error querying Solr host", exc);         
              }
      
              QueryResponse resp = null;
      
              //System.out.println(queryString);
      
              try {
                  resp = server.query(query);
              }
              catch (Exception exc) {
                  log.error("error querying search server", exc);
              }
      
              SolrDocumentList docs = resp.getResults();
      
              Iterator<SolrDocument> iter = docs.iterator();
      
              while (iter.hasNext()) {
                  SolrDocument resultDoc = iter.next();
      
                  String tags = (String) resultDoc.getFieldValue("tag");
                  String dv = (String) resultDoc.getFieldValue("dreamvalue");
                  Date dreamDate = (Date)resultDoc.getFieldValue("dreamdate");
                  String dn = (String) resultDoc.getFieldValue("dreamname");
                  Integer did = (Integer) resultDoc.getFieldValue("dream_id"); //id is the uniqueKey field
      
      
                  //System.out.println("in!!!!!!!!!!!!!");
                  
                  searchResultsBean.addSearchResult(
                         String.valueOf(did),
                         dn,
                         dv,
                         dreamDate,
                         tags
                          );
              }
      
              searchResultsBean.setDreamIdForMatch(dreamId);
      
              return true;
      
          }
      




      The xhtml with the AJAX call and component rendering is below.  My problem (which is probably a simple misunderstanding on my part) is that the SearchResultBean in the datatablepanel rich panel won't display.  It is supposed to display a data table of components (dreams) populated by the searchResultsBean.getSearchResults() method.  If I simply reload the page, the search results show up correctly.  Any help is appreciated.






                  <a:region id="theregion">
                      <a:form  id="theform" ajaxSingle="true" reRender="datatablepanel">
                          <a:commandButton id="Match"
                                value="Match!"
                               action="#{searchBean.matchDream(user.userId, _dream.dreamId)}"
      
                              />
      
                          <rich:panel id="datatablepanel">
                              <h:dataTable id="results2" var="_searchResult" value="#{searchResultsBean.getSearchResults()}">
                                  <h:column>
                                      <s:link value="#{_searchResult.name}" view="/DreamSearchItem.xhtml">
                                          <f:param name="id" value="#{_searchResult.id}"/>
                                      </s:link>
                                  </h:column>
                              </h:dataTable>
                          </rich:panel>
      
                   </a:form>
      
                  <a:status>
                      <f:facet name="start">
                          <h:graphicImage  value="img/aprocessing.gif"/>
      
                      </f:facet>
                  </a:status>
              </a:region>