I have an adaptive form which has unbound and bound fields because it it partially based on a XDP form model.
I now need to pre-fill some of the fields with data from the currently logged in user.
I found Adobe example files and took the following route:
final boolean isAnonymous = UserPropertiesUtil.isAnonymous(slingRequest);
boolean isDisabled = WCMMode.fromRequest(request).equals(WCMMode.DISABLED);
if(!isAnonymous && isDisabled && slingRequest.getParameter("dataRef")== null
UserProperties userProperties = slingRequest.adaptTo(UserProperties.class);
String givenName = userProperties.getProperty("givenName");
String dataXML="<afData>" +
"<General_firstName>"+ StringUtils.trimToEmpty(userProperties.getProperty("givenName")) + "<General_firstName>" +
In the above snippet, "<General_firstName>" is the element name of the form field.
The jsp is included and has no errors, but the field is not pre-filled. Does the XML need a different structure? The above field was dragged from the content finder (the loaded XDP) but I also have unbound fields.
Any help is greatly appreciated.
Please don't point me to the documentation - https://helpx.adobe.com/aem-forms/6-1/prepopulate-adaptive-form-fields.html - since it did not help me 😞
import org.apache.jackrabbit.api.security.user.Authorizable ;
i have used the following
UserManager um = ((JackrabbitSession) session).getUserManager();
Authorizable loggedinUser = um.getAuthorizable(session.getUserID());
System.out.println("The path of the user is"+loggedinUser.getPath());
System.out.println("The family name is "+loggedinUser.getProperty("profile/familyName").getString());
suggest you use prefill service to populate forms , instead of doing it in the JSP page
it needs to be <data> and not <dataRoot> as stated in the documentation. Submitting a form saves the form data in CRX, if you download the 'data' element you can look at the actual XML structure. Pre-filling needs to have the same structure.
Also, pre-filling can only be viewed in WCM Mode disabled, not in preview mode.
I have already done so,
The xml i got was
<?xml version="1.0" encoding="UTF-8"?><afData>
taking it as a base i set the data attribute , just removed unnecessary tags from above xml
try the following steps first
1.Set the form's submit action to "Store Content". Preview the form and enter some value in the text fields
2.Submit the form
3.go to the node where the form's data is submitted. Get the data xml from the jcr:data node. Save the data xml as a xml file on your file system
4.Preview you form with the data xml stored in the previous steps
5.The forms should prepopulate with the data from the xml file
6.Then make sure the data that you are passing in your code matches the structure in the xml file which you got in step 4
I am working on AEM forms too,
I also have tried to use prefilling of form by using data attribute but its not working.
Even tried the things you have suggested, still facing problem.
Please help me
Here is the data attribute:
The Form is without any data model and containing only two textbox with name "textbox1" and "textbox2"
Can you throw some light on what was the problem and what were the steps taken to solve it ? Also, with 6.2, we have introduced a much simpler and manageable way to prefill forms with the notion of "prefill service", the documentation of this would be live soon.