I am using angularjs, restangular and the java stripes framework in my project.
I want my form to pass up params such that stripes will map the params back to the objects in my action.
My stripes action works and looks like
@DefaultHandler
public Resolution allUsers(){....}
private User newUser;
//Getter and setter
public Resolution createUser()
{
//persist the user
}
My very simple angularjs
var usrs = Restangular.all('User.action');
usrs.getList().then(function(users){
$scope.users = users;
});
$scope.newUser = {};
$scope.createUser = function(){
usrs.post('ajax/UserAjax.action?', $scope.newUser).then(
function(data)
{
$scope.users.push(data);
}
);
};
And my form
<form ng-submit="createUser()" >
<input type="hidden" ng-model="newUser.createUser" name="newUser.createUser" ng-init="newUser.createUser=''" value="{{newUser.createUser}}"/>
<input type="text" name="newUser.login" ng-model="newUser.login"/>
<input type="text" name="newUser.password" ng-model="newUser.password"/>
<input type="submit"/>
</form>
My form will post and send up the params. But it sends up login=xxx and password=xxx. And so the action gets a null newUser. I want to pass up newUser.login=xxx and newUser.password=xxx so that stripes will do the mapping.
I can get the following to work, but I don't like it:
$scope.createUser = function(){
usrs.post('ajax/UserAjax.action?', {createUser:'','newUser.login':$scope.newUser.login,'newUser.password':$scope.newUser.password})).then(
function(data)
{
$scope.users.push(data);
}
);
};
I've also tried things like
<input type="text" name="newUser.newUser.login" ng-model="newUser.newUser.login"/>
<input type="text" name="newUser.'newUser.login'" ng-model="newUser.'newUser.login'"/>
How do I get angularjs/restangular to pass up params with '.' in the names?
I just found out that I can do something like this:
<input type="text" name="newUser[newUser.login]" ng-model="newUser[newUser.login]"/>