cancel
Showing results for 
Search instead for 
Did you mean: 

Backoffice clone : passing context data to configurableFlowWizard

Former Member

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

  1. editorarea action context " action action-id="com.hybris.cockpitng.action.clone"property="currentObject"

  2. 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.

Accepted Solutions (1)

Accepted Solutions (1)

former_member625836
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

Hi ,

did you get a solution to this one? Could you please share the steps you used to achieve this. I am trying to bring up a "clone-wizard" (a custom component).

Thanks, Pratiusha

Former Member
0 Kudos

Yes, follow the steps i have posted which version you are using 5,0 or 6.0 ?

0 Kudos

I am using 6.4.

Former Member
0 Kudos

Hi ,

Did you get any solution for create-wizard? after the above steps create-wizard got impacted in my case as well. Do you have any solution for this?

TIA, Cheers Anil

Former Member
0 Kudos

i didn't reuse the create wizard , i created a custom component and called the confguration through code . please refer here Thanks Seb

Former Member
0 Kudos

Thanks it worked :)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Sebin,

For the wz:prepare id="eventPrepare" , did you include them in the component="create-wizard"? Thanks

Former Member
0 Kudos

I create a clone-wizard which is similar to create-wizard and called it through settings within the code in action class.

Former Member
0 Kudos

To create a clone-wizard component what do I have to do? And how do you call it from your action class?

Former Member
0 Kudos

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.

Former Member
0 Kudos

the event model (product model ) comes to action class , from the property "currentObject" set in editorareaactions component as shown below editorarea action context " action action-id="com.hybris.cockpitng.action.clone"property="currentObject"

Former Member
0 Kudos

Hi Sebin,

I`m having an issue importing com.web.core.model.EventModel in ee. Which extension does have it? Thanks.

Former Member
0 Kudos

, the eventmodel is a composed item type created extending the product model it's not available in any extension

Former Member
0 Kudos

Ok. Thank you,

Former Member
0 Kudos

Hi Sebin,

For editorarea action context " action action-id="com.hybris.cockpitng.action.clone"property="currentObject"

Do you have the backoffice config syntax?

Thanks again.