Highlighted

Create and run a prefill service, sample boilerplate project download link is missing

kevinw83897078

03-02-2017

https://helpx.adobe.com/aem-forms/6-2/prepopulate-adaptive-form-fields.html

Create and run a prefill service

The prefill service is an OSGi bundle. You create the OSGi bundle, upload, and install it to AEM Forms bundles. Before you get started with creating the bundle:

  • Download the AEM 6.2 Forms Client SDK from Adobe public repository.
  • Download the boilerplate package (Prefill-Sumbit-XMLsAndContentPackage.zip)
  • Place the data xml (prefill XML) file in the crx-repository. You can place the file at any location in the \contents folder of crx-repository .

there is no link to download boilerplate project !!!!

Replies

Highlighted

Khushwant_Singh

03-02-2017

There is a DOWNLOAD section in the article after section - Adaptive form using XFA form template. It contains link to download the boilerplate package. The name of the boilerplate package zip is Prefill-Sumbit-XMLsAndContentPackage.zip. Kindly take a look. If you still face the issue, use direct link https://helpx.adobe.com/aem-forms/6-2/prepopulate-adaptive-form-fields/_jcr_content/main-pars/downlo....

Regards,
Khushwant Singh

Highlighted

joell91868939

04-04-2017

Was the boilerplate zip ever located? I found the zip file provides examples for preloading data via URL. I did not see anything related to an example of a prefill service.

 

Specifically AdaptiveFormContainer (configuration) => Prefill Service

Thanks

Joel

Highlighted

user2062153

13-02-2018

Sample prefill service

package com.adobe.test;

import com.adobe.forms.common.service.DataXMLOptions;

import com.adobe.forms.common.service.DataXMLProvider;

import com.adobe.forms.common.service.FormsException;

import java.io.InputStream;

import javax.jcr.Node;

import org.apache.felix.scr.annotations.Component;

import org.apache.felix.scr.annotations.Service;

import org.apache.sling.api.resource.NonExistingResource;

import org.apache.sling.api.resource.Resource;

import org.apache.sling.api.resource.ResourceResolver;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

@Component(

  immediate = true,

  metatype = true,

  label = "Default Form Prefill service"

)

@Service({DataXMLProvider.class})

public class Prefill implements DataXMLProvider {

  private Logger logger = LoggerFactory.getLogger(Prefill.class);

  public Prefill() {

  }

  public InputStream getDataXMLForDataRef(DataXMLOptions options) throws FormsException {

  if (options.getDataRef() == null | "".equals(options.getDataRef())) {

  Resource formResource = options.getFormResource();

  ResourceResolver resolver = formResource.getResourceResolver();

  InputStream result = null;

  try {

  String nodePath = "/content/prefillservice.xml";

  Resource fileResource = resolver.resolve(nodePath);

  if (fileResource instanceof NonExistingResource) {

  return null;

  } else {

  Node jcrNode = (Node)fileResource.adaptTo(Node.class);

  Node jcrContent = jcrNode.getNode("jcr:content");

  result = jcrContent.getProperty("jcr:data").getBinary().getStream();

  return result;

  }

  } catch (Exception var9) {

  this.logger.warn("unable to read data for the dataRef ");

  throw new FormsException(var9);

  }

  } else {

  return null;

  }

  }

  public String getServiceName() {

  return "myServiceName";

  }

  public String getServiceDescription() {

  return "My Service";

  }

}

Highlighted

prabuj201987

15-02-2018

Hi Vijay, Have tried to create a service and deploy it, but its not available for selection in Adaptive form.

Can you share the complete project with pom.xml?

Highlighted

user2062153

16-02-2018

Currently, I am unable to share the complete project. Did you included package in export path?

<plugin>

  <groupId>org.apache.felix</groupId>

  <artifactId>maven-bundle-plugin</artifactId>

  <extensions>true</extensions>

  <configuration>

  <instructions>

  <Bundle-SymbolicName>com.adobe.qe.af.af-qe-core-bundle</Bundle-SymbolicName>

  <Export-Package>

  com.adobe.test.*

  </Export-Package>

  <Import-Package>

  com.adobe.aemds.guide.progressive.* 

  </Import-Package>

  </instructions>

  </configuration>

  </plugin>

Highlighted

prabuj201987

16-02-2018

Hi Vijay. Tried your suggestion still not working. Below is my pom.xml. Please let me know if anything is missing.

Actually this is the first time i am creating a custom osgi service, if you are unable to share the code kindly point me to appropriate tutorial which would be really helpful.

Highlighted

jagjeetthukral

18-02-2018

prabuj201987

I think I had a similar problem a few days back. In my case the bundle was getting active but the pre-fill service I created was not getting active/satisfied, due to run-time dependencies of some class (some class related to w3c dom document, if I remember correctly).

Please check if you are also facing something similar, where some run-time dependencies are missing.

Hope this helps !!!

Cheers,

Jagjeet Singh

AEM Forms Blog