cancel
Showing results for 
Search instead for 
Did you mean: 

NG Cockpit :cannot be cast to com.hybris.cockpitng.actions.CockpitAction

Former Member
0 Kudos

Hello, I've created custom editareaactions in my custom extension(training-backoffice-config.xml) for type Customer to do some operation. To handle that action i've created my action by implementing CockpitAction< CustomerModel,CustomerModel> .

While going to editor area for type customer in backoffice, its raising class cast exception to CockpitAction.


Code: public class ApproveActions implements CockpitAction < CustomerModel,CustomerModel> { }

Also tried by implementing CockpitAction < Object,Object >...

Existing Action's and my Custom Action (Delete Action, Principal Permission Action and My Custom Action)

Class Cast Exception for CockpitAction in back office.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Problem is resolved, by taking ApproveActions Class into backoffice context

Cheers, Kishore

Answers (4)

Answers (4)

Former Member
0 Kudos

Hello Wojciech,

Sorry, what ever suggestions you mentioned that am already updated. Un fortunately i was updated incorrect code can you check this once again ... Still am facing same issue....

definition.xml

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <action-definition id="org.training.actions.ApproveActions"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:noNamespaceSchemaLocation="http://www.hybris.com/schema/cockpitng/action-definition.xsd">
 
     <name>basic.approval</name>
     <description>Approval</description>
     <author>hybris</author>
     <version>0.1</version>
 
     <actionClassName>org.training.actions.ApproveActions</actionClassName>
     <inputType>de.hybris.platform.core.model.user.CustomerModel</inputType>
     <outputType>de.hybris.platform.core.model.user.CustomerModel</outputType>
     <iconUri>icons/remove.png</iconUri>
     <settings>
         <setting key="viewMode" default-value="textOnly"/>
     </settings>
 </action-definition>
 



And in my training-backoffice-config.xml file

y:action action-id="org.training.actions.ApproveActions" property="currentObject"

Thanks!!!

former_member632755
Active Contributor
0 Kudos

Hi,

definitely the two declarations are wrong:

      <inputType>java.lang.CustomerModel</inputType>
      <outputType>java.lang.CustomerModel</outputType>

CustomerModel is not from the stadard library 😉

Beside that you have declared:

 action-id="org.training.actions.ApproveAction"

while the definition gives it annother name:

 id="org.training.actions.ApproveActions"

Cheers, Wojtek

Former Member
0 Kudos

Hello Wojciech,

      Already tried How to create actions documentation. still i facing same issue(Class cast exception to CockpitAction).  I worked out by implementing CockpitAction of generic type CustomerModel and Object. 

Here i pasted my code, These are the files ApproveActions.java, training-backoffice-config.xml and definition.xml

ApproveActions.java

 public class ApproveActions implements CockpitAction<CustomerModel, CustomerModel>
 {
 
 
     @Override
     public boolean canPerform(final ActionContext<CustomerModel> arg0)
     {
         return false;
     }
 
 
     @Override
     public String getConfirmationMessage(final ActionContext<CustomerModel> arg0)
     {
         return null;
     }
 
 
     @Override
     public boolean needsConfirmation(final ActionContext<CustomerModel> arg0)
     {
         return false;
     }
 
 
     @WireVariable
     ModelService modelService;
 
     @Override
     public ActionResult<CustomerModel> perform(final ActionContext<CustomerModel> arg0)
     {
 
         final CustomerModel customerModel = arg0.getData();
         final CustomerModel updateModel = modelService.get(customerModel);
         modelService.save(updateModel.setActive(true));
         return new ActionResult<CustomerModel>(ActionResult.SUCCESS);
     }
 }

definition.xml(training/backoffice/widgets/actions/approveactions/definition.xml)

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <action-definition id="org.training.actions.ApproveActions"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:noNamespaceSchemaLocation="http://www.hybris.com/schema/cockpitng/action-definition.xsd">
 
     <name>remove.order.line</name>
     <description>Remove Order line</description>
     <author>hybris</author>
     <version>0.1</version>
 
     <actionClassName>org.training.actions.ApproveActions</actionClassName>
     <inputType>java.lang.CustomerModel</inputType>
     <outputType>java.lang.CustomerModel</outputType>
     <iconUri>icons/remove.png</iconUri>
     <settings>
         <setting key="viewMode" default-value="textOnly"/>
     </settings>
 </action-definition>

training-backoffice-config.xml (training/resources/training-backoffice.xml)

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <config xmlns="http://www.hybris.com/cockpit/config">
 
 <context component="editorareaactions" type="Customer">
         <y:actions xmlns:y="http://www.hybris.com/cockpit/config/hybris">
             <y:group qualifier="common">
                 <y:label>actiongroup.common</y:label>
                 <y:action action-id="org.training.actions.ApproveAction" property="currentObject"/>
             </y:group>
         </y:actions>
 </context>
 
 </config>

Is this Generic type of CockpitAction is correct or nt ? Or any other solution for this issue? Let me know.... Cheers, Kishore...

former_member632755
Active Contributor
0 Kudos

Hi,

a tutorial on actions can be found here. If you cannot resolve it alone please paste the action's code (with imports) and the definiotion.xml. With no code I cannot guess the root caouse.

Cheers, Wojtek

Former Member
0 Kudos

Wojciech thanks for your reply, Please check my code comment below. And also check this Question How to restrict Actions for any type .....

Cheers Kishore