xyformsfacades Extension

The xyformsfacades extension contains classes to interact with the xyformsservices extension.

Data Transfer Objects

Legend

  • Blue: Core SAP Commerce Cloud Backofficefunctionality
  • Purple: yForms Functionality
Class Class contains
yFormDefinitionData information related to a yForm Definition item.
yFormDataData

information related to a yForm Data item.

Facades

Legend

  • Blue: Core SAP Commerce Cloud Backofficefunctionality
  • Purple: yForms Functionality

DefaultYFormFacade

The DefaultYFormFacade implements the yFormFacade interface and implements methods encapsulating and orchestrating calls to services.

DefaultProxyFacade

The DefaultProxyFacade implements the ProxyFacade interface and implements following methods:

Method Header This method:
getInlineFormHtml()

returns the HTML representation of a Form, containing both: yFormDefintion and yFormData. Depending on the parameters, representation can be a read-only Form, an empty new Form or enabled to edit, existing one.

proxy()

acts as a proxy, serving mainly static content (CSS, JS, PNG, JPEG, and so on) files and acts as an intermediary between the browser and the Orbeon XForms Engine. Thus allows you to validate content form, save form drafts and final versions.

yForm ProxyServlet

Legend

  • Blue: Core SAP Commerce Cloud Backofficefunctionality
  • Purple: yForms Functionality

This yFormProxyServlet is a facility class that allows proxying Orbeon content.

Populators

Legend

  • Blue: Core SAP Commerce Cloud Backofficefunctionality
  • Purple: yForms Functionality

These populators convert YFormDefinition and YFormData models defined in the xyformsservices extension.

Preprocessor

Legend

  • Blue: Core SAP Commerce Cloud Backofficefunctionality
  • Purple: yForms Functionality

Preprocessing is at the heart of yForm Data manipulation. It allows you to apply some modifications to yForm Data before rendering it and to inject information to yForm Data items.

Example

This example fills the yForms with current user email address before rendering and allows you to see the preprocessor's way of working.

Building the Form

Build the Form Definition using Backoffice. Proper use of yForm Data that this yForm Definition generates following structure:

yforms/contact

<?xml version=""1.0"" encoding=""UTF-8""?>
<form>
    <contact>
        <name></name>
        <surname></surname>
        <email></email>
        <phone></phone>
        <callmeback></callmeback>
        <message></message>
    </contact>
</form>

Above structure is generated by the already existing sample yForm Definition: yforms\contact.

In order to apply pre-population, create a draft yForm Data record or use already existing one. To do this, use class yFormPreprocessorStrategy, which implements requirement thanks to TransformerYFormPreprocessorStrategy.Therefore, extend the abstract class as follows:

MyYFormPreprocessorStrategy.java

package de.hybris.platform.myextension.preprocessor;

import ...;

public class MyYFormPreprocessorStrategy extends TransformerYFormPreprocessorStrategy
{
   @Override
   Protected String transform(final String xmlContent, final Map<String, Object> params) throws YFormProcessorException
   {
      String email = (String)params.get("email");

      // this is just an example, please consider an XSLT transformation or something more ad-hoc.
      Pattern p = Pattern.compile("^(.+)(<email>.*</email>)(.+)$");
      Matcher m = p.matcher(xmlContent);
      String prefix = m.group(1);
      String c = m.group(2);
      String suffix = m.group(3);
      String xml = prefix + "<email>"+email+"</email>" + suffix;
      return xml;
   }
}

Make sure that the following is a part in your client code:

MyFacade.java

package de.hybris.platform.myextension.facades;

import ...;

public class MyFacade
{
    @Resource(name = "yFormFacade")
    private YFormFacade yFormFacade;

    @Resource(name = "myYFormPreprocessorStrategy")
    private MyYFormPreprocessorStrategy strategy;

    public String getFormHtml() throws Exception
	{
       String formDataId = yFormFacade.getNewFormDataId();
       Map<String, Object> params = new HashMap<String, Object>();

       // TODO: get the email from the current logged user.
       params.put("email", "john.doe@email.com"); 
       
       String content = yFormFacade.getInlineFormHtml("yforms", "contact", YFormDataActionEnum.NEW, formDataId, strategy, params);
       return content;
    }
}

Remember to generate every form using a yFormCMSComponent or something ad-hoc and to define the bean definitions in myextension-spring.xml.

myextension-spring.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd">
    
    <alias name="defaultMyYFormPreprocessorStrategy" alias="myYFormPreprocessorStrategy"/>
    <bean id="defaultMyYFormPreprocessorStrategy"
          class="de.hybris.platform.myextension.preprocessor.MyYFormPreprocessorStrategy">
    </bean>

    <alias name="defaultMyFacade" alias="myFacade"/>
    <bean id="defaultMyFacade"
          class="de.hybris.platform.myextension.facades.MyFacade">
    </bean>
</beans>

Getting yForm Definitions for an Item

Legend

  • Blue: Core SAP Commerce Cloud Backofficefunctionality
  • Purple: yForms Functionality

Currently there is this class GetYFormDefinitionsForProductStrategy, that allows you to get yForm Definitions for a given Product.

<alias name="defaultMyYFormPreprocessorStrategy" alias="myYFormPreprocessorStrategy"/>
    <bean id="defaultMyYFormPreprocessorStrategy"
          class="de.hybris.platform.myextension.strategy.preprocessor.MyYFormPreprocessorStrategy">
    </bean>