AnsweredAssumed Answered

External Servlet for searchs [solved]

Question asked by anusk on Jul 16, 2010
Latest reply on Jul 19, 2010 by anusk
Hola a todos!
Hi all!

I'm trying to do a servlet to access Alfresco through a specific URL. The idea is to redirect to the search results page.
In the servlet I create an UIComponent of the type UISimpleSearch, an event and finally I add the searchContext to the event.
Now the problem is that this only works if the user login in alfresco and then put the URL in the browser. However if I put the URL in the browser without do the login first (and this is the functionality I need!) it doesn't works!. Alfresco goes to the Company Home space intead of shows the search results, and if I reload the page, It appears the search result title in the dashboard, but it still shows the spaces of the company home inside the "browse spaces".
I can't use webscripts to do this beacuse I need all the functionality of Alfresco then, I mean, after doing the search, the user could do everything with that documents (check-in, check-out,workflows), webscripts only retrieve the documents, but then a user won't be able to do anything with them.

This is the code inside the Servlet to do the search :

     // we almost always need this bean reference
      FacesContext fc = FacesHelper.getFacesContext(req, res, getServletContext());
      BrowseBean browseBean = (BrowseBean)FacesHelper.getManagedBean(fc, "BrowseBean");

      //Create UIComponent, and the event
       UISimpleSearch search = new UISimpleSearch();
      //test searching the word "index"
      SearchEvent sevent= new SearchEvent(search,"index",0);

     // own method to set the searchContext to the event

      fc.getApplication().getNavigationHandler().handleNavigation(fc, null, outcome);
      // perform the forward to the page processed by the Faces servlet
      String viewId = fc.getViewRoot().getViewId();
      getServletContext().getRequestDispatcher(FACES_SERVLET + viewId).forward(req, res);

Any idea why only works after the user login??

Kind regards,


Edit: I put  the line browseBean.externalAccessRefresh(); in the servlet and now when I access through the URL to Alfresco shows the CompanyHome, but when a refresh the browser appears the search results… how can I show them without refresh????