Constraint Violation Exception when trying to add node property | Community
Skip to main content
ariellea4070516
Level 3
Feb 21, 2019 11:21 PM UTC
Solved

Constraint Violation Exception when trying to add node property

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>

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Gaurav-Behl
Gaurav-BehlAccepted solution
Level 10
Feb 22, 2019 1:33 AM UTC

"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

6 replies

сергейд53065179
New Participant
Feb 23, 2019 7:03 AM UTC
Translate
ariellea4070516
Level 3
Feb 22, 2019 6:25 PM UTC

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!

Translate
Prince_Shivhare
New Participant
Feb 22, 2019 2:52 AM UTC

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.

Translate
Gaurav-Behl
Gaurav-BehlAccepted solution
Level 10
Feb 22, 2019 1:33 AM UTC

"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

Translate
smacdonald2008
Level 10
Feb 22, 2019 12:38 AM UTC

Or by form submission, do you mean component dialog?

Translate
smacdonald2008
Level 10
Feb 22, 2019 12:31 AM UTC

Using a WCMUsePojo not best choice to handle a form submission. Where did you get that idea?

Translate