API Quick Starts (Code Examples) > Forms Service API Quick Starts > Quick Start: Rendering an HTML form using the Java API

Quick Start: Rendering an HTML form using the Java API
The following code example renders an HTML form using the Forms ES service Java API. A toolbar is added to the HTML form as well as two file attachments. (See Rendering Forms as HTML.)
/*
 * This Java Quick Start uses the following JAR files
 * 1. adobe-forms-client.jar
 * 2. adobe-livecycle-client.jar
 * 3. adobe-usermanager-client.jar
 * 
 *  (Because Forms quick starts are implemented as Java servlets, it is 
 *  not necessary to include J2EE specific JAR files - the Java project
 *  that contains this quick start is exported as a WAR file which
 *  is deployed to the J2EE application server)
 *  
 *  These JAR files are located in the following path:
 * <install directory>/Adobe/LiveCycle8/LiveCycle_ES_SDK/client-libs
 * 
 * For complete details about the location of these JAR files, 
 * see "Including LiveCycle ES library files" in Programming with LiveCycle ES
 */
import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.adobe.livecycle.formsservice.client.*;
import java.util.*;
import java.io.InputStream;
import com.adobe.idp.Document;
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;
import java.io.FileInputStream;
 
 
public class RenderHTMLForms extends HttpServlet implements Servlet {
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
			doPost(req,resp); 
	}
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
			
			try{
			
				//Set connection properties required to invoke LiveCycle ES	
				Properties connectionProps = new Properties();
				connectionProps.setProperty("DSC_DEFAULT_EJB_ENDPOINT", "jnp://localhost:1099");
				connectionProps.setProperty("DSC_TRANSPORT_PROTOCOL","EJB");          
				connectionProps.setProperty("DSC_SERVER_TYPE", "JBoss");
				connectionProps.setProperty("DSC_CREDENTIAL_USERNAME", "administrator");
				connectionProps.setProperty("DSC_CREDENTIAL_PASSWORD", "password");
			
				//Create a FormsServiceClient object
				ServiceClientFactory myFactory = ServiceClientFactory.createInstance(connectionProps);
				FormsServiceClient formsClient = new FormsServiceClient(myFactory); 
		
				//Set parameter values for the renderHTMLForm method
				String formName = "Loan.xdp";  
				byte[]	cData = "".getBytes();
				Document oInputData = new Document(cData);
				String userAgent = "" ;
									
				//Create an HTMLRenderSpec object to store HTML run-time options
				HTMLRenderSpec htmlRS = new HTMLRenderSpec();
				htmlRS.setHTMLToolbar(HTMLToolbar.Vertical);
														
				//Specify the locale value
				htmlRS.setLocale("en_US");
				
				//Render the HTML form within full HTML tags
				htmlRS.setOutputType(OutputType.FullHTMLTags);
																
				//Specify URI values
				URLSpec uriValues = new URLSpec(); 
				uriValues.setApplicationWebRoot("http://localhost:8080/FormsServiceClientApp");
				uriValues.setContentRootURI("C:\\Adobe");
				uriValues.setTargetURL("http://localhost:8080/FormsServiceClientApp/HandleData");
								
				//Specify file attachments
				FileInputStream myForm = new FileInputStream("C:\\Attach1.txt"); 
				Document attachment1 = new Document(myForm);
				FileInputStream myForm2 = new FileInputStream("C:\\Attach2.txt"); 
				Document attachment2 = new Document(myForm2);
				String fileName = "Attach1.txt";
				String fileName2 = "Attach2.txt";
					
				Map fileAttachments = new HashMap();
				fileAttachments.put(fileName, attachment1); 
				fileAttachments.put(fileName2, attachment2); 
						
				//Invoke the renderHTMLForm method
				FormsResult formOut = formsClient.renderHTMLForm(
					formName,               //formQuery
					TransformTo.MSDHTML,	//transformTo
					oInputData, 			//inDataDoc
					htmlRS,					//renderHTMLSpec
					userAgent,				//User Agent
					uriValues,				//urlSpec
					fileAttachments			//attachments
					);
		
				//Create a Document object that stores form data
				Document myData = formOut.getOutputContent();
		
				//Get the content type of the response and
				//set the HttpServletResponse object’s content type
				String contentType = myData.getContentType(); 
				resp.setContentType(contentType);
		
				//Create a ServletOutputStream object
				ServletOutputStream oOutput = resp.getOutputStream();
		
				//Create an InputStream object
				InputStream inputStream = myData.getInputStream();
		
				//Get the size of the InputStream object
				int size = inputStream.available();
		
				//Create and populate a byte array	
				byte[] data = new byte[size];
				inputStream.read(data);
			
				//Write the data stream to the web browser		
				 oOutput.write(data);
		
				}catch (Exception e) {
					 System.out.println("The following exception occurred: "+e.getMessage());
					 }
			}
}
 
 
 
 

API Quick Starts (Code Examples) > Forms Service API Quick Starts > Quick Start: Rendering an HTML form using the Java API

Programming with LiveCycle ES (LiveDocs)
Adobe LiveCycle ES Update 1

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/livecycle/8.2/programLC/programmer/help/000076.html