Hi, I have created a WCMUsePojo to handle form submissions that serve to update and/or create user profile properties found under
/home/users/../userID/profile
But am getting a Constraint Violation exception
javax.jcr.nodetype.ConstraintViolationException: No matching property definition: nodePropertyValue = thisissomestring
Even though this node is of type unstructured. I have posted my code below, any insight would be appreciated!
Thank you!
Session session = getRequest().getResourceResolver().adaptTo(Session.class);
UserManager userManager = getRequest().getResourceResolver().adaptTo(UserManager.class);
String sessionUserId = session.getUserID();
authorizablePath = userManager.getAuthorizable(sessionUserId).getPath();
String nodePropertyValue= getRequest().getParameter("nodePropertyValue");
Resource resource = getRequest().getResourceResolver().getResource(authorizablePath);
Node node = resource.adaptTo(Node.class);
Node profile = node.getNode("profile");
profile.setProperty("nodePropertyName", nodePropertyValue);
session.save();
The form is structured as such
<form method="POST" action="FormSubmission.java">
<input type="text" name="nodePropertyValue" id="nodePropertyValue" />
<button type="submit">Submit</button>
</form>
Solved! Go to Solution.
Views
Replies
Total Likes
"No matching property definition: nodePropertyValue = thisissomestring"
means that your code is trying to add "nodePropertyValue" to a node <authorizablePath> where it's not allowed.
Not sure why it says the property name is not "nodePropertyName" but "nodePropertyValue = thisissomestring". You should run the server in debug mode or dump logs to find more clues.
you're correct that "nt:unstructured" should've allowed it but I'm not sure if you as a logged-in user can modify your own (session-user's profile) profile at runtime? Did you try with "admin" user? Could you check if this user has "write" permissions (rep:write + jcr:write) to create the property on own profile (although that would've thrown a different exception in logs)
You may try with a service user and ensure that you have appropriate permissions on the /home/users... path
P.S. As Scott mentioned, you should use better options for this use case in production-ready code
Using a WCMUsePojo not best choice to handle a form submission. Where did you get that idea?
Views
Replies
Total Likes
Or by form submission, do you mean component dialog?
Views
Replies
Total Likes
"No matching property definition: nodePropertyValue = thisissomestring"
means that your code is trying to add "nodePropertyValue" to a node <authorizablePath> where it's not allowed.
Not sure why it says the property name is not "nodePropertyName" but "nodePropertyValue = thisissomestring". You should run the server in debug mode or dump logs to find more clues.
you're correct that "nt:unstructured" should've allowed it but I'm not sure if you as a logged-in user can modify your own (session-user's profile) profile at runtime? Did you try with "admin" user? Could you check if this user has "write" permissions (rep:write + jcr:write) to create the property on own profile (although that would've thrown a different exception in logs)
You may try with a service user and ensure that you have appropriate permissions on the /home/users... path
P.S. As Scott mentioned, you should use better options for this use case in production-ready code
agree with above comments: please use service user, as you are trying to do some changes with node at runtime. ResourceResolverFactory rrFactory; Map<String, Object> param = new HashMap<String, Object>(); param.put(ResourceResolverFactory.SUBSERVICE, "getResourceResolver"); ResourceResolver resourceResolver = rrFactory.getServiceResourceResolver(param); also if you are working on normal page form then you can sling models. search for helpx articles.
Views
Replies
Total Likes
Thanks Gaurav, I was not planning on using the WCMUsePojo in production ready code but simply experimenting in a quick fashion to understand what logic should be used to process form entries into node property updates. Also, "nodePropertyName" and "Value" were my fillers to help explain what was previously there "email" and "example@gmail.com." I have moved my code into an AEM core bundle and will utilize JSP to return my param values.
Thanks!
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies