html page:
----------
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Baby's First Years - The first years of my life!</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
function loadplans() {
//alert("hai");
$.ajax({
type : "POST", // Method to send the data. I would need "post" method
// as better option.
url : "plan!getPlans", // Action called to data treatament
data : {
// PARAMETER jgGrdData with variable "postData" value
},
/** START: handlers for request. Not important for this trouble * */
dataType : "json",
contentType : "application/x-www-form-urlencoded; charset=utf-8",
success : function(text) {
// alert("one. .. ");
responseText = text.planss;
fillPlans(responseText);
},
error : function(xhr, textStatus, errorThrown) {
//alert("error"+errorThrown);
}
/** END: handlers for the request. * */
});
}
function fillPlans(pageData) {
//alert("fillplans");
var myObject = eval('(' + pageData + ')');
if (myObject != null) {
var storages = myObject.storage;
var domains = myObject.domain;
for ( var i = 1; i <= 3; i++) {
document.getElementById(i).innerHTML = myObject[i - 1].description;
document.getElementById("p" + i).innerHTML = myObject[i - 1].amount;
document.getElementById("s" + i).innerHTML = myObject[i - 1].storage;
document.getElementById("d" + i).innerHTML = myObject[i - 1].domain;
document.getElementById("e" + i).innerHTML = myObject[i - 1].support;
document.getElementById("de" + i).innerHTML = myObject[i - 1].duraction;
}
}
}
</script>
</head>
<body
onLoad="loadplans()">
<div id="babys_wrapper">
<!-- end of babys header -->
<div id="babys_middle" style="padding-top: 0px;">
<div id="container">
<div class="pricingtable ">
<div class="top">
<h2>
<label id="1"></label>
</h2>
</div>
<h1>
<sup>$</sup><label id="p1"></label>
</h1>
<p>
<label id="de1"></label>
</p>
<ul>
<li><strong><label id="e1"></label></strong> Email Support</li>
<li><strong><label id="s1"></label></strong>GB of Storage</li>
<li><strong><label id="d1"></label></strong> Domains</li>
</ul>
<div class="pricingtable">
<div class="top">
<h2>
<label id="2"></label>
</h2>
</div>
<h1>
<sup>$</sup><label id="p2"></label>
</h1>
<p>
<label id="de2"></label>
</p>
<ul>
<li><strong><label id="e2"></label></strong> Email Support</li>
<li><strong><label id="s2"></label></strong>GB of Storage</li>
<li><strong><label id="d2"></label></strong> Domains</li>
</ul>
<div class="pricingtable">
<div class="top">
<h2>
<label id="3"></label>
</h2>
</div>
<h1>
<sup>$</sup><label id="p3"></label>
</h1>
<p>
<label id="de3"></label>
</p>
<ul>
<li><strong><label id="e3"></label></strong> Email Support</li>
<li><strong><label id="s3"></label></strong>GB Storage</li>
<li><strong><label id="d3"></label></strong> Domains</li>
</ul>
</div>
</div>
Action class:
-------------
PlanController.java:
--------------------
package com.asman.BabysFirstYears;
import java.util.List;
import java.util.Map;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.interceptor.SessionAware;
import com.asman.BabysFirstYears.service.UsersService;
import com.asman.BabysFirstYears.to.SubPlans;
import com.opensymphony.xwork2.ValidationAwareSupport;
@ParentPackage("json-default")
@Results({ @Result(name = "success", type = "json") })
public class PlanController extends ValidationAwareSupport implements
SessionAware {
/**
*
*/
private static final long serialVersionUID = 1L;
private Map<String, Object> session;
@Override
public void setSession(Map<String, Object> session) {
this.session = session;
}
private String planss;
/**
* @param plans the plans to set
*/
private List<SubPlans> subPlansList;
/**
* @return the subPlansList
*/
public List<SubPlans> getSubPlansList() {
return subPlansList;
}
/**
* @param subPlansList the subPlansList to set
*/
public void setSubPlansList(List<SubPlans> subPlansList) {
this.subPlansList = subPlansList;
}
private UsersService usersService=new UsersService();
public String getPlans()
{
//System.out.println("in actionnnnnnnnnnnnnnnnnnnnnnnnnnnn");
subPlansList=usersService.getPlans();
//System.out.println("sizeeeeeeeee"+subPlansList.size());
planss=usersService.getPlansByJSON(subPlansList);
System.out.println("plans::::::::::"+planss);
return "success";
}
/**
* @return the planss
*/
public String getPlanss() {
return planss;
}
/**
* @param planss the planss to set
*/
public void setPlanss(String planss) {
this.planss = planss;
}
}
----------
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Baby's First Years - The first years of my life!</title>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
function loadplans() {
//alert("hai");
$.ajax({
type : "POST", // Method to send the data. I would need "post" method
// as better option.
url : "plan!getPlans", // Action called to data treatament
data : {
// PARAMETER jgGrdData with variable "postData" value
},
/** START: handlers for request. Not important for this trouble * */
dataType : "json",
contentType : "application/x-www-form-urlencoded; charset=utf-8",
success : function(text) {
// alert("one. .. ");
responseText = text.planss;
fillPlans(responseText);
},
error : function(xhr, textStatus, errorThrown) {
//alert("error"+errorThrown);
}
/** END: handlers for the request. * */
});
}
function fillPlans(pageData) {
//alert("fillplans");
var myObject = eval('(' + pageData + ')');
if (myObject != null) {
var storages = myObject.storage;
var domains = myObject.domain;
for ( var i = 1; i <= 3; i++) {
document.getElementById(i).innerHTML = myObject[i - 1].description;
document.getElementById("p" + i).innerHTML = myObject[i - 1].amount;
document.getElementById("s" + i).innerHTML = myObject[i - 1].storage;
document.getElementById("d" + i).innerHTML = myObject[i - 1].domain;
document.getElementById("e" + i).innerHTML = myObject[i - 1].support;
document.getElementById("de" + i).innerHTML = myObject[i - 1].duraction;
}
}
}
</script>
</head>
<body
onLoad="loadplans()">
<div id="babys_wrapper">
<!-- end of babys header -->
<div id="babys_middle" style="padding-top: 0px;">
<div id="container">
<div class="pricingtable ">
<div class="top">
<h2>
<label id="1"></label>
</h2>
</div>
<h1>
<sup>$</sup><label id="p1"></label>
</h1>
<p>
<label id="de1"></label>
</p>
<ul>
<li><strong><label id="e1"></label></strong> Email Support</li>
<li><strong><label id="s1"></label></strong>GB of Storage</li>
<li><strong><label id="d1"></label></strong> Domains</li>
</ul>
<div class="pricingtable">
<div class="top">
<h2>
<label id="2"></label>
</h2>
</div>
<h1>
<sup>$</sup><label id="p2"></label>
</h1>
<p>
<label id="de2"></label>
</p>
<ul>
<li><strong><label id="e2"></label></strong> Email Support</li>
<li><strong><label id="s2"></label></strong>GB of Storage</li>
<li><strong><label id="d2"></label></strong> Domains</li>
</ul>
<div class="pricingtable">
<div class="top">
<h2>
<label id="3"></label>
</h2>
</div>
<h1>
<sup>$</sup><label id="p3"></label>
</h1>
<p>
<label id="de3"></label>
</p>
<ul>
<li><strong><label id="e3"></label></strong> Email Support</li>
<li><strong><label id="s3"></label></strong>GB Storage</li>
<li><strong><label id="d3"></label></strong> Domains</li>
</ul>
</div>
</div>
Action class:
-------------
PlanController.java:
--------------------
package com.asman.BabysFirstYears;
import java.util.List;
import java.util.Map;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.interceptor.SessionAware;
import com.asman.BabysFirstYears.service.UsersService;
import com.asman.BabysFirstYears.to.SubPlans;
import com.opensymphony.xwork2.ValidationAwareSupport;
@ParentPackage("json-default")
@Results({ @Result(name = "success", type = "json") })
public class PlanController extends ValidationAwareSupport implements
SessionAware {
/**
*
*/
private static final long serialVersionUID = 1L;
private Map<String, Object> session;
@Override
public void setSession(Map<String, Object> session) {
this.session = session;
}
private String planss;
/**
* @param plans the plans to set
*/
private List<SubPlans> subPlansList;
/**
* @return the subPlansList
*/
public List<SubPlans> getSubPlansList() {
return subPlansList;
}
/**
* @param subPlansList the subPlansList to set
*/
public void setSubPlansList(List<SubPlans> subPlansList) {
this.subPlansList = subPlansList;
}
private UsersService usersService=new UsersService();
public String getPlans()
{
//System.out.println("in actionnnnnnnnnnnnnnnnnnnnnnnnnnnn");
subPlansList=usersService.getPlans();
//System.out.println("sizeeeeeeeee"+subPlansList.size());
planss=usersService.getPlansByJSON(subPlansList);
System.out.println("plans::::::::::"+planss);
return "success";
}
/**
* @return the planss
*/
public String getPlanss() {
return planss;
}
/**
* @param planss the planss to set
*/
public void setPlanss(String planss) {
this.planss = planss;
}
}
UsersService.java:
------------------
public class UsersService
{
public List<SubPlans> getPlans()
{
System.out.println("in serviceeeeeeeeeeeeeeeeeeeee");
SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
List<SubPlans> subPlansList= usersDao.getPlans(session);
return subPlansList;
}
/** generate json data from list object
**/
public String getPlansByJSON(List<SubPlans> subPlans) {
String plans = null;
JSONArray plansArray = new JSONArray();
for (SubPlans subPlan : subPlans) {
JSONObject plan = new JSONObject();
plan.put("description", subPlan.getSubDescription());
plan.put("amount", subPlan.getAmount());
plan.put("storage", subPlan.getStorage());
plan.put("domain", subPlan.getDomain());
plan.put("support", subPlan.getSupport());
plan.put("duraction", subPlan.getDuration());
plansArray.put(plan);
}
plans = plansArray.toString();
return plans;
}
}
UserDao.java:
---------------
public class UserDao
{
public List<SubPlans> getPlans(Session session)
{
Query query=session.createQuery("from SubPlans");
List<SubPlans> subPlansList=query.list();
return subPlansList;
}
}
No comments:
Post a Comment