on 03-18-2017 6:20 PM
Hi All,
Hybris version 5.7.13
i have created a clone action button in my custom product editor area. Below is the configuration and code
editorarea action context " action action-id="com.hybris.cockpitng.action.clone"property="currentObject"
definition.xml for action
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<action-definition id="com.hybris.cockpitng.action.clone"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.hybris.com/schema/cockpitng/action-definition.xsd">
<name>Clone Action</name>
<description>Action providing default implementation of clone operationfrom create operation.</description>
<author>hybris</author>
<version>1.0</version>
<actionClassName>com.web.event.actions.clone.CloneAction</actionClassName>
<sockets>
<input id="currentObject" type="com.web.core.model.EventModel" />
<output id="wizardContext" type="java.util.Map" />
</sockets>
<inputType>java.lang.Object</inputType>
<outputType>java.lang.Object</outputType>
<iconUri>icons/icon_action_event_clone_default.png</iconUri>
<iconHoverUri>icons/icon_action_event_clone_default.png</iconHoverUri>
<iconDisabledUri>icons/icon_action_event_clone_disabled.png
</iconDisabledUri>
</action-definition>
3.CUSTOM ACTION PERFORM METHOD
public ActionResult<Object> perform(ActionContext<Object> ctx) {
ActionResult<Object> result = null;
if ((ctx.getData() instanceof EventModel))
{
final EventModel data = (EventModel) ctx.getData();
final Map<String, Object> contextMap = new HashMap<>();
contextMap.put(ConfigurableFlowContextParameterNames.TYPE_CODE.getName(), "Event");
contextMap.put("name", data.getName());
contextMap.put("summary", data.getSummary());
sendOutput("wizardContext",contextMap);
System.out.println(ctx.getParameter("ctx.name"));
result = new ActionResult<>(ActionResult.SUCCESS,data);
}
else {
result = new ActionResult<>(ActionResult.ERROR);
}
return result;
}
WIDGET CONNECTION
<widget-connection sourceWidgetId="STUB_com.hybris.cockpitng.action.clone" outputId="wizardContext" targetWidgetId="configurableFlow" inputId="context"/>
cockpit-config.xml for the context parameters to load
<wz:prepare id="eventPrepare">
<wz:initialize property="newEvent" type="ctx.TYPE_CODE" />
<wz:assign property="newEvent.name" value="ctx.name" />
<wz:assign property="newEvent.summary" value="ctx.summary" />
</wz:prepare>
After trying the above method to clone a object and pre fill the context through hashmap to a configurable flow wizard . The values are send through the socket to output but not gettting populated in the wizard. Can any one guide me if i am doing anything wrong in the procedure. ?
Attached the image of the wizard after clicking the action, in fact the TYPE_CODE is set in the contextMap opens the exact wizard belong to the TYPE_CODE except the data.
Hi ,
The "problem" is that you are dealing with localized attributes. An editor for localized values expects a map with locale as key and value for it as value. You send it as data.getName())
which returns a value for current session locale. So: editor expects a map you provide a single java.lang.String
value. You need to provide a value properly. I can see two solution for you:
you might put map into context in your actions perform
method; this map should contain values for each localization available in system; you might take a look at de.hybris.platform.platformbackoffice.accessors.LocalizedModelPropertyAccessor#read
method to see how it may be done
you might also use ExpressionResolverFactory to achieve the same (`expressionResolverFactory` is a spring bean defined in CockpitNG):
private ExpressionResolverFactory expressionResolverFactory;
public Object readLocalizedValue(final Object data, final String attribute)
{
return expressionResolverFactory.createResolver().getValue(data, attribute);
}
@Required
public void setExpressionResolverFactory(final ExpressionResolverFactory expressionResolverFactory)
{
this.expressionResolverFactory = expressionResolverFactory;
}
public ActionResult<Object> perform(final ActionContext<Object> ctx) {
// ...
contextMap.put("name", readLocalizedValue(data, EventModel.NAME);
contextMap.put("summary", readLocalizedValue(data, EventModel.SUMMARY));
// ...
}
Hope it helped, Jacek
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi .
Thanks!
It Worked!. I used the expression resolver factory. Post the changes, the Create Action got impacted ,as i was using same" create-wizard" Component for both create and copy.
Since the cockpit-config.xml has the
<wz:assign property="newEvent.name" value="ctx.name" />
create operation is expecting map as out put.
So Jackey , instead of modifying create action how can i change the ConfigContext from actions, or is there any other way to open a custom wizard component for this action.
Thanks Sebin
i didn't reuse the create wizard , i created a custom component and called the confguration through code . please refer here Thanks Seb
Hi Sebin,
For the wz:prepare id="eventPrepare" , did you include them in the component="create-wizard"? Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
Im trying to follow the above instruction on how to clone an item type data in the backoffice, where does EventModel come from? The code cannot see com.web.core.model.EventModel.
Im using hybris 6.3 platform. Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
1 | |
1 | |
1 | |
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.