cancel
Showing results for 
Search instead for 
Did you mean: 

Custom search dialog

oltchuva
Champ in-the-making
Champ in-the-making
I needed a custom view to display search results. I couldn't find how to apply template to search results using web client, so I implemented a dialog that takes search terms as parameter and displays results using custom jsp

Below are details of the implementation in case someone is trying to solve a similar problem. I removed my application specific sorting and data formatting (the reason I needed custom view in the first place), but you should get an idea 😃

I also have a couple of questions; they are in in blue font

I packaged dialog as described in Packaging_And_Deploying_Extensions by placing files in the root of deployed Alfresco web application in <alfresco_home>\tomcat\webapps\alfresco

> WEB-INF
   > lib
      > custom-dialog.jar
         > alfresco
            > extension
               > web-client-config-custom.xml
         > META-INF
            > faces-config.xml
            > MANIFEST.MF
         > edu
            > fccc
               > sample
                  > SearchClinicalDocumentsDialog.class
                  > SearchClinicalDocumentsDialog$Node.class
> jsp
   > extension
      > search-clinical-documents.jsp
Q: Does anyone know how to work with Multiple web-client-config-custom.xml files

web-client-config-custom.xml

<alfresco-config>

         <!– Add custom dialog –>
    <config>
      <actions>
      <!– Launch Clinical Documents Search Dialog –>
          <action id="search_clinical_documents">
             <label>Search Clinical Documents</label>
             <image>/images/icons/view_web_project.gif</image>
             <action>dialog:searchClinicalDocuments</action>
          </action>
          <action-group id="navigator_actions">
             <action idref="search_clinical_documents"/>
          </action-group>
      </actions>
   </config>
   
    <config>   
       <dialogs>
          <dialog name="searchClinicalDocuments"
                   page = "/jsp/extension/search-clinical-documents.jsp"
                   managed-bean="SearchClinicalDocumentsDialog"
                   icon="/images/icons/submit_large.gif"
                   title="Search for Clinical Documents"
                   description="Returns list of clinical documents">
            <buttons>
                  <button id="searchClinicalDocuments_new"
                        label="New search"
                          action="#{DialogManager.bean.newSearch}"
                          disabled="#{DialogManager.bean.newSearchDisabled}"

                          />
               </buttons>
          </dialog>
       </dialogs>
    </config>   
</alfresco-config>
Q:  I used action-group "navigator_actions" to add link to the dialog, but i actually would like to add it to search drop down list under Advanced Search option. Is there an action-group for that?

faces-config.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
                              "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>

   <managed-bean>
      <managed-bean-name>SearchClinicalDocumentsDialog</managed-bean-name>
      <managed-bean-class>edu.fccc.sample.ClinicalDocumentsDialog</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
      <managed-property>
         <property-name>searchService</property-name>
         <value>#{SearchService}</value>
      </managed-property>
   </managed-bean>

</faces-config>

SearchClinicalDocumentsDialog.java
 package edu.fccc.sample;

import javax.faces.context.FacesContext;
import org.alfresco.web.bean.dialog.BaseDialogBean;

import org.alfresco.service.cmr.search.SearchParameters;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.cmr.search.ResultSetRow;
import org.alfresco.web.app.servlet.DownloadContentServlet;


public class SearchClinicalDocumentsDialog extends BaseDialogBean{
     
   private String searchTerms;
   private boolean searchFinished;
   private java.util.List<Node> sortedNodes;
   
   
   public void init (java.util.Map  parameters){
         super.init(parameters);
         searchFinished = false;
      }

      protected String finishImpl(FacesContext context, String outcome) throws Exception
      {
         startSearch();
         searchFinished = true;
         return "do nothing";
      }

      public boolean getFinishButtonDisabled()
      {
        return searchFinished;
      }

      public boolean getNewSearchDisabled(){
         return !searchFinished;
      }

      public String getFinishButtonLabel()
      {
         return "Search";
      }
     
      public String getCancelButtonLabel()
      {
         return "Finish";
      }
     
   //main method: performs search and stores result to sortedNodes
   public void startSearch(){

      sortedNodes = new java.util.ArrayList<Node>();
      
      SearchParameters searchParameters = new SearchParameters();
      searchParameters.addStore(new StoreRef("workspace", "SpacesStore"));
      searchParameters.setLanguage(this.getSearchService().LANGUAGE_LUCENE);
      //I only searched for documents with certain custom aspect; modify query to fit your model
String aspect= " +ASPECT:\"{custom.model}ClinicalReport\"";
      String text = " +TEXT:\""+ searchTerms.trim() +"\"";
      
      searchParameters.setQuery(aspect + text);
      
      ResultSet reports = this.getSearchService().query(searchParameters);
      for (ResultSetRow row: reports){
         sortedNodes.add(new Node(row));
      }
   }
   
// called when New Search button clicked – resets dialog
   public void newSearch(){
      init(new java.util.HashMap());
   }
   

         public String getSearchTerms() {
         return searchTerms;
      }

      public void setSearchTerms(String searchTerms) {
         this.searchTerms = searchTerms;
      }

      public java.util.List<Node> getSortedNodes() {
         return sortedNodes;
      }

      public void setSortedNodes(java.util.List<Node> sortedNodes) {
         this.sortedNodes = sortedNodes;
      }

      public boolean isSearchFinished() {
         return searchFinished;
      }
      public void setSearchFinished(boolean searchFinished) {
         this.searchFinished = searchFinished;
      }


   public class Node{
      String name;
      String url;
      
      public Node (ResultSetRow row){
         try {
            name = row.getValue(QName.createQName("{http://www.alfresco.org/model/content/1.0}name")).toString();
         }catch (Exception e){}

         try {
            url = DownloadContentServlet.generateBrowserURL(row.getNodeRef(), name);
         }catch (Exception e){}
//add more code

      }
      
      public String getName() {
         return name;
      }
      public void setName(String name) {
         this.name = name;
      }
      public String getUrl() {
         return url;
      }
      public void setUrl(String url) {
         this.url = url;
      }
      
   }

}
Q:  I perform search in finishImpl method because it already wrapped in transaction. When I tried to search from method triggered by additional dialog button, Alfresco threw an exception. SO I used finish method instead, but this way the flow becomes quirky (finish is not a finish and additional button resets dialog by calling init). It’d be nice to know how to do it more elegantly 

search-clinical-documents.jsp

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %>
<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>                             

<h:panelGroup rendered="#{DialogManager.bean.searchFinished == false }">
   <h:outputText value="Enter serach terms then click \"Search\":  "/>
   <h:inputText size="100" value="#{DialogManager.bean.searchTerms}" />
</h:panelGroup>
      


<h:panelGroup rendered="#{DialogManager.bean.searchFinished == true }">
   <h:outputText value="Serach terms: "/>
   <h:outputText value="#{DialogManager.bean.searchTerms}" style="font-weight:bold"/>
   <f:verbatim><BR><BR></f:verbatim>
   <h:dataTable var="node" value="#{DialogManager.bean.sortedNodes}"    border="1"  cellpadding="10" style="vertical-align:top; "> 
      <h:column>    
         <h:outputLink   value="/alfresco/#{node.url}" target="_blank">
            <h:outputText value="#{node.name}" />   
         </h:outputLink>
      </h:column>    
   </h:dataTable>
</h:panelGroup>
That’s it.

Olga
10 REPLIES 10

robain
Champ in-the-making
Champ in-the-making
Hi oltchuva,
Would it be possible to post a screen shot of what you have implemented. Thanks in advance.

Thanks
robain

oltchuva
Champ in-the-making
Champ in-the-making
Hi robain.

Enter search terms:
[img]http://photofile.ru/photo/fccc_ru/2478224/102479358.jpg[/img]

Search results displayed:
[img]http://photofile.ru/photo/fccc_ru/2478224/102479359.jpg[/img]

Simple, but that was what we needed,
Olga

robain
Champ in-the-making
Champ in-the-making
Thanks Olga.

jrippon
Champ in-the-making
Champ in-the-making
Thanks Olga,

We also needed a custom view on search results.  Your post was extremely helpful.

theorbix
Confirmed Champ
Confirmed Champ
Hi Olga…. very useful customization! I need to do something similar.

Did you package your Web Client customization in a .AMP file? Can you post the .AMP file so I can see the actual source code and modify it for my needs?

Another question: do you believe that it would be possible to call the standard Web Client search result list navigation pages from a custom search page?

In my case, I don't need to have a custom search results page: I'm satisfied with the behaviour of the current Web Client.

But I need to have a custom search page (the Advanced Search page is too complex for my users) that "calls" the standard search results page, after executing the query, to navigate in the search results set.

Do you believe this is possible?

mialfresco
Champ in-the-making
Champ in-the-making
Hi Olga,
Thanks for your contribution.
i'm also looking for the same example.\can you send the source code and deployment process of your contribution.
Please send as a zip file to my mail id    mialfresco@gmail.com

thansk for your contribution

oltchuva
Champ in-the-making
Champ in-the-making
Did you package your Web Client customization in a .AMP file? Can you post the .AMP file so I can see the actual source code and modify it for my needs?

Another question: do you believe that it would be possible to call the standard Web Client search result list navigation pages from a custom search page?

Hi Orbix,

I did not package dialog to .AMP, instead I just archived files into jar and placed it in <alfresco_home>\tomcat\webapps\alfresco\WEB-INF\lib

Did you have a chance to implement your custom search?

Thank you,
Olga

oltchuva
Champ in-the-making
Champ in-the-making
can you send the source code and deployment process of your contribution.

HI mialfresco,

I'll send compiled custom-dialog.jar to your e-mail, but actually my first post contains source code and configuration files to recreate it:
1) Compile SearchClinicalDocumentsDialog.java
2) Archive compiled class and configuration files into custom-dialog.jar
3) Place jar file to <alfresco_home>\tomcat\webapps\alfresco\WEB-INF\lib folder

This is the structure of the jar file:

      
> custom-dialog.jar
         > alfresco
            > extension
               > web-client-config-custom.xml
         > META-INF
            > faces-config.xml
            > MANIFEST.MF
         > edu
            > fccc
               > sample
                  > SearchClinicalDocumentsDialog.java
                  > SearchClinicalDocumentsDialog.class
                  > SearchClinicalDocumentsDialog$Node.class

My manifest file (the only one missing from the first post):
Manifest-Version: 1.0
Built-By: oltchuva
Class-Path: web-client-config-custom.xml

Olga

cybermakoki
Champ in-the-making
Champ in-the-making
Hi Olga,

Your post was very useful for me, thank you very much Smiley Happy

I only have a question: how did you show de total results of the search?  ("Found xx results for. …");

Thank you!