I am using struts2 framework with angularjs.There are two buttons one for reset the texts fields with default value and other is to submit the page. my submit is not working. My jsp page is:-
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.16/angular.min.js"></script>
</head>
<body ng-app="postApp" ng-controller="postController">
<div class="container">
<div class="col-sm-8 col-sm-offset-2">
<div class="page-header">
<h1>
Post data using angularJS
</h1>
</div>
<form name="studentForm" novalidate >
<div class="form-group">
<label>
Name
</label>
<input type="text" name="name" class="form-control"
ng-model="user.name" required>
<span ng-show="errorname">{{errorname}}</span>
</div>
<div class="form-group">
<label>
Username
</label>
<input type="text" name="username" class="form-control"
ng-model="user.username" required>
<span ng-show="errorUsername">{{errorUsername}}</span>
</div>
<div class="form-group">
<label>
Email
</label>
<input type="email" name="email" class="form-control"
ng-model="user.email" required>
<span ng-show="erroremail">{{erroremail}}</span>
</div>
<div><span><button ng-click="reset()" class="btn btn-primary">
reset
</button> </span>
<span> <button type="submit" ng-click="submitForm()" ng-disabled = {{erroremail}}
class="btn btn-primary">
Submit
</button></span>
</div>
</form>
</div>
</div>
<script>
var postApp = angular.module('postApp', []);
postApp.controller('postController', function($scope, $http) {
$scope.reset = function() {
$scope.user.name = "Mahesh";
$scope.user.username = "Parashar";
$scope.user.email = "MaheshParashar@gmail.com";
}
$scope.user = {};
$scope.submitForm = function() {
$http( {
method : 'POST',
url : '/angular/studentForm.action',
data : $scope.user,
headers : {
'Content-Type' : 'application/x-www-form-urlencoded'
}
}).success(function(data){
if (data.errors) {
$scope.errorname = data.errors.name;
$scope.errorUsername = data.errors.username;
$scope.erroremail = data.errors.email;
} else {
$scope.message = data.message;
}
}).error(function(data,status){
return false;
});
};
});
</script>
</body>
</html>
here is my Action class.
package com.skilrock.Action;
import com.opensymphony.xwork2.ActionSupport;
public class StudentController extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
private String firstName;
private String lastName;
private String email;
public String stdController() {
System.out.println(firstName + lastName + email);
return SUCCESS;
}
}
my reset button is working fine but when i click on submit button having an empty form then it call the given action class's method.. Other point is that each time either the form is empty or not that action method is not getting values of the form...