using the sling post servlet to create new nodes under a cq:Page
I have a cq:Page at /etc/news/users, this has a sling resourceTyle /news/components/admin/userlist which is a child type of wcm/foundation/component/page--body.html has a simple form (see below) in it right now. That page has a number of children representing virtual users or sling:resourceType:news/components/admin/user (essentially, these are legacy authors and contacts from an old news system that don't need accounts, but need some place to store their information like active authors).
I'm trying to create a form to create new users under this page. I thought I'd be able to get away with using the default sling post servlet to generate these nodes and not have to create a servlet myself, but I'm running into some issues. Do I have to create this servlet automatically? Am I missing some required fields?
Here's a slimmed down version of the form:
<form method="POST" action="/etc/news/users/"> <input id="name" type="text" name=":name" ng-value="displayName | spaceless | lowercase"/> <input id="displayName" type="text" name="displayName" ng-model="displayName"/> <input id="sling:resourceType" type="hidden" name="sling:resourceType" value="news/components/admin/user"/> <input type="submit" value="Create New User"> </form>
When I submit that form, I get a 500 error in the browser (when I enter "test" for the displayName --angular automatically places "test" in :name also):
Error while processing /etc/news/users/test Status 500 Message org.apache.sling.api.SlingException: Exception during response processing. Location /etc/news/users/test Parent Location /etc/news/users Path /etc/news/users/test Referer http://localhost:4502/etc/news/users.html
and a javax.jcr.nodetype.ConstraintViolationException in the log:
27.06.2016 11:13:17.733 *ERROR* [0:0:0:0:0:0:0:1 [1467040397731] POST /etc/news/users/ HTTP/1.1] org.apache.sling.servlets.post.impl.operations.ModifyOperation Exception during response processing. javax.jcr.nodetype.ConstraintViolationException: No matching property definition: displayName = test at org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate.setProperty(NodeDelegate.java:522) at org.apache.jackrabbit.oak.jcr.session.NodeImpl$35.perform(NodeImpl.java:1375) at org.apache.jackrabbit.oak.jcr.session.NodeImpl$35.perform(NodeImpl.java:1363) at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:208) at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:112) at org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty(NodeImpl.java:1363) ....