Stepan Tuhacek
Stepan Tuhacek

Reputation: 218

Hybris component in Addon not calling controller

I created my custom form component. After I added it in the smart edit, it doesn't call controller to fillIn the form. I created itemtype MyComponentModel in *-items.xml, checked in HAC deployment, it's there. I also added annotations like in this answer

@Controller("MyComponentController")
@RequestMapping(value = ControllerConstants.Actions.Cms.MyComponent)
public class MyComponentController extends AbstractAcceleratorCMSComponentController<MyComponentModel> {

and the mapping value is in my ControllerConstants like this:

String _Prefix = "/view/"; // NOSONAR
String _Suffix = "Controller"; // NOSONAR
String MyComponent = _Prefix + MyComponentModel._TYPECODE + _Suffix; // NOSONAR

When I add it in smartedit on a page, the .jsp file is loaded (I can see some text), but as the controller isn't called

According to Hybris doc, the called method in my controller should be this:

@Override
protected void fillModel(HttpServletRequest request, Model model, MyComponentModel component) {

But it isn't called, so I'm not able to fill the form.

<div class="span-20 last">
    I can see this text
    <div class="row item_container_holder">
        <c:if test="${not empty MyForm}">
          <%--this condition is false, form is empty--%>

Note that I also added component in impex, I have updated system in HAC, I tried to sync catalogs.

INSERT_UPDATE MyComponent; $contentCV[unique = true]; uid[unique = true]       ; name                               ; &componentRef
;; MyComponent ; MyComponent ; MyComponent

EDIT:

*-items.xml

 <itemtype code="MyComponent" autocreate="true" generate="true" extends="SimpleCMSComponent"
              jaloclass="mypackage.b2c.core.jalo.components.MyComponent">
        <deployment table="MyComponents" typecode="15900"/>
        <attributes>
            <attribute qualifier="title" type="localized:java.lang.String">
                <persistence type="property" />
                <modifiers />
                <description>Localized title of the component.</description>
            </attribute>
        </attributes>
    </itemtype>

Upvotes: 2

Views: 4930

Answers (3)

sc1ientific
sc1ientific

Reputation: 1

Check extending class. Could be "Accelerator" is extra in AbstractAcceleratorCMSComponentController

Upvotes: 0

HybrisHelp
HybrisHelp

Reputation: 5810

As you said, you are trying to create this component in the addon

Make sure you followed the step I have mentioned here

Your comment: I put it on path /WEB-INF/views/responsive/cms, but I still get an error Error processing component tag. currentComponent [MyComponentModel (8796093136412@1)] exception: File [/WEB-INF/views/responsive/cms/myComponent.jsp] not found

Debug getView method of AbstractCMSAddOnComponentController to check the path.

You have to add your jsp to /youraddon/acceleratoraddon/web/webroot/WEB-INF/views/responsive/cms/myComponent.jsp, which later will be copied to your stroefront extension while build process.

Upvotes: 1

Johannes von Zmuda
Johannes von Zmuda

Reputation: 1822

The controller called for a cms component depends on the itemtype. You cannot create a JspIncludeComponent and expect a component controller for MyComponent to get called.

Try this instead:

INSERT_UPDATE MyComponent;...

Upvotes: 1

Related Questions