03-07-2012 05:51 AM
<config evaluator="model-type" condition="cm:content">
<forms>
<form id="search">
<field-visibility>
<!– … (other fields here) –>
<show id="path"/>
</field-visibility>
<appearance>
<!– … (other fields here) –>
<field id="path" label="Path">
<control template="/org/alfresco/components/form/controls/association.ftl" />
</field>
</appearance>
</form>
</forms>
</config>
ERROR [freemarker.runtime] [http-8080-36] Template processing error: "Expression field.endpointType is undefined on line 22, column 20 in org/alfresco/components/form/controls/association.ftl."
Expression field.endpointType is undefined on line 22, column 20 in org/alfresco/components/form/controls/association.ftl.
The problematic instruction:
———-
==> ${field.endpointType} [on line 22, column 18 in org/alfresco/components/form/controls/association.ftl]
in include "${field.control.template}" [on line 90, column 7 in org/alfresco/components/form/form.lib.ftl]
in user-directive renderField [on line 121, column 13 in org/alfresco/components/form/form.lib.ftl]
in user-directive formLib.renderSet [on line 23, column 16 in org/alfresco/components/form/form.get.html.ftl]
in user-directive formLib.renderFormContainer [on line 20, column 7 in org/alfresco/components/form/form.get.html.ftl]
———-
03-07-2012 03:01 PM
03-12-2012 10:11 AM
11-29-2012 11:38 AM
08-16-2014 02:26 PM
FormFilter
and a few dirty tricks. I tried and put all the info in this post.
<extension>
<modules>
<module>
<id>Main module of my custom extension</id>
<version>${project.version}</version>
<auto-deploy>true</auto-deploy>
<customizations>
<customization>
<!– Order matters here! target before source, always! –>
<targetPackageRoot>org.alfresco</targetPackageRoot>
<sourcePackageRoot>my-module</sourcePackageRoot>
</customization>
</customizations>
</module>
</modules>
</extension>
<alfresco-config>
<!– Search form
| OVERRIDES: webapps/share/WEB-INF/classes/alfresco/share-form-config.xml
| OVERRIDES: webapps/share/WEB-INF/classes/alfresco/team-config.xml
–>
<config evaluator="model-type" condition="cm:content">
<forms>
<!– Search form –>
<form id="search">
<field-visibility>
<show id="searchInFolder" force="true" />
</field-visibility>
<appearance>
<field id="searchInFolder" label="Search in">
<control template="/org/alfresco/components/form/controls/association.ftl" />
</field>
</appearance>
</form>
</forms>
</config>
</alfresco-config>
searchInFolder
) in the content model, you could create a type or an aspect with such association (modulo the namespace), or create a form filter like I did.
package my.project.forms;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.forms.AssociationFieldDefinition;
import org.alfresco.repo.forms.Field;
import org.alfresco.repo.forms.Form;
import org.alfresco.repo.forms.FormData;
import org.alfresco.repo.forms.processor.AbstractFilter;
import org.alfresco.repo.forms.processor.node.ContentModelField;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class SearchInFolderFilter extends AbstractFilter<Object, NodeRef> {
private static final Log logger = LogFactory.getLog(SearchInFolderFilter.class);
@Override
public void beforeGenerate(Object item, List<String> fieldStringList,
List<String> forcedFieldStringList, Form form,
Map<String, Object> contextMap) {
logger.debug("beforeGenerate");
}
@Override
public void afterGenerate(Object item, List<String> fieldStringList,
List<String> forcedFieldStringList, Form form,
Map<String, Object> contextMap) {
logger.debug("afterGenerate");
try {
if (fieldStringList.contains("searchInFolder")) {
AssociationFieldDefinition associationFieldDefinition = new AssociationFieldDefinition("searchInFolder", "cm:folder", AssociationFieldDefinition.Direction.TARGET);
associationFieldDefinition.setDataKeyName("searchInFolder");
associationFieldDefinition.setLabel("searchInFolder");
Field field = new ContentModelField(associationFieldDefinition, Collections.EMPTY_LIST);
form.addField(field);
}
} catch (Exception e) {
logger.error("There was a problem creating the searchInFolder field", e);
}
}
@Override
public void beforePersist(Object item, FormData formData) {
logger.debug("beforePersist");
}
@Override
public void afterPersist(Object item, FormData formData,
NodeRef persistedObjectNodeRef) {
logger.debug("afterPersist");
}
}
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="searchInFolderFilterNode"
class="my.project.forms.SearchInFolderFilter"
parent="baseFormFilter">
<property name="filterRegistry" ref="nodeFilterRegistry" />
</bean>
<bean id="searchInFolderFilterType"
class="my.project.forms.SearchInFolderFilter"
parent="baseFormFilter">
<property name="filterRegistry" ref="typeFilterRegistry" />
</bean>
</beans>
searchInFolder
is not interpreted by Alfresco in the search. In order to get it to work, I will put searchInFolder
(which is a node reference of the folder that was selected by the user) in rootNode
(which is the root node from where the search query is applied).searchInFolder
before the "serialization".
/**
* Advanced Search component.
*
* @namespace Alfresco
* @class Alfresco.AdvancedSearch
*
* CALLED AFTER: webapps/share/components/search/advsearch.js
*/
(function()
{
/**
* YUI Library aliases
*/
var Dom = YAHOO.util.Dom;
YAHOO.lang.augmentObject(Alfresco.AdvancedSearch.prototype,
{
/**
* Event handler that gets fired when user clicks the Search button.
*
* @method onSearchClick
* @param e {object} DomEvent
* @param obj {object} Object passed back from addListener method
*/
onSearchClick: function ADVSearch_onSearchClick(e, obj)
{
// retrieve form data structure directly from the runtime
var formData = this.currentForm.runtime.getFormData();
// add DD type to form data structure
formData.datatype = this.currentForm.type;
// Clean association.ftl data from the formData, it is useless for our purpose
delete formData.assoc_searchInFolder_added;
delete formData.assoc_searchInFolder_removed;
// Retrieve the node ref of the selected "search in" folder, it is in
// the hidden input of "association.ftl" that has no name. In order to
// find it, use one of the two useless (in our case) fields:
// "assoc_searchInFolder_added" and "assoc_searchInFolder_removed" in
// order to deduce the id of our useful field.
var searchInFolder_value = null;
try {
var searchInFolder_added_id = document.getElementsByName("assoc_searchInFolder_added")[0].id;
var searchInFolder_id = searchInFolder_added_id.substring(0, searchInFolder_added_id.length - "-cntrl-added".length);
searchInFolder_value = document.getElementById(searchInFolder_id).value;
} catch (err) {
// Something is probably undefined…
alert("Something is probably undefined - " + err.message)
}
// build and execute url for search page
var url = YAHOO.lang.substitute(Alfresco.constants.URL_PAGECONTEXT + "{site}search?t={terms}&q={query}&r={repo}&searchInFolder={searchInFolder}",
{
site: (this.options.siteId.length !== 0 ? ("site/" + this.options.siteId + "/") : ""),
terms: encodeURIComponent(Dom.get(this.id + "-search-text").value),
query: encodeURIComponent(YAHOO.lang.JSON.stringify(formData)),
repo: this.options.searchRepo.toString(),
searchInFolder : searchInFolder_value == null?"":searchInFolder_value
});
window.location.href = url;
}
}, true);
})();
<#– OVERRIDES: webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/search/advsearch.get.html.ftl
–>
<@markup id="custom-share-js" target="js" action="after">
<@script src="${url.context}/res/my-module/components/search/advsearch.js" group="search"/>
</@>
rootNode
argument before calling the Alfresco search web script.
/**
* Search component GET method
*/
function main()
{
var search = widgetUtils.findObject(model.widgets, "id", "Search");
if (page.url.args["searchInFolder"] != null && page.url.args["searchInFolder"] != "") {
search.options.searchRootNode = page.url.args["searchInFolder"];
}
}
main();
getSearchResults
from <em>search.lib.js</em>, a 200 lines js function inside a 1000 lines script that is imported as a resource, so you can't override it without taking the whole lot in your project… it is about choosing between two evils for working this side effect around)…
// When "seach in" folder is selected and "key word" field is empty, we set it to "*" so it will return all the results
var searchText = encodeURIComponent(Dom.get(this.id + "-search-text").value);
if (searchInFolder_value != null && searchInFolder_value != "" && searchText == "") {
searchText = "*";
}
// build and execute url for search page
var url = YAHOO.lang.substitute(Alfresco.constants.URL_PAGECONTEXT + "{site}search?t={terms}&q={query}&r={repo}&searchInFolder={searchInFolder}",
{
site: (this.options.siteId.length !== 0 ? ("site/" + this.options.siteId + "/") : ""),
terms: searchText,
query: encodeURIComponent(YAHOO.lang.JSON.stringify(formData)),
repo: this.options.searchRepo.toString(),
searchInFolder : searchInFolder_value == null?"":searchInFolder_value
});
06-30-2017 05:15 AM
does this work for alfresco CE 5.2?
07-29-2015 08:59 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.