You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by er...@apache.org on 2010/02/16 17:42:00 UTC

svn commit: r910587 - in /ofbiz/trunk/framework: common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy example/widget/example/FormWidgetExampleLookupScreens.xml

Author: erwan
Date: Tue Feb 16 16:42:00 2010
New Revision: 910587

URL: http://svn.apache.org/viewvc?rev=910587&view=rev
Log:
The auto-completer (in lookup fields) default behavior is "%fieldValue%" (contains operation).
This allows to change the behavior to "fieldValue%"(statrWith operation) when setting to "Y" the searchTypeStartWith field

Modified:
    ofbiz/trunk/framework/common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy
    ofbiz/trunk/framework/example/widget/example/FormWidgetExampleLookupScreens.xml

Modified: ofbiz/trunk/framework/common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy?rev=910587&r1=910586&r2=910587&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy (original)
+++ ofbiz/trunk/framework/common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy Tue Feb 16 16:42:00 2010
@@ -32,7 +32,10 @@
 displayFields = context.displayFields ?: searchFields;
 searchValueFieldName = parameters.searchValueField;
 fieldValue = parameters.get(searchValueFieldName);
- 
+searchTypeStartWith = context.searchTypeStartWith;
+if( searchTypeStartWith == null){
+    searchTypeStartWith = "N";
+}
 if (searchFields && fieldValue) {
     searchFieldsList = StringUtil.toList(searchFields);
     displayFieldsSet = StringUtil.toSet(displayFields);
@@ -40,20 +43,26 @@
     displayFieldsSet.add(returnField); //add it to select fields, in case it is missing
     context.returnField = returnField;
     context.displayFieldsSet = displayFieldsSet;
-    searchFieldsList.each { fieldName -> 
-        andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER(EntityFieldValue.makeFieldValue(fieldName)), EntityOperator.LIKE, "%" + fieldValue.toUpperCase() + "%"));
+    if("Y".equals(searchTypeStartWith.toUpperCase())){
+    	searchValue = fieldValue.toUpperCase() + "%";
+    }
+    else{
+    	searchValue = "%" + fieldValue.toUpperCase() + "%";
+    }
+    searchFieldsList.each { fieldName ->
+        andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER(EntityFieldValue.makeFieldValue(fieldName)), EntityOperator.LIKE, searchValue));
     }
 }
-
+System.out.println(andExprs);
 if (andExprs && entityName && displayFieldsSet) {
     entityConditionList = EntityCondition.makeCondition(andExprs, EntityOperator.OR);
-    
-    //if there is an extra condition, add it to main condition 
+
+    //if there is an extra condition, add it to main condition
     if (context.andCondition && context.andCondition  instanceof EntityCondition) {
         entityConditionList = EntityCondition.makeCondition(context.andCondition, entityConditionList);
     }
-    
-    Integer autocompleterViewSize = Integer.valueOf(context.autocompleterViewSize ?: 10);     
+
+    Integer autocompleterViewSize = Integer.valueOf(context.autocompleterViewSize ?: 10);
     EntityFindOptions findOptions = new EntityFindOptions();
     findOptions.setMaxRows(autocompleterViewSize);
     autocompleteOptions = delegator.findList(entityName, entityConditionList, displayFieldsSet, StringUtil.toList(displayFields), findOptions, false);

Modified: ofbiz/trunk/framework/example/widget/example/FormWidgetExampleLookupScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/widget/example/FormWidgetExampleLookupScreens.xml?rev=910587&r1=910586&r2=910587&view=diff
==============================================================================
--- ofbiz/trunk/framework/example/widget/example/FormWidgetExampleLookupScreens.xml (original)
+++ ofbiz/trunk/framework/example/widget/example/FormWidgetExampleLookupScreens.xml Tue Feb 16 16:42:00 2010
@@ -41,6 +41,10 @@
                 <!-- it might be hidden based on widget.autocompleter.displayReturnField property in widget.properties -->
                 <set field="searchFields" value="[partyId, firstName, middleName, lastName, groupName]"/>
 
+                <!--  when set Y the auto-completer will search value using "fieldValue%"(statrWith operation)-->
+                <!--  the default behavior is "%fieldValue%" (contains operation) -->
+                <set field="searchTypeStartWith" value="Y"/>
+
                 <!-- optional: fields to display in the given order, default is searchFields -->
                 <set field="displayFields" value="[firstName, lastName, groupName]"/>
 
@@ -106,24 +110,24 @@
                 <property-map resource="PartyUiLabels" map-name="uiLabelMap" global="true"/>
                 <set field="title" value="${uiLabelMap.PartyLookupPartyPerson}"/>
                 <set field="queryString" from-field="result.queryString"/>
-                
+
                 <set field="viewIndex" from-field="parameters.VIEW_INDEX" type="Integer" default-value="0"/>
                 <set field="viewSize" from-field="parameters.VIEW_SIZE" type="Integer" default-value="20"/>
-                
+
                 <!-- entries needed for lookup ajax auto completer -->
                 <!-- required: entity to search in -->
                 <set field="entityName" value="PartyNameView"/>
-                
+
                 <!-- required: fields to search a match -->
                 <set field="searchFields" value="[partyId, firstName, middleName, lastName]"/>
-                
+
                 <!-- optional: field to return after user selection, default is first element of searchFields -->
                 <!-- return field might be hidden based on widget.autocompleter.displayReturnField property in widget.properties -->
                 <set field="returnField" value="partyId"/>
-                
+
                 <!-- optional: fields to display, default are searchFields -->
                 <set field="displayFields" value="[firstName, lastName]"/>
-                
+
             </actions>
             <widgets>
                 <decorator-screen name="LookupLayerPopupDecorator" location="component://common/widget/CommonScreens.xml">
@@ -136,6 +140,6 @@
                 </decorator-screen>
             </widgets>
         </section>
-    </screen>    
-    
+    </screen>
+
 </screens>
\ No newline at end of file



Re: svn commit: r910587 - in /ofbiz/trunk/framework: common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy example/widget/example/FormWidgetExampleLookupScreens.xml

Posted by Scott Gray <sc...@hotwaxmedia.com>.
Thanks Erwan!

Regards
Scott

HotWax Media
http://www.hotwaxmedia.com

On 17/02/2010, at 12:30 AM, Erwan de FERRIERES wrote:

> 
>> Hi Erwan,
>> 
>> You've forgotten to remove your println statement.
>> Also please watch your code formatting:
>> if (...) {
>>     ...
>> } else {
>>     ...
>> }
>> 
>> Thanks
>> Scott
> 
> Done at r910844. Thanks !!
> 
> -- 
> Erwan de FERRIERES
> www.nereide.biz


Re: svn commit: r910587 - in /ofbiz/trunk/framework: common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy example/widget/example/FormWidgetExampleLookupScreens.xml

Posted by Erwan de FERRIERES <er...@nereide.fr>.
> Hi Erwan,
>
> You've forgotten to remove your println statement.
> Also please watch your code formatting:
> if (...) {
>      ...
> } else {
>      ...
> }
>
> Thanks
> Scott

Done at r910844. Thanks !!

-- 
Erwan de FERRIERES
www.nereide.biz

Re: svn commit: r910587 - in /ofbiz/trunk/framework: common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy example/widget/example/FormWidgetExampleLookupScreens.xml

Posted by Scott Gray <sc...@hotwaxmedia.com>.
On 16/02/2010, at 9:42 AM, erwan@apache.org wrote:

> Author: erwan
> Date: Tue Feb 16 16:42:00 2010
> New Revision: 910587
> 
> URL: http://svn.apache.org/viewvc?rev=910587&view=rev
> Log:
> The auto-completer (in lookup fields) default behavior is "%fieldValue%" (contains operation).
> This allows to change the behavior to "fieldValue%"(statrWith operation) when setting to "Y" the searchTypeStartWith field
> 
> Modified:
>    ofbiz/trunk/framework/common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy
>    ofbiz/trunk/framework/example/widget/example/FormWidgetExampleLookupScreens.xml
> 
> Modified: ofbiz/trunk/framework/common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy?rev=910587&r1=910586&r2=910587&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy (original)
> +++ ofbiz/trunk/framework/common/webcommon/WEB-INF/actions/includes/FindAutocompleteOptions.groovy Tue Feb 16 16:42:00 2010
> @@ -32,7 +32,10 @@
> displayFields = context.displayFields ?: searchFields;
> searchValueFieldName = parameters.searchValueField;
> fieldValue = parameters.get(searchValueFieldName);
> - 
> +searchTypeStartWith = context.searchTypeStartWith;
> +if( searchTypeStartWith == null){
> +    searchTypeStartWith = "N";
> +}
> if (searchFields && fieldValue) {
>     searchFieldsList = StringUtil.toList(searchFields);
>     displayFieldsSet = StringUtil.toSet(displayFields);
> @@ -40,20 +43,26 @@
>     displayFieldsSet.add(returnField); //add it to select fields, in case it is missing
>     context.returnField = returnField;
>     context.displayFieldsSet = displayFieldsSet;
> -    searchFieldsList.each { fieldName -> 
> -        andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER(EntityFieldValue.makeFieldValue(fieldName)), EntityOperator.LIKE, "%" + fieldValue.toUpperCase() + "%"));
> +    if("Y".equals(searchTypeStartWith.toUpperCase())){
> +    	searchValue = fieldValue.toUpperCase() + "%";
> +    }
> +    else{
> +    	searchValue = "%" + fieldValue.toUpperCase() + "%";
> +    }
> +    searchFieldsList.each { fieldName ->
> +        andExprs.add(EntityCondition.makeCondition(EntityFunction.UPPER(EntityFieldValue.makeFieldValue(fieldName)), EntityOperator.LIKE, searchValue));
>     }
> }
> -
> +System.out.println(andExprs);

Hi Erwan,

You've forgotten to remove your println statement.  
Also please watch your code formatting:
if (...) {
    ...
} else {
    ...
}

Thanks
Scott