1

I am creating a widget in backoffice on HYBRIS.

After the generation of the extension trainingbackoffice I added it in the localxtension.xml file as following :

<extensions>
<path dir='${HYBRIS_BIN_DIR}' autoload='false' />
<extension name='mcc' />
<extension name='adaptivesearchsolr' />
<extension name='adaptivesearchbackoffice' />
<extension name='adaptivesearchsamplesaddon' />
<extension name='commerceservicesbackoffice' />
<extension name='solrfacetsearchbackoffice' />
<extension name='solrserver' />
<!-- <extension name='yacceleratorcockpits' /> -->
<!-- <extension name='yacceleratorinitialdata' /> -->
<!-- <extension name='yacceleratorstorefront' /> -->
<extension name='ycommercewebservices' />
<extension name='ycommercewebservicestest' />
<extension name='electronicsstore' />
<extension name='apparelstore' />
<extension name='captchaaddon' />
<extension name='liveeditaddon' />
<extension name='acceleratorwebservicesaddon' />
<extension name='commerceorgsamplesaddon' />
<extension name='orderselfserviceaddon' />
<extension name='rulebuilderbackoffice' />
<extension name='couponbackoffice' />
<extension name='droolsruleengineservices' />
<extension name='couponfacades' />
<extension name='promotionenginesamplesaddon' />
<extension name='assistedservicestorefront' />
<extension name='assistedserviceyprofileaddon' />
<extension name='assistedservicecustomerinterestsaddon' />
<extension name='assistedservicepromotionaddon' />
<extension name='customerticketingaddon' />
<extension name='customersupportbackoffice' />
<extension name='eventtrackingwsaddon' />
<extension name='hybrisanalyticsaddon' />
<extension name='yprofileeventtrackingws' />
<extension name='yprofileeventadapter' />
<extension name='yprofileprocessadapter' />
<extension name='privacyoverlayeraddon' />
<extension name='yaasconfigurationbackoffice' />
<extension name='textfieldconfiguratortemplatebackoffice' />
<extension name='textfieldconfiguratortemplateaddon' />
<extension name='cmswebservices' />
<extension name='smarteditwebservices' />
<extension name='cmssmarteditwebservices' />
<extension name='permissionswebservices' />
<extension name='smarteditaddon' />
<extension name='cmssmartedit' />
<extension name='consignmenttrackingaddon' />
<extension name='consignmenttrackingmockaddon' />
<extension name='consignmenttrackingbackoffice' />
<extension name='notificationaddon' />
<extension name='customerinterestsaddon' />
<extension name='stocknotificationaddon' />
<extension name='configurablebundleaddon' />
<extension name='previewpersonalizationweb' />
<extension name='personalizationcmsweb' />
<extension name='personalizationsmartedit' />
<extension name='personalizationsampledataaddon' />
<extension name='personalizationyprofile' />
<extension name='personalizationpromotions' />
<extension name='personalizationpromotionsweb' />
<extension name='personalizationservicesbackoffice' />
<extension name='personalizationpromotionsbackoffice' />
<extension name='personalizationcmsbackoffice' />
<extension name='personalizationintegrationbackoffice' />
<extension name='assistedserviceatddtests' />
<extension name='promotionengineatddtests' />
<extension name='textfieldconfiguratortemplateatddtests' />
<extension name='configurablebundleatddtests' />
<extension name='configurablebundlecockpits' />
<extension name='pcmbackofficesamplesaddon' />


<extension name='mcc' />
<extension name="hmc" />


<extension name='trainingcockpits'/>
<extension name='trainingcore'/>
<extension name='trainingfacades'/>
<extension name='trainingfulfilmentprocess'/>
<extension name='traininginitialdata'/>
<extension name='trainingstorefront'/>
<extension name='trainingtest'/>

<extension name='trainingbackoffice'/>

</extensions>

and I created a controller for the widget as following :

 package org.training.widgets.mysearch;

 import java.util.List;

 import org.training.service.SearchService;
 import org.zkoss.zk.ui.event.Events;
 import org.zkoss.zk.ui.select.annotation.WireVariable;
 import org.zkoss.zul.Messagebox;
 import org.zkoss.zul.Textbox;

 import com.hybris.cockpitng.annotations.ViewEvent;
 import com.hybris.cockpitng.util.DefaultWidgetController;



 /* @author scharafi
 *
 */
 public class MySearchController extends DefaultWidgetController
 {
private Textbox searchInput;
@WireVariable
private SearchService searchService;

@ViewEvent(componentID = "searchBtn", eventName = Events.ON_CLICK)
public void doSearch() throws InterruptedException
{
    final List<String> result = searchService.search(searchInput.getText());
    Messagebox.show(result.get(0));
}

public Textbox getSearchInput()
{
    return searchInput;
}

public void setSearchInput(final Textbox searchInput)
{
    this.searchInput = searchInput;
}

public SearchService getSearchService()
{
    return searchService;
}

public void setSearchService(final SearchService searchService)
{
    this.searchService = searchService;
}
}

and I added the controller in definitions.xml as following :

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<widget-definition id="org.training.widgets.mysearch" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.hybris.com/schema/cockpitng/widget-definition.xsd">

<controller class="org.training.widgets.mysearch.MySearchController"/>


<name>My Search</name>
<description>My own search widget.</description>
<defaultTitle>Search</defaultTitle>
<author>CHARAFI Saad</author>
<version>0.1</version>

</widget-definition>

After having run the command ant clean all the build does not pass.

And errors appear in the console as following :

[yjavac] 1. ERROR in C:\hybris\hybris\bin\custom\trainingbackoffice\src\org\training\widgets\mysearch\MySearchController.java (at line 6)
   [yjavac]     import org.zkoss.zk.ui.event.Events;
   [yjavac]            ^^^^^^^^^
   [yjavac]     The import org.zkoss cannot be resolved

The error is applied on all imports of zul

UPDATE :

Here is extensioninfo.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<extensioninfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="extensioninfo.xsd">

<extension abstractclassprefix="Generated" classprefix="Trainingbackoffice" managername="TrainingbackofficeManager" managersuperclass="de.hybris.platform.jalo.extension.Extension" name="trainingbackoffice" usemaven="false">

    <!-- you should add all required extensions to this list, except platform extensions which are automatically required -->
    <!-- <requires-extension name="cms"/> -->

    <requires-extension name="backoffice"/>


    <coremodule generated="true" manager="org.training.jalo.TrainingbackofficeManager" packageroot="org.training"/>

    <meta key="backoffice-module" value="true"/>

</extension>

CHARAFI Saad
  • 1,340
  • 3
  • 16
  • 36

3 Answers3

5

Your class is defined in a global context, but ZK Framework is only available in a backoffice context.

The extension structure:

  • src ← global context (all extensions can use it)
  • backoffice/src ← backoffice context (only backoffice extensions can use it)

Move your classes which depend on ZK Framework from src to backoffice/src.


Why ZK Framework is only available in the backoffice context? Backoffice is a web application and can use libraries located in lib and web/webroot/WEB-INF/lib directories. ZK classes are located in the web/webroot/WEB-INF/lib directory. Backoffice extensions (backoffice/src) are loaded in the web context and that is the reason why they can use ZK Framework. Classes defined in src can use only libraries located in the lib directory, so ZK classes are not available.

agabrys
  • 8,728
  • 3
  • 35
  • 73
2

How you have created your custom backoffice extension. Have you used ybackoffice template ?

The problem seems to be related with dependency issue. Kindly verify your extensioninfo.xml file. You should have dependency with backoffice extension.

extensioninfo.xml ...

<requires-extension name="backoffice"/>
Free-Minded
  • 5,322
  • 6
  • 50
  • 93
  • Thank u for ur reply, yes I used the template ybackoffice. In trainingbackoffice extensioninfo.xml the dependency exist. But in the tag extension the usemaven attribute is false. – CHARAFI Saad Apr 08 '18 at 17:59
  • I added extensioninfos.xml in the post – CHARAFI Saad Apr 08 '18 at 18:07
  • Then issue will be your file location. As suggested by @agabrys, move your controller file from src folder to backoffice/src folder. It must solved the problem. – Free-Minded Apr 09 '18 at 04:38
  • Thank you for your cooperation problem solved, but i would like why ZK framework is available only is a backoffice context – CHARAFI Saad Apr 09 '18 at 08:51
0

You can check in your setup if zkoss library is present and has not been deleted by mistake during build or something. Sometimes this creates problem with import. If this is the problem you need to add all missing libraries in your setup post which you will be able to proceed.Hope this solves your problem!