cancel
Showing results for 
Search instead for 
Did you mean: 

External Servlet for searchs [solved]

anusk
Champ in-the-making
Champ in-the-making
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");
   
      outcome=OUTCOME_BROWSE;

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

     // own method to set the searchContext to the event
      browseBean.setSearchContext(sevent);

      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,

Ana


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????
3 REPLIES 3

savic_prvoslav
Champ on-the-rise
Champ on-the-rise
Now the problem is that this only works if the user login in alfresco and then put the URL in the browser
this is  normal alfresco does not allow to access if you are not logged in first.

so my advice is that you do next:
   <servlet-name>externalAccess</servlet-name>
  <servlet-class>org.alfresco.web.app.servlet.ExternalAccessServlet</servlet-class> check this inside web.xml this is servlet witch deals with /n/showDocDetails/${child.nodeRef} you get this and details dialog opens , nice. so why do not extend this servlet to post your search results.
if you are having problem with login part you can do :
loginbean.setusername("guets")
loginbean.login();

and if documents in guest homespace this would work.

anusk
Champ in-the-making
Champ in-the-making
Hi savic!

Thanks for your post.
By the way, that is what I already did. I did an external servlet based in the one that provides alfresco. The login part I know is normal, I did another external servlet which leads you to an specific node in alfresco (and of course you have to login to access alfresco). The problem is when the user login, alfresco goes to company home space first!, then you refresh the browser and goes to the search results page. I don't know why alfresco goes first to company home space.
What I want is : you put the URL in the browser, alfresco login page appears, the user login, and alfresco shows you directly the page results.

Kind regards,
Ana

anusk
Champ in-the-making
Champ in-the-making
I finally solved it.
The problem was the UIlocation was not initialized. After doing
 browseBean.updateUILocation(nodeRef);
it finally works!

Kind regards,
Ana