Results 1 to 3 of 3

Thread: using handleRequest and onsubmit in same controller

  1. #1
    Join Date
    Aug 2010
    Posts
    3

    Default using handleRequest and onsubmit in same controller

    hi, everyone i really need help

    i try to make the page to link to next page and i don't know how to use these two method together in the same controller...

    this is my controller
    Code:
    package MPrint.MVC.controller;
    
    import java.util.Collection;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.validation.BindException;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.SimpleFormController;
    
    import MPrint.MVC.DAO.CustomerDAO;
    import MPrint.MVC.DAO.MemberDAO;
    import MPrint.MVC.DAO.PurchasingOrderDAO;
    import MPrint.MVC.DAO.PurchasingRequestDAO;
    import MPrint.MVC.DAO.QuotationDetailDAO;
    
    import MPrint.MVC.Model.Customer;
    import MPrint.MVC.Model.Member;
    
    import MPrint.MVC.Model.PurchasingOrder;
    import MPrint.MVC.Model.PurchasingRequest;
    
    import MPrint.MVC.Model.QuotationDetail;
    
    public class AddQuotation1Controller extends SimpleFormController {
    
    	private QuotationDetailDAO quotationDetailDAO;
    	private MemberDAO memberDAO;
    	private CustomerDAO customerDAO;
    	private PurchasingRequestDAO purchasingRequestDAO;
    	private PurchasingOrderDAO purchasingOrderDAO;
    
    	public void setPurchasingRequestDAO(
    			PurchasingRequestDAO purchasingRequestDAO) {
    		this.purchasingRequestDAO = purchasingRequestDAO;
    	}
    
    	public void setPurchasingOrderDAO(PurchasingOrderDAO purchasingOrderDAO) {
    		this.purchasingOrderDAO = purchasingOrderDAO;
    	}
    
    	public void setCustomerDAO(CustomerDAO customerDAO) {
    		this.customerDAO = customerDAO;
    	}
    
    	public void setMemberDAO(MemberDAO memberDAO) {
    		this.memberDAO = memberDAO;
    	}
    
    	public void setQuotationDetailDAO(QuotationDetailDAO quotationDetailDAO) {
    		this.quotationDetailDAO = quotationDetailDAO;
    	}
    
    	public ModelAndView handleRequest(HttpServletRequest arg0,
    			HttpServletResponse arg1) throws Exception {
    
    		//QuotationDetail q = (QuotationDetail) command;
    		Collection<Member> members = memberDAO.listAll();
    		Collection<Customer> customers = customerDAO.listAll();
    		Collection<PurchasingOrder> oo = purchasingOrderDAO.listAll();
    		Collection<PurchasingRequest> rr = purchasingRequestDAO.listAll();
    		
    		ModelAndView x = new ModelAndView("quotationPage/addQuotation1");
    		x.addObject("memberList", members);
    		x.addObject("customerList", customers);
    		x.addObject("orderList", oo);
    		x.addObject("requestList", rr);
    		x.addObject("test", "test value");
    
    		System.out.println(members.toString());
    
    		return x;
    
    	}
    
    	public ModelAndView onSubmit(HttpServletRequest request,
    			HttpServletResponse response, Object command, BindException errors)
    			throws Exception {
    
    		QuotationDetail q = (QuotationDetail) command;
    
    		String purchasingRequestNo = q.getPurchasingRequestNo();
    		PurchasingRequest pr = purchasingRequestDAO
    				.getPurchasingRequest(purchasingRequestNo);
    		q.setPurchasingRequest(pr);
    
    		String purchasingOrderNo = q.getPurchasingOrderNo();
    		PurchasingOrder po = (PurchasingOrder) purchasingOrderDAO
    				.getPurchasingOrder(purchasingOrderNo);
    		q.setPurchasingOrder(po);
    		
    //		String memberNo = q.getMemberNo();
    //		Member mm = memberDAO.getMember(memberNo);
    //		q.setMember(mm);
    //		
    //		String customerNo = q.getCustomerNo();
    //		Customer cc = customerDAO.getCustomer(customerNo);
    //		q.setCustomer(cc);
    
    		quotationDetailDAO.addQuotationDetail(q);
    		return new ModelAndView("quotationPage/addQuotation2");
    
    	}
    }
    and this is my model

    Code:
    package MPrint.MVC.Model;
    
    import java.util.ArrayList;
    import java.util.Date;
    
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.OneToMany;
    import javax.persistence.OneToOne;
    
    import org.hibernate.mapping.Collection;
    
    @Entity
    public class QuotationDetail {
    	@Id
    	@GeneratedValue(strategy = GenerationType.AUTO)
    	Long id;
    	@Column(unique = true)
    	private String quotationNo;
    	@Column
    	private Date date;
    	@Column
    	private String termOfPayment;
    	@Column
    	private String quotationRemark;
    
    	//member
    	//private String memberNo;
    	@ManyToOne(targetEntity = MPrint.MVC.Model.Member.class)
    	@JoinColumn(name = "memberNo", nullable = false)
    	@org.hibernate.annotations.IndexColumn(name = "Member")
    	private Member member ;
    	
    	//customer
    	//private String customerNo;
    	@ManyToOne (targetEntity = MPrint.MVC.Model.Customer.class)
    	@JoinColumn(name = "customerNo", nullable = false)
    	@org.hibernate.annotations.IndexColumn(name = "Customer")
    	private Customer customer;
    
    	// use Purchasing Order DB
    	private String purchasingOrderNo;
    	@OneToOne
    	@JoinColumn(name = "purchasingOrder")
    	private PurchasingOrder purchasingOrder ;
    
    	// use Purchasing Request DB
    	private String purchasingRequestNo;
    	@OneToOne
    	@JoinColumn(name = "purchasingRequest")
    	private PurchasingRequest purchasingRequest;
    	
    	
    
    	public QuotationDetail() {
    
    	}
    
    	public QuotationDetail(String quotationNo, Date date, String termOfPayment,
    			String quotationRemark, Member memberNo, Customer customerNo,
    			PurchasingOrder purchasingOrderNo,
    			PurchasingRequest purchasingRequestNo) {
    		super();
    		quotationNo = quotationNo;
    		date = date;
    		termOfPayment = termOfPayment;
    		quotationRemark = quotationRemark;
    		memberNo = memberNo;
    		customerNo = customerNo;
    		purchasingOrderNo = purchasingOrderNo;
    		purchasingRequestNo = purchasingRequestNo;
    
    	}
    
    	// getter and setter
    
    	public Long getId() {
    		return id;
    	}
    
    	public void setId(Long id) {
    		this.id = id;
    	}
    
    	public String getQuotationNo() {
    		return quotationNo;
    	}
    
    	public void setQuotationNo(String quotationNo) {
    		this.quotationNo = quotationNo;
    	}
    
    	public Date getDate() {
    		return date;
    	}
    
    	public void setDate(Date date) {
    		this.date = date;
    	}
    
    	public String getTermOfPayment() {
    		return termOfPayment;
    	}
    
    	public void setTermOfPayment(String termOfPayment) {
    		this.termOfPayment = termOfPayment;
    	}
    
    	public String getQuotationRemark() {
    		return quotationRemark;
    	}
    
    	public void setQuotationRemark(String quotationRemark) {
    		this.quotationRemark = quotationRemark;
    	}
    
    	// new get/set of memberNo and customerNo
    
    //
    //	public String getCustomerNo() {
    //		return customerNo;
    //	}
    //
    //	public void setCustomerNo(String customerNo) {
    //		this.customerNo = customerNo;
    //	}
    //
    //	
    //	public String getMemberNo() {
    //		return memberNo;
    //	}
    //
    //	public void setMemberNo(String memberNo) {
    //		this.memberNo = memberNo;
    //	}
    
    
    	public Member getMember() {
    		return member;
    	}
    
    	public void setMember(Member member) {
    		this.member = member;
    	}
    
    
    	public Customer getCustomer() {
    		return customer;
    	}
    
    	public void setCustomer(Customer customer) {
    		this.customer = customer;
    	}
    
    	public String getPurchasingOrderNo() {
    		return purchasingOrderNo;
    	}
    
    	public void setPurchasingOrderNo(String purchasingOrderNo) {
    		this.purchasingOrderNo = purchasingOrderNo;
    	}
    
    	public PurchasingOrder getPurchasingOrder() {
    		return purchasingOrder;
    	}
    
    	public void setPurchasingOrder(PurchasingOrder purchasingOrder) {
    		this.purchasingOrder = purchasingOrder;
    	}
    
    	public String getPurchasingRequestNo() {
    		return purchasingRequestNo;
    	}
    
    	public void setPurchasingRequestNo(String purchasingRequestNo) {
    		this.purchasingRequestNo = purchasingRequestNo;
    	}
    
    	public PurchasingRequest getPurchasingRequest() {
    		return purchasingRequest;
    	}
    
    	public void setPurchasingRequest(PurchasingRequest purchasingRequest) {
    		this.purchasingRequest = purchasingRequest;
    	}
    	
    
    }
    and the bean
    Code:
     <bean id="addQuotation1Controller" class="MPrint.MVC.controller.AddQuotation1Controller">
    		<property name="quotationDetailDAO" ref="quotationDetailDAO" />
    		<property name="memberDAO" ref="memberDAO" />
    		<property name="customerDAO" ref="customerDAO" />
    		<property name="purchasingRequestDAO" ref="purchasingRequestDAO" />
    		<property name="purchasingOrderDAO" ref="purchasingOrderDAO" />
    		<property name="formView" value="quotationPage/addQuotation1" />
    		<property name="commandName" value="quotationDetail" />
    		<property name="commandClass" value="MPrint.MVC.Model.QuotationDetail" />
    		<property name="successView" value="quotationPage/addQuotation2" />
    	</bean>
    the jsp page allow user to add the data in the text box and has display the drop down menu from defined data in database


    thing that i really need is "make this page go to the addQuotation2 page by click submit button"

    i need suggestion how to do with my controller..... please help
    Last edited by belion; Aug 26th, 2010 at 07:44 AM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    that is never going to work. You are using a SimpleFormController and thus should NEVER override the handleRequest method, by doing so you have destroyed the flow of the simpleformcontroller.

    If you want wizard style functionality use spring web flow, which is designed/build for that.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Aug 2010
    Posts
    3

    Default

    thank you so much..

    but if you have any suggestions to solve this problem that is not spring web flow please tell me :3

    because i have no experiences in their and i have to submit my project in this nearly month(i'm a student with tiny knowledge T.T) i have no idea to make it work now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •