- 在AEM表单中,访问新实例需要使用AEM Forms REST API。以下是一个示例代码,通过HTTP POST请求创建新实例:
HttpPost request = new HttpPost("https://[server]:[port]/api/1.0/forms/forminstances");
request.addHeader(HttpHeaders.AUTHORIZATION, "Bearer [access_token]");
request.addHeader(HttpHeaders.CONTENT_TYPE, "application/json");
JSONObject json = new JSONObject();
json.put("formName", "[form_name]");
json.put("locale", "[locale]");
json.put("contentRoot", "[content_root]");
json.put("dataKey", "[data_key]");
json.put("formData", "[form_data]");
json.put("attachments", "[attachments]");
json.put("template", "[template]");
json.put("draft", "[draft]");
json.put("dueDate", "[due_date]");
json.put("prefill", "[prefill]");
json.put("captcha", "[captcha]");
json.put("allowDebugging", "[allow_debugging]");
StringEntity entity = new StringEntity(json.toString(), Charset.forName("UTF-8"));
request.setEntity(entity);
HttpClient httpClient = HttpClientBuilder.create().build();
HttpResponse response = httpClient.execute(request);
int statusCode = response.getStatusLine().getStatusCode();
- 除了通过REST API创建新实例,还可以使用AEM表单提供的UI,通过浏览器进入表单管理应用。在应用中,点击“创建表单实例”按钮,填写相应信息,最后点击“创建”即可。