on 2019 Jul 08 11:22 AM
Request clarification before answering.
Thx for the answer, I found out about the filters too, but the didn't help me...
So, after some research I couldn't find some default hybris way (18.11) to use templates, so I thought of some possible solution, although we don't know yet if we will implement this. However I didn't want the possible solution to get lost.... In 'backoffice-cockpit-config.xml are the wizards for the 'excel-export-wizard' UI (above) defined, which define 2 steps, for the 'excelExportRenderer' and 'excelClassificationExportRenderer'. Both are spring beans, which can be overwritten eg.
<alias name="preselectableExcelExportRenderer" alias="excelExportRenderer"/>
<bean id="preselectableExcelExportRenderer" class="net.netconomy.someextension.backoffice.excel.export.wizard.renderer.MyExportRenderer" parent="abstractAttributesExportRenderer"></bean>
... same for the 'excelClassificationExportRenderer'
both Renderer make it possible to override 'populateAttributesChooserForm' which set in their last lines these attributes:
attributesForm.setAvailableAttributes(available);
attributesForm.setChosenAttributes(mandatory);
setAvailableAttributes() sets a list of 'Attribute's that are only being made available, hence left side, in the UI setChosenAttributes() are all those attributes that are selected, hence right side in the UI, which only the, mandatory once are being selected by now by hybris. Mandatory Attributes have the setMandatory property set 'true' and can not be deselected.
So we could just extend ExcelExportRenderer and ClassificationAttributesExportRenderer and override
protected void populateAttributesChooserForm(AttributeChooserForm attributesForm...) {
super.populateAttributesChooserForm(attributesForm...)
// Move *preselectable* attributes from attributesForm.getAvailableAttributes() to
// attributes.getChosenAttributes()
}
in order to accomplish, that in the UI the attributes we want are being preselected upon opening the wizard and they can also be unselected by the user...
So now we only have to figure out how we can make attributes configurable for exporting. It would be nice to create maybe some (newly created item) 'ExportConfiguration' that can be linked to all the attributes we want to export. Sth like
$classificationCatalog=SomeClassification
$classSystemVersion=systemVersion(catalog(id[default=$classificationCatalog]),version[default='1.0'])[unique=true,default=$classificationCatalog:1.0]
INSERT_UPDATE ExportConfiguration; code[unique=true]; attributeName[unique=true]; attributeDescriptor(enclosingType(code), qualifier); classificationAttribute(code,$classSystemVersion);preselect
myConfig;bodyText;Product:bodyText;;true
myConfig;productCode;Product:code;;true
myConfig;someclassifAttributes;;someclassifAttribute;true
This way we would have a link from the AttributeDescriptor to the ExportConfiguration and also from the ClassificationAttribute to ExportConfiguration by creating to between the three models
Unfortunately for the List that is returned above, each Attribute only contains Strings as qualifiers, and it's instantiation is also hardcoded into both Renderers which makes it hard to easily reference any ExportConfiguration to each attribute.
So we need to dig a little 'deeper :slight_smile:
It's quite easy to just replace from ExcelExportRender not calling it's super but copying and extending the code:
protected void populateAttributesChooserForm(...) {
....
while(...) {
if (....) {
...
mandatory.add(attribute);
} else {
available.add(this.createAttributeWithLocalizedChildren(attrDesc, supportedLanguages, false));
}
}
attributesForm.setAvailableAttributes(available);
attributesForm.setChosenAttributes(mandatory);
}
The first 'if' adds the mandatory field, the second the available once. We only need to add ONE more 'else if'
...
if (....) {
...
mandatory.add(attribute);
} else if (hasExportConfiguration(attrDesc)) {
mandatory.add(this.createAttributeWithLocalizedChildren(attrDesc, supportedLanguages, false));
} else {
available.add(this.createAttributeWithLocalizedChildren(attrDesc, supportedLanguages, false));
}
...
protected boolean hasExportConfiguration() {
return attrDesc.getExportConfig() != null && attrDesc.getExportConfig().isPreselect()
}
Now the attribute that is in the ExportConfig is also moved to the 'chosenAttributes' but with 'mandatory' set to 'false' (For simplification reason, this implementation would currently only supports ONE ExportConfiguration for ONE Attribute)
It's a little more complicated with the ClassificationAttributesExportRenderer since for the same logic to apply for the ClassificationAttributes we need to override
private CreatedNodes createClassificationAttributes(...)
but unfortunately this method is private, so we need to copy more than one method: protected populateAttributesChooserForm(...) private createClassificationClasses(...) private createClassificationAttributes(...)
to change 'createClassificationAttributes()' the same way we did above
An extension to this solution could be to provide more ExportConfigurations, eg that you could have some possibility to select between several export configurations when klicking the Export Excel button in BO/Productcockpit...
If someone has a simpler Solution, please provide it here...
(For now I will not mark this Question solved until it has been implemented successfully)
: Maybe someone who knows about the the subject can approve this solution above...
Does someone know if there are any plans to support preconfigurable Excel Export Templates in future releases?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Thomas,
The "standard" attributes, based on AttributeDescriptor, are rendered using ExcelExportRenderer class (bean id: "excelExportRenderer". ExcelExportRenderer has "requiredFilters" field which is simple java's Predicate. Every attribute which requiredFilters consider as positive (the "true" is returned by "test" method") is added to the already chosen view. You can simply create your own instance of "ExcelFilter" (which is a subclass of Predicate) and inject it to "excelExportRenderer" and it should work. You can combine multiple filters using "AndFilter".
<alias name="defaultRequiredCheckingFilter" alias="requiredCheckingFilter"/>
<bean id="defaultRequiredCheckingFilter" class="com.hybris.backoffice.excel.template.filter.OrFilter">
<property name="excelFilter1" ref="uniqueCheckingFilter"/>
<property name="excelFilter2">
<bean class="com.hybris.backoffice.excel.template.filter.AndFilter">
<property name="filters">
<util:list value-type="com.hybris.backoffice.excel.template.filter.ExcelFilter">
<ref bean="mandatoryCheckingFilter"/>
<bean class="com.hybris.backoffice.excel.template.filter.NegateFilter">
<property name="excelFilter" ref="valueCheckingFilter"/>
</bean>
</util:list>
</property>
</bean>
</property>
</bean>
As you can see current filter checks if attribute is unique ("uniqueCheckingFilter") or mandatory ("mandatoryCheckingFilter") and has no default value ("valueCheckingFilter"). You can adjust filter to your needs.
However, when it comes to classification it seems not so easy. You would need to modify com.hybris.backoffice.renderer.attributeschooser.ClassificationAttributesExportRenderer#createClassificationAttributes method or to define your classification attributes as "mandatory", then they will appear on the right side of the attribute chooser.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I've seen you answered some questions on the excel export subject. Do you have an idea how to customize the excel export in order to preselect attributes to export?
I've found the excel-export-wizard in the backoffice-cockpit-config.xml, but I am not where it makes sense to customizes both, the attributes and the classification attributes...
<context type="GenericItem" component="excel-export-wizard">
<wz:flow id="excelExportWizard" title="excel.export.wizard.title" show-breadcrumb="false" size="large">
<wz:prepare id="excelExportWizardPrepare">
<wz:initialize property="excelForm" template-bean="excelExportWizardForm"/>
<wz:initialize property="excelForm.attributesForm" template-bean="attributesForm"/>
<wz:assign property="excelForm.pageable" value="ctx.excelExportData"/>
<wz:assign property="excelForm.typeCode" value="ctx.TYPE_CODE"/>
</wz:prepare>
<wz:step id="step1" label="excel.export.wizard.attributes.label" sublabel="excel.export.wizard.attributes.sublabel">
<wz:content id="step1.content">
<wz:custom-view lang="zul">
<wz:renderer spring-bean="excelExportRenderer"/>
</wz:custom-view>
</wz:content>
<wz:navigation id="step1.navigation">
<wz:cancel/>
<wz:next/>
<wz:custom label="excel.export.wizard.button.label" handler="excelExportHandler" visible="excelForm.attributesForm.hasSelectedAttributes()">
<wz:parameter>
<wz:name>excelIncludeClassification</wz:name>
<wz:value>false</wz:value>
</wz:parameter>
</wz:custom>
</wz:navigation>
</wz:step>
</wz:flow>
</context>
<context type="Product" component="excel-export-wizard" parent="GenericItem" merge-by="type">
<wz:flow id="excelExportWizard" title="excel.export.wizard.title" show-breadcrumb="true">
<wz:prepare id="excelExportWizardPrepare">
<wz:initialize property="excelForm.classificationAttributesForm" template-bean="attributesForm"/>
</wz:prepare>
<wz:step id="step2" label="excel.export.wizard.classification.label" sublabel="excel.export.wizard.classification.sublabel">
<wz:content id="step2.content">
<wz:custom-view lang="zul">
<wz:renderer spring-bean="excelClassificationExportRenderer">
<wz:parameter>
<wz:name>itemsToExport</wz:name>
<wz:value>excelForm.getPageable().getAllResults()</wz:value>
</wz:parameter>
<wz:parameter>
<wz:name>classificationAttributesFormModelKey</wz:name>
<wz:value>excelForm.classificationAttributesForm</wz:value>
</wz:parameter>
<wz:parameter>
<wz:name>emptyAttributesMessageKey</wz:name>
<wz:value>attributechooser.excel.no.intersection</wz:value>
</wz:parameter>
<wz:parameter>
<wz:name>retrieveMode</wz:name>
<wz:value>ITEMS_INTERSECTION</wz:value>
</wz:parameter>
</wz:renderer>
</wz:custom-view>
</wz:content>
<wz:navigation id="step2.navigation">
<wz:cancel/>
<wz:back/>
<wz:custom label="excel.export.wizard.button.label" handler="excelExportHandler" visible="excelForm.attributesForm.hasSelectedAttributes()"/>
</wz:navigation>
</wz:step>
</wz:flow>
</context>
I wonder if there is a way in ExcelExportAction to preselect attributes...? When debugging I found out that ExcelExportWizardForm is instantiated after
this.sendOutput("itemsToExport", excelExportData);
is called in
public ActionResult<Pageable<? extends ItemModel>> perform(ActionContext<String> ctx) {
ActionResult<Pageable<? extends ItemModel>> result = new ActionResult("error");
this.getData(ctx).ifPresent((excelExportData) -> {
int totalCount = excelExportData.getTotalCount();
if (this.isMaxRowsExceeded(ctx, totalCount)) {
this.showMaxRowsExceeded(ctx, totalCount);
} else {
this.sendOutput("itemsToExport", excelExportData);
result.setResultCode("success");
result.setData(excelExportData);
}
});
return result;
}
After debugging even some more I found out that excelExportRenderer has a
protected populateAttributesChooserForm(...)
method which can be overwritten. And in this method
attributesForm.setChosenAttributes(mandatory)
is called... So extending the excelExportRenderer Spring-bean and calling setChosenAttributes(..) could be possible solution.
same for excelClassificationExportRenderer...
I wonder if this is the 'best' solution...
It would sure be nice to create some 'Template' that would allow simple configuration for the Export Wizard... Is there sth like that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.