i want simple crud application in struts2 , angularjs.
i have tried below code
addtourcontroller.js
var myapp = angular.module('myapp', []); myapp.controller('addtourcart', function($scope, $http){ $scope.getdatafromserver = function(){ var joumobj={}; var params = { "fromstate" : $scope.tourfromstate, "fromcity" : $scope.tourfromcity, "fromdate" : $scope.tourfromdate, "tostate" : $scope.tourtostate, "tocity" : $scope.tourtocity, "todate" : $scope.tourtodate, "purpose" : $scope.purpose, "staydetails" : $scope.tourstaymode }; var data = angular.tojson(params); $http( { method : 'post', url : 'addtourcart.action', data : 'value=' + data, headers : { 'content-type' : 'application/x-www-form-urlencoded' } }).success(function(data){ $scope.joumobj = data.joumobj; alert(data.joumobj); alert(params.fromdate); }); } });
jsp page
<!doctype html> <html> <head> <meta charset="iso-8859-1"> <title>tour</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"> </script> </head> <body> <div ng-app="myapp"> <div id="divjourneydetail" ng-controller="addtourcart"> <table id="table2" align="center" cellpadding="0" cellspacing = "0"> <tr> <th><b>from</b></th> <th><b>to</b></th> <th><b>travel details</b></th> <th>add / reset</th> </tr> <tr> <td><strong>state/city</strong></td> <td><strong>date</strong></td> <td><strong>state/city</strong></td> <td><strong>date</strong></td> <td><strong>purpose</strong></td> <td><strong>stay detail</strong></td> <td> <input type="button" id="addtourdtl" value="add" ng-click="getdatafromserver()"/> </td> </tr> <tr> <td> <s:select name="tourfromstate" id="tourfromstate" list="statelist" listkey="statecode" listvalue="statename" ng-model="tourfromstate" headerkey="" headervalue="-select state-" value="27" onchange="jfun_statebycitylist(this.value,'tourfromcity')"/> <div id="tourreplacecity"> <s:select name="tourfromcity" id="tourfromcity" list="citylist" listkey="regcd" listvalue="distname" ng-model="tourfromcity" headerkey="" headervalue="-select city-" onchange="jfun_setnewcity(this.value,'gettourfromnewcity','newtourfromcity')"/> </div> <div id="gettourfromnewcity"></div> </td> <td> <input type="text" name="fromdate" id="tourfromdate" value="" maxlength="10" ng-model="tourfromdate" > <img src="<%=request.getcontextpath()%>/mahbill/images/calender_anim.gif" onclick="popupcalender('tourfromdate');" width="19" height="19" > </td> <td> <s:select name="tourtostate" id="tourtostate" list="statelist" listkey="statecode" listvalue="statename" ng-model="tourtostate" headerkey="" headervalue="-select state-"value="27" onchange="jfun_statebycitylist(this.value,'tourtocity')"/> <div id="tourreplacetocity"> <s:select name="tourtocity" id="tourtocity" list="citylist" listkey="regcd" listvalue="distname" ng-model="tourtocity" headerkey="" headervalue="-select city-" onchange="jfun_setnewcity(this.value,'gettournewcity','newtourtocity')"/> </div> <div id="gettournewcity" ></div> </td> <td> <input type="text" name="tourtodate" id="tourtodate" value="" maxlength="10" ng-model="tourtodate" /> <img src="<%=request.getcontextpath()%>/mahbill/images/calender_anim.gif" onclick="popupcalender('tourtodate');" width="19" height="19" > </td> <td > <s:textarea key="purpose" name="purpose" id="tourpurpose" ng-model="purpose" cols="24" rows="2"/> </td> <td> <s:select name="tourstaymode" id="tourstaymode" headervalue="- select -" headerkey="" ng-model="tourstaymode" list="staymodelist" listkey="staymodeid" listvalue="staymodename" onchange="return jfun_staymode(this.value);"/> </td> </tr> </table> <div id="carttourdetails"> <table id="table2" align="center" cellpadding="0" cellspacing = "0"> <tr> <th align="center" colspan="2" style="border-right:1px solid #333;"><b>from</b></th> <th align="center" colspan="2" style="border-right:1px solid #333;"><b>to</b></th> <th align="center" colspan="2" style="border-right:1px solid #333;"><b>travel details</b></th> </tr> <tr> <td><strong>state/city</strong></td> <td><strong>date</strong></td> <td><strong>state/city</strong></td> <td><strong>date</strong></td> <td><strong>purpose</strong></td> <td><strong>stay detail</strong></td> </tr> <tr ng-repeat="journey in params"> <td valign="middle"> {{fromstate}} <div id="tourreplacecity"> {{fromcity}} </div> </td> <td>{{fromdate}}</td> <td valign="middle"> {{tostate}} <div id="tourreplacetocity"> {{tocity}} </div> </td> <td>{{todate}}</td> <td>{{purpose}} </td> <td>{{todate}}</td> </tr> </table> </div> </div> </div>
struts.xml
<package name="base" extends="json-default"> <action name="addtourcart" class="action.tour" method="addtourcart"> <result type="json"> <param name="root">joumobj</param> </result> </action> </package>
model class
public class journeydetail_m implements serializable{ private string fromstate; private string fromcity; private string fromdate; private string tostate; private string tocity; private string todate; private string staymodeid; private string staymodename; private string purpose; //getter , setter }
action class
public class tour extends actionsupport { journeydetail_m joumobj=new journeydetail_m(); public string addtourcart(){ try { system.out.println(request.getparameter("value")); string tourfromstate=request.getparameter("fromstate"); string tourfromcity=request.getparameter("fromcity"); string tourtostate=request.getparameter("tostate"); string tourtocity=request.getparameter("tocity"); string tourfromdate=request.getparameter("fromdate"); string tourtodate=request.getparameter("todate"); string purpose=request.getparameter("purpose"); string staymode=request.getparameter("staydetails"); joumobj.setfromstate(tourfromstate); joumobj.setfromcity(tourfromcity); joumobj.setfromdate(tourfromdate); joumobj.settostate(tourtostate); joumobj.settocity(tourtocity); joumobj.settodate(tourtodate); joumobj.setpurpose(purpose); joumobj.setstaymodeid(staymode); } catch (ioexception e) { e.printstacktrace(); return "error"; } return success; } public journeydetail_m getjoumobj() { return joumobj; } public void setjoumobj(journeydetail_m joumobj) { this.joumobj = joumobj; } }
here code in action using request.getparameter("value") got value how set , action class?
i found important link can make application on struts2 , angularjs.
Comments
Post a Comment