This is an automated email from the ASF dual-hosted git repository.
jleroux pushed a commit to branch release18.12 in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git The following commit(s) were added to refs/heads/release18.12 by this push: new d61fb40 Fixed: Cant search ViewEntity InventoryItemDetailForSum (OFBIZ-12193) d61fb40 is described below commit d61fb40e5679c027edb2f1b84c9954c29d92e7d0 Author: Jacques Le Roux <[hidden email]> AuthorDate: Mon Mar 8 09:38:14 2021 +0100 Fixed: Cant search ViewEntity InventoryItemDetailForSum (OFBIZ-12193) Go to Entity Engine - > search entity InventoryItemDetailForSum (view entity) -> search for entries -> an error message is shown. A SQL exception occurred running the service executeFind Thanks: Sebastian Berg Conflicts handled by hand framework/webtools/groovyScripts/entity/FindGeneric.groovy --- .../groovyScripts/entity/FindGeneric.groovy | 79 +++++++++++++++++----- 1 file changed, 62 insertions(+), 17 deletions(-) diff --git a/framework/webtools/groovyScripts/entity/FindGeneric.groovy b/framework/webtools/groovyScripts/entity/FindGeneric.groovy index d305573..be6c73b 100644 --- a/framework/webtools/groovyScripts/entity/FindGeneric.groovy +++ b/framework/webtools/groovyScripts/entity/FindGeneric.groovy @@ -25,6 +25,8 @@ import org.apache.ofbiz.entity.GenericEntityException import org.apache.ofbiz.entity.model.ModelEntity import org.apache.ofbiz.entity.model.ModelFieldType import org.apache.ofbiz.entity.model.ModelReader +import org.apache.ofbiz.entity.model.ModelViewEntity +import org.apache.ofbiz.entity.model.ModelViewEntity.ModelAlias import org.apache.ofbiz.widget.model.FormFactory import org.apache.ofbiz.widget.model.ModelForm import org.apache.ofbiz.widget.renderer.FormRenderer @@ -40,6 +42,8 @@ try { } if (modelEntity) { + List<String> fieldsToSelect = getFieldsToSelect(modelEntity) + entityName = modelEntity.entityName context.entityName = entityName ModelReader entityModelReader = delegator.getModelReader() @@ -79,22 +83,34 @@ if (modelEntity) { context.dynamicAutoEntitySearchForm = writer //prepare the result list from performFind - String dynamicAutoEntityFieldListForm = '<?xml version="1.0" encoding="UTF-8"?><forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ofbiz.apache.org/Widget-Form" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Form http://ofbiz.apache.org/dtds/widget-form.xsd">' + - '<form name="ListGeneric" type="list" target="FindGeneric" list-name="listIt" ' + - ' odd-row-style="alternate-row" default-table-style="basic-table light-grid hover-bar">' + - '<actions><service service-name="performFind">' + - '<field-map field-name="inputFields" from-field="parameters"/>' + - '<field-map field-name="entityName" value="' + entityName + '"/>' + - '</service></actions>' + - '<auto-fields-entity entity-name="' + entityName + '" default-field-type="display" include-internal="true"/>' + - '<field name="entityName"><hidden value="' + entityName + '"/></field>' + - '<field name="viewGeneric" title=" "><hyperlink target="ViewGeneric" description="view">' + - ' <auto-parameters-entity entity-name="' + entityName + '"/>' + - ' <parameter param-name="entityName" value="' + entityName + '"/>' + - '</hyperlink></field>' + - '<sort-order><sort-field name="viewGeneric"/></sort-order>' + - '</form></forms>' - //Debug.logInfo(dynamicAutoEntityFieldForm, "") + String dynamicAutoEntityFieldListForm = """<?xml version="1.0" encoding="UTF-8"?><forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ofbiz.apache.org/Widget-Form" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Form http://ofbiz.apache.org/dtds/widget-form.xsd"> + <form name="ListGeneric" type="list" target="entity/find/${entityName}" list-name="listIt" paginate-target="entity/find/${entityName}" + odd-row-style="alternate-row" default-table-style="basic-table light-grid hover-bar" header-row-style="header-row-2"> + <actions> + <service service-name="performFind"> + <field-map field-name="inputFields" from-field="parameters"/> + <field-map field-name="entityName" value="${entityName}"/>""" + if (fieldsToSelect) { + dynamicAutoEntityFieldListForm += """ + <field-map field-name="fieldList" value="${fieldsToSelect}"/>""" + } + dynamicAutoEntityFieldListForm += """ + <field-map field-name="orderBy" from-field="parameters.sortField"/> + </service> + </actions> + <auto-fields-entity entity-name="${entityName}" default-field-type="display" include-internal="true"/> + <field name="_method"><hidden value="POST"/></field> + <field name="entityName"><hidden value="${entityName}"/></field>""" + modelEntity.getFieldsUnmodifiable().each { + modelField -> + dynamicAutoEntityFieldListForm += + "<field name=\"${modelField.name}\" sort-field=\"true\"/>" + } + dynamicAutoEntityFieldListForm += """ + <field name="viewGeneric" title=" "><hyperlink target="\${groovy: 'entity/find/' + org.apache.ofbiz.entity.util.EntityUtil.entityToPath(delegator, '${entityName}', context)}" description="view"/></field> + <sort-order><sort-field name="viewGeneric"/></sort-order> + </form></forms>""" + Document dynamicAutoEntityFieldListFormXml = UtilXml.readXmlDocument(dynamicAutoEntityFieldListForm, true, true) modelFormMap = FormFactory.readFormDocument(dynamicAutoEntityFieldListFormXml, entityModelReader, dispatcher.getDispatchContext(), entityName) if (UtilValidate.isNotEmpty(modelFormMap)) { @@ -106,4 +122,33 @@ if (modelEntity) { Writer writerList = new StringWriter() dynamicAutoEntityListFormRenderer.render(writerList, context) context.dynamicAutoEntityListForm = writerList -} \ No newline at end of file +} + +def getFieldsToSelect(ModelEntity modelEntity) { + groupByFields = [] + functionFields = [] + + if (modelEntity instanceof ModelViewEntity) { + aliases = modelEntity.getAliasesCopy() + for (ModelAlias alias : aliases) { + if (alias.getGroupBy()) { + groupByFields.add(alias.getName()) + } else if (alias.getFunction()) { + functionFields.add(alias.getName()) + } + } + } + List<String> fieldsToSelect = [] + + if (groupByFields || functionFields) { + + for (String groupByField : groupByFields) { + fieldsToSelect.add(groupByField) + } + + for (String functionField : functionFields) { + fieldsToSelect.add(functionField) + } + } + return fieldsToSelect +} |
Free forum by Nabble | Edit this page |