AnsweredAssumed Answered

Custom search dialog

Question asked by oltchuva on Oct 3, 2008
Latest reply on Jun 15, 2011 by flykarthick
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

   > 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



         <!– Add custom dialog –>
      <!– Launch Clinical Documents Search Dialog –>
          <action id="search_clinical_documents">
             <label>Search Clinical Documents</label>
          <action-group id="navigator_actions">
             <action idref="search_clinical_documents"/>
          <dialog name="searchClinicalDocuments"
                   page = "/jsp/extension/search-clinical-documents.jsp"
                   title="Search for Clinical Documents"
                   description="Returns list of clinical documents">
                  <button id="searchClinicalDocuments_new"
                        label="New search"

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?


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"


 package edu.fccc.sample;

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

import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.QName;

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

      protected String finishImpl(FacesContext context, String outcome) throws Exception
         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"));
      //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("{}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) { = 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 


<%@ taglib uri="" prefix="h" %>
<%@ taglib uri="" prefix="f" %>
<%@ taglib uri="/WEB-INF/alfresco.tld" prefix="a" %>
<%@ taglib uri="/WEB-INF/repo.tld" prefix="r" %>
<%@ taglib uri="" 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 rendered="#{DialogManager.bean.searchFinished == true }">
   <h:outputText value="Serach terms: "/>
   <h:outputText value="#{DialogManager.bean.searchTerms}" style="font-weight:bold"/>
   <h:dataTable var="node" value="#{DialogManager.bean.sortedNodes}"    border="1"  cellpadding="10" style="vertical-align:top; "> 
         <h:outputLink   value="/alfresco/#{node.url}" target="_blank">
            <h:outputText value="#{}" />   
That’s it.