如何在多个页面上使用相同的表单bean和操作类?我是否需要为其他JSP页面创建一个完全具有相同变量的表单bean和操作类?提前致谢。如何在Dashboard.jsp中使用这些表单和操作类?我只想在dashboard.jsp中显示供应商的数据。
下面是示例代码:
VendorInfoForm.java
package com.pms.reference;
import com.base.utility.DateUtil;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
public class VendorInfoForm extends org.apache.struts.action.ActionForm {
private String vivendorID;
private String vivendorShortname;
private String vivendorName;
public String getVivendorID() {
return vivendorID;
}
public void setVivendorID(String vivendorID) {
this.vivendorID = vivendorID;
}
public String getVivendorName() {
return vivendorName;
}
public void setVivendorName(String vivendorName) {
this.vivendorName = vivendorName;
}
public String getVivendorShortname() {
return vivendorShortname;
}
public void setVivendorShortname(String vivendorShortname) {
this.vivendorShortname = vivendorShortname;
}
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
return errors;
}
}
VendorInfoAction.java
package com.pms.reference;
import com.base.constant.MessageConstant;
import com.base.utility.BaseUtil;
import com.base.utility.DateUtil;
import com.hbs.base.entities.ComAccessLevel;
import com.hbs.base.entities.ComUserProfiles;
import com.hbs.base.entities.ComAccessLevel;
import com.htp.web.base.BaseAction;
import com.htp.web.base.constant.PageConstant;
import com.htp.web.utility.WebUtil;
import com.pms.reference.entities.ASVendorInfo;
import com.pms.reference.entities.HDPersonInfo;
import com.pms.reference.entities.RefState;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class VendorInfoAction extends BaseAction {
private final static String JSP_LIST = "/jspNew/pms/reference/VendorInfoList.jsp";
private final static String JSP_CREATE = "/jspNew/pms/reference/VendorInfoCreate.jsp";
private final static String JSP_READ = "/jspNew/pms/reference/VendorInfoRead.jsp";
private final static String JSP_UPDATE = "/jspNew/pms/reference/VendorInfoUpdate.jsp";
public ActionForward executeAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
VendorInfoForm formBean = (VendorInfoForm)form;
String action = WebUtil.getStrInput(request, "hdAction");
String nextJSP = "";
try {
if (BaseUtil.isEqualsCaseIgnore(action, PageConstant.MENU) ||
BaseUtil.isEqualsCaseIgnore(action, PageConstant.LIST) ||
BaseUtil.isEqualsCaseIgnore(action, PageConstant.GET_SORTING)) {
nextJSP = getList(request, action);
}
else if (BaseUtil.isEqualsCaseIgnore(action, PageConstant.GET_CREATE)) {
nextJSP = getCreate(request, action);
}
else if (BaseUtil.isEqualsCaseIgnore(action, PageConstant.CREATE) ||
BaseUtil.isEqualsCaseIgnore(action, PageConstant.UPDATE)) {
nextJSP = doCreateOrUpdate(request, action, formBean);
}
else if (BaseUtil.isEqualsCaseIgnore(action, PageConstant.DELETE)) {
nextJSP = doDelete(request, action);
}
else if (BaseUtil.isEqualsCaseIgnore(action, PageConstant.GET_READ)
|| BaseUtil.isEqualsCaseIgnore(action, PageConstant.GET_UPDATE)) {
nextJSP = getReadOrUpdate(request, action);
}
}
catch(Exception e){
e.getMessage();
}
return new ActionForward(nextJSP);
}
private String getList(HttpServletRequest request, String action) throws Exception{
ComUserProfiles profile = (ComUserProfiles)request.getSession().getAttribute("PROFILE");
lookupComAccessLevel();
ComAccessLevel accessLevel = comAccessLevelFacade.find(profile.getAclId());
request.setAttribute("accessLevel", accessLevel);
String input = WebUtil.getStrInput(request, "txtSchAll");
input = BaseUtil.replaceQuickSearch(input);// modified by din 20/05/2015
String pageNo = WebUtil.getStrInput(request, "hdPgNo");
String sortOrder = "";
String sortId = WebUtil.getStrInput(request, "sortId");
if (BaseUtil.isEqualsCaseIgnore(action, PageConstant.MENU)) {
manageCommonSession(request, "Vendor");
}
// ----------------- Start Sorting -------------//
manageSortingSession(request, sortId);
sortId = BaseUtil.getStr(request.getSession().getAttribute("sortingId"));
sortOrder = BaseUtil.getStr(request.getSession().getAttribute("sortingOrder"));
// ------------------ End Sorting --------------//
Integer maxNo = BaseUtil.getInt(request.getSession().getAttribute("DISPLAY"));
Integer firstNo = ((pageNo!=null && !pageNo.equalsIgnoreCase("")?Integer.parseInt(pageNo):1) - 1) * maxNo;
lookupASVendorInfo();
int[] range = new int[]{firstNo, maxNo};
List<ASVendorInfo> list = aSVendorInfo.findAll(input, range, sortId, sortOrder);
int totalRecord = aSVendorInfo.findTotal(input);
request.setAttribute("list", list);
request.setAttribute("currentpageno", pageNo);
request.setAttribute("totalrecords", String.valueOf(totalRecord));
request.setAttribute("noofpages", String.valueOf(totalRecord / range[1] + (totalRecord % range[1] == 0 ? 0 : 1)));
request.setAttribute("recordstartno", firstNo);
request.setAttribute("searchinput", input);
return JSP_LIST;
}
private String getCreate(HttpServletRequest request, String action) throws Exception{
if (BaseUtil.isEqualsCaseIgnore(action, PageConstant.MENU)) {
manageCommonSession(request, "Vendor");
}
lookupHDPersonInfo();
List<HDPersonInfo> personList = hDPersonInfo.findAllByPersonType("3");
request.setAttribute("personList", personList);
lookupRefState();
List<RefState> stateList = refStateFacade.findAll();
request.setAttribute("stateList", stateList);
return JSP_CREATE;
}
private String doCreateOrUpdate(HttpServletRequest request, String action, VendorInfoForm src) throws Exception{
ComUserProfiles profile = (ComUserProfiles)request.getSession().getAttribute("PROFILE");
String msgInfo = "";
String msgType = "";
ASVendorInfo dest = new ASVendorInfo();
BeanUtils.copyProperties(dest, src);
try {
msgType = MessageConstant.SUCCESS;
lookupASVendorInfo();
if(BaseUtil.isEqualsCaseIgnore(action, PageConstant.UPDATE)){
dest.setVivendorShortname(BaseUtil.getStrUpper(src.getVivendorShortname()));
dest.setViAddress1(BaseUtil.getStrUpper(src.getViAddress1()));
dest.setViAddress2(BaseUtil.getStrUpper(src.getViAddress2()));
dest.setViAddress3(BaseUtil.getStrUpper(src.getViAddress3()));
dest.setViUpdateDate(new Date(DateUtil.getCurrentDateTime()));
dest.setViUpdateId(profile.getId());
dest.setViActiveSts(BaseUtil.getStr(src.getViActiveSts()));
aSVendorInfo.edit(dest);
msgInfo = MessageConstant.RECORD_UPDATE_SUCCESS + ". <a href=\""+request.getContextPath()+"/VendorInfo.do?hdAction=getRead&id=" + dest.getVivendorID() + "\" data-toggle=\"ajaxModal\" >View Here.</a>";
}
else {
dest.setVivendorID("");
dest.setVivendorShortname(BaseUtil.getStrUpper(src.getVivendorShortname()));
dest.setViAddress1(BaseUtil.getStrUpper(src.getViAddress1()));
dest.setViAddress2(BaseUtil.getStrUpper(src.getViAddress2()));
dest.setViAddress3(BaseUtil.getStrUpper(src.getViAddress3()));
dest.setViCreateDate(new Date(DateUtil.getCurrentDateTime()));
dest.setViCreateId(profile.getId());
dest.setViActiveSts(BaseUtil.getStr(src.getViActiveSts()));
String vendorId = aSVendorInfo.createVendorInfo(dest);
msgInfo = MessageConstant.RECORD_CREATE_SUCCESS + ". <a href=\""+request.getContextPath()+"/VendorInfo.do?hdAction=getRead&id=" + vendorId + "\" data-toggle=\"ajaxModal\" >View Here.</a>";
}
} catch(Exception e) {
msgType = MessageConstant.ERROR;
e.printStackTrace();
if(BaseUtil.isEqualsCaseIgnore(action, PageConstant.UPDATE)) {
msgInfo = MessageConstant.RECORD_UPDATE_FAILED;
}
else {
msgInfo = MessageConstant.RECORD_CREATE_FAILED;
}
}
request.setAttribute("errMsg", BaseUtil.getMessage(msgType, msgInfo));
return getList(request, action);
}
private String getReadOrUpdate(HttpServletRequest request, String action) throws Exception{
String id = WebUtil.getStrInput(request, "id");
if (BaseUtil.isEqualsCaseIgnore(action, PageConstant.MENU)) {
manageCommonSession(request, "Vendor");
}
lookupHDPersonInfo();
List<HDPersonInfo> personList = hDPersonInfo.findAllByPersonType("3");
request.setAttribute("personList", personList);
lookupRefState();
List<RefState> stateList = refStateFacade.findAll();
request.setAttribute("stateList", stateList);
lookupASVendorInfo();
ASVendorInfo o = aSVendorInfo.find(id);
request.setAttribute("obj", o);
if (BaseUtil.isEqualsCaseIgnore(action, PageConstant.GET_UPDATE)) {
return JSP_UPDATE;
}
else {
return JSP_READ;
}
}
private String doDelete(HttpServletRequest request, String action) throws Exception{
String id = WebUtil.getStrInput(request, "id");
lookupASVendorInfo();
ASVendorInfo o = aSVendorInfo.find(id);
aSVendorInfo.remove(o);
return getList(request, action);
}
@Override
protected void manageCommonSession(HttpServletRequest request, String formName) throws Exception {
request.getSession().removeAttribute("sortingOrder");
request.getSession().removeAttribute("sortingId");
request.getSession().removeAttribute("formName");
request.getSession().removeAttribute("menuId");
request.getSession().removeAttribute("txnId");
request.getSession().setAttribute("formName", formName);
request.getSession().setAttribute("menuId", WebUtil.getStrInput(request, "menuId"));
request.getSession().setAttribute("txnId", WebUtil.getStrInput(request, "txnId"));
}
}
Dashboard.jsp
<%@page import="com.htp.web.base.constant.PageConstant"%>
<%@page import="org.json.JSONObject"%>
<%--@ page language="java" contentType="application/json; charset=UTF-8" pageEncoding="UTF-8"--%>
<%@page import="com.pms.reference.entities.HDCaseMaster"%>
<%@page import="java.util.List"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="com.hbs.base.entities.ComUserProfiles"%>
<%@page import="com.base.utility.BaseUtil"%>
<%
String userID = "";
HDCaseMaster o = (HDCaseMaster) request.getAttribute("obj");
if (o == null) {
o = new HDCaseMaster();
}
ComUserProfiles profile = (ComUserProfiles) request.getSession().getAttribute("PROFILE");
List<HDCaseMaster> masterList = (List) request.getSession().getAttribute("masterList");
if (profile != null) {
if (!profile.equals("")) {
userID = profile.getId();
}
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<ul class="breadcrumb no-border no-radius b-b b-light pull-in">
<li><i class="fa fa-home"></i> Dashboard</li>
</ul>
<!--<content-page></content-page>-->
<div class="m-b-md">
<h3 class="m-b-none">Dashboard</h3>
<small>Welcome back, <%=BaseUtil.getStr(profile.getNickName())%></small> </div>
<%
JSONObject json = new JSONObject();
json.put("city", "Mumbai");
json.put("country", "India");
%>
<%=json.toString()%>
<%=o.getCmStatus()%>
<section class="panel panel-default">
<div class="row m-l-none m-r-none bg-light lter">
<div class="col-sm-4 col-md-4 padder-v b-r b-light min-box-height"> <span class="fa-stack fa-2x pull-left m-r-sm"> <i class="fa fa-circle fa-stack-2x text-info"></i> <i class="fa fa-user fa-stack-1x text-white"></i> </span> <a class="clear" href="javascript:getMenuPage('/CaseMaster.do?hdAction=getStartPage&menuId=M0302&txnId=M03T02');"> <span class="h3 block m-t-xs"><strong>Incident</strong></span> <small class="text-muted text-uc">Add New Incident</small> </a> </div>
<div class="col-sm-4 col-md-4 padder-v b-r b-light min-box-height"> <span class="fa-stack fa-2x pull-left m-r-sm"> <i class="fa fa-circle fa-stack-2x text-info"></i> <i class="fa fa-tasks fa-stack-1x text-white"></i> </span> <a class="clear" href="javascript:getMenuPage('/SLA.do?hdAction=getStartPage&menuId=M0402&txnId=M04T02');"> <span class="h3 block m-t-xs"><strong>SLA</strong></span> <small class="text-muted text-uc">Add New SLA</small> </a> </div>
<div class="col-sm-4 col-md-4 padder-v b-r b-light min-box-height"> <span class="fa-stack fa-2x pull-left m-r-sm"> <i class="fa fa-circle fa-stack-2x text-info"></i> <i class="fa fa-edit fa-stack-1x text-white"></i> </span> <a class="clear" href="javascript:getMenuPage('/GenReport.do?hdAction=getStartPage&menuId=M0502&txnId=M05T02');"> <span class="h3 block m-t-xs"><strong>Report</strong></span> <small class="text-muted text-uc">Incident Report</small> </a> </div>
</div>
</section>
<div class="row">
<div class="col-md-12"> <!-- .crousel slide -->
<section class="panel panel-default">
<div class="carousel slide auto panel-body" id="c-slide">
<ol class="carousel-indicators out">
<li data-target="#c-slide" data-slide-to="0" class="active"></li>
<li data-target="#c-slide" data-slide-to="1" class=""></li>
<li data-target="#c-slide" data-slide-to="2" class=""></li>
</ol>
<div class="carousel-inner">
<div class="item active">
<p class="text-center"> <em class="h4 text-mute">Save your time</em><br>
<small class="text-muted">Many components</small> </p>
</div>
<div class="item">
<p class="text-center"> <em class="h4 text-mute">Nice and easy to use</em><br>
<small class="text-muted">Full documents</small> </p>
</div>
<div class="item">
<p class="text-center"> <em class="h4 text-mute">Mobile header first</em><br>
<small class="text-muted">Mobile/Tablet/Desktop</small> </p>
</div>
</div>
<a class="left carousel-control" href="#c-slide" data-slide="prev"> <i class="fa fa-angle-left"></i> </a> <a class="right carousel-control" href="#c-slide" data-slide="next"> <i class="fa fa-angle-right"></i> </a> </div>
</section>
<!-- / .carousel slide --> </div>
</div>
<div class="row">
<div class="col-md-12">
<section class="panel panel-default portlet-item">
<header class="panel-heading bg-primary"> News </header>
<section class="panel-body">
<article class="media"> <span class="pull-left thumb-sm"><img src="../../images/avatar_default.jpg" class="img-circle"></span>
<div class="media-body">
<div class="pull-right media-xs text-center text-muted"> <strong class="h4">12:18</strong><br>
<small class="label bg-light">pm</small> </div>
<a href="#" class="h4">Bootstrap 3 released</a> <small class="block"><a href="#" class="">John Smith</a> <span class="label label-success">Circle</span></small> <small class="block m-t-sm">Sleek, intuitive, and powerful mobile-first front-end framework for faster and easier web development.</small> </div>
</article>
<div class="line pull-in"></div>
<article class="media"> <span class="pull-left thumb-sm"><i class="fa fa-file-o fa-3x icon-muted"></i></span>
<div class="media-body">
<div class="pull-right media-xs text-center text-muted"> <strong class="h4">17</strong><br>
<small class="label bg-light">feb</small> </div>
<a href="#" class="h4">Bootstrap documents</a> <small class="block"><a href="#" class="">John Smith</a> <span class="label label-info">Friends</span></small> <small class="block m-t-sm">There are a few easy ways to quickly get started with Bootstrap, each one appealing to a different skill level and use case. Read through to see what suits your particular needs.</small> </div>
</article>
<div class="line pull-in"></div>
<article class="media">
<div class="media-body">
<div class="pull-right media-xs text-center text-muted"> <strong class="h4">09</strong><br>
<small class="label bg-light">jan</small> </div>
<a href="#" class="h4 text-success">Mobile first html/css framework</a> <small class="block m-t-sm">Bootstrap, Ratchet</small> </div>
</article>
</section>
</section>
</div>
</div>
<div class="row">
<div class="col-md-12">
<section class="panel panel-default">
<header class="panel-heading font-bold">Incident Logs Created This Month</header>
<div class="panel-body">
<div class="row text-sm wrapper">
<div class="col-sm-12 m-b-xs text-center">
<div class="btn-group m-b" data-toggle="buttons">
<label class="btn btn-sm btn-default active btn-info">
<input type="radio" name="options" id="btnMonth">
Month </label>
<label class="btn btn-sm btn-default btn-info">
<input type="radio" name="options" id="btnWeek">
Week </label>
</div>
</div>
<div id="flot-test" style="height:265px"></div>
<!--<div id="namaHari"></div>-->
</div>
</div>
<footer class="panel-footer bg-white no-padder">
<%--<%=masterListDisplay %>--%>
<%
// int count [] = new int [5];
// if(masterListDisplay != null){
// for(HDCaseMaster o : masterListDisplay ){
// if(BaseUtil.isEquals(BaseUtil.getStr(o.getCmStatus()), "4")){count[0]=count[0]+1;}
// else if(BaseUtil.isEquals(BaseUtil.getStr(o.getCmStatus()), "5")){count[1]=count[1]+1;}
// else if(BaseUtil.isEquals(BaseUtil.getStr(o.getCmStatus()), "6")){count[2]=count[2]+1;}
// else if(BaseUtil.isEquals(BaseUtil.getStr(o.getCmStatus()), "7")){count[3]=count[3]+1;}
// else
// count[4]=count[4]+1;
// }
// }
%>
<div class="row text-center no-gutter">
<div class="col-xs-3 b-r b-light btn-success">
<span class="h4 font-bold m-t block">
</span> <small class="text-white m-b block ">Open Logs<div id="openLog"></div></small> </div>
<div class="col-xs-3 b-r b-light btn-warning"> <span class="h4 font-bold m-t block">System.out.print(GetTotalLog())</span> <small class="text-white m-b block ">Resolved Logs</small> </div>
<div class="col-xs-3 b-r b-light btn-info"> <span class="h4 font-bold m-t block">System.out.print(GetTotalLog())</span> <small class="text-white m-b block ">Closed Logs</small> </div>
<div class="col-xs-3 btn-danger"> <span class="h4 font-bold m-t block">System.out.print(GetTotalLog())</span> <small class="text-white m-b block ">Duplicate/Cancel Logs</small> </div>
</div>
</footer>
</section>
</div>
</div>
<div class="row">
<div class="col-md-8">
<section class="panel panel-default">
<header class="panel-heading font-bold">Total Incident Logs Created by Month</header>
<div class="panel-body">
<div id="flot-bar" style="height:150px"></div>
</div>
</section>
</div>
<div class="col-md-4">
<section class="panel panel-default">
<header class="panel-heading font-bold">Data By Day</header>
<div class="bg-light dk wrapper"> <span class="pull-right">Wednesday</span> <span class="h4">07-11-2014<br>
<small class="text-muted"></small> </span>
<div class="text-center m-b-n m-t-sm">
<div class="sparkline" data-type="line" data-height="65" data-width="100%" data-line-width="2" data-line-color="#dddddd" data-spot-color="#bbbbbb" data-fill-color="" data-highlight-line-color="#fff" data-spot-radius="3" data-resize="true" values="280,320,220,385,450,320,345,250,250,250,400,380"></div>
<br/>
</div>
</div>
<div class="panel-body">
<div> <span class="text-muted">Total:</span> <span class="h3 block">53 <small class="text-muted">log(s) created</small></span> </div>
</div>
</section>
</div>
</div>
<div class="row">
<div class="col-md-4">
<section class="panel b-light">
<header class="panel-heading bg-primary no-border"><strong>Calendar</strong></header>
<div id="calendar" class="bg-primary-lt m-l-n-xxs m-r-n-xxs"></div>
<div class="list-group"> <a href="#" class="list-group-item text-ellipsis"> <span class="badge bg-danger">7:30</span> Meet a friend </a> <a href="#" class="list-group-item text-ellipsis"> <span class="badge bg-success">9:30</span> Have a kick off meeting with .inc company </a> <a href="#" class="list-group-item text-ellipsis"> <span class="badge bg-light">19:30</span> Milestone release </a> </div>
</section>
</div>
</div>