"SSH Project Combat" national tax cooperation platform-32. I want to complain function 2

Source: Internet
Author: User

We're going to do the preservation of the complaint information.

Let's start by thinking about the process of our entire complaint:
1. Keep the complaint information

2. Prompt the user to complain successfully

3. Refresh the parent window

4. Close the current window
Let's draw a time series diagram (the interaction of a message between an object and an object in chronological order):

What we're going to do now is the steps after the 9th step.

We review our complaint information to fill out the interface:
<%@ page contenttype= "Text/html;charset=utf-8" language= "java"%><% pagecontext.setattribute ("BasePath", Request.getcontextpath () + "/");%>
We add an onclick event to the Save announce:
<input type= "button" class= "BtnB2" value= "Save" onclick= "Dosubmit ()"/>

Then complete the Dosubmit () method of the onclick in <script></script>:
Submit Form Function Dosubmit () {    //1. Submit form and save    $.ajax ({    URL: "${basepath}sys/home_complainadd.action",    data:$ ("#form"). Serialize (),    type: "Post",    Async:false,    success:function (msg) {    if ("success" = = msg) {    //2. Prompt user to complain success    alert ("Complaint successful!");    3. Refresh the parent window    window.opener.parent.location.reload (true);    4. Close the current window    window.close ();    } else{    alert ("Complaint failed!");    }    ,    error:function () {alert ("Complaint failed!");}    );}

Since we use Ajax to save our complaint information, we need to get our Title attribute content, Department attribute content, complainant attribute content, text attribute and so on from the page, we use $ ("#form"). Serialize () to get all the label values for the entire page.

(Explain $ ("#form"). Serialize ():
The serialize () method creates a URL-encoded text string by serializing the form value.
You can select one or more form elements (such as input and/or text boxes), or the form element itself.
The serialized value can be used in the URL query string when generating an AJAX request.

)

We will then add the Complainadd method in Homeaction to complete the complaint information:
Inject complainservice@resourceprivate complainservice complainservice;//complaint Information Package object private complain Comp;public Complain Getcomp () {return comp;} public void Setcomp (complain comp) {this.comp = comp;} Save complaint Information public void Complainadd () {try {if (comp! = NULL) {//Set default complaint status to Pending Comp.setstate (Complain.complain_state_undone) ; Comp.setcomptime (New Timestamp () GetTime ()); Complainservice.save (comp);//output complaint result HttpServletResponse Response = Servletactioncontext.getresponse (); Response.setcontenttype ("text/html"); Servletoutputstream outputstream = Response.getoutputstream () outputstream.write ("Success". GetBytes ("Utf-8")); O Utputstream.close ();}} catch (Exception e) {e.printstacktrace ();}}

Let's take a look at how our complaint information is saved successfully:

First enter a variety of our complaint information, then click Save:


You will first see a popup dialog box:


Then click "OK", our complaint information editing page will be closed, we go to the "tax services" under the "Complaints management" function to view, found that our complaint information has been successfully saved:


Click "Accept", we can see the details of our complaint information:


Finally, we resolve the query condition that we have been yelling about before:
First, add the following attribute to our Complainaction:
private string Strtitle;private string Strstate;public string Getstrtitle () {return strtitle;} public void Setstrtitle (String strtitle) {this.strtitle = strtitle;} Public String Getstrstate () {return strstate;} public void Setstrstate (String strstate) {this.strstate = strstate;}

Prevent these two conditions from being overwritten in Dealui:
Public String Dealui () {//Load state collection Actioncontext.getcontext (). Getcontextmap (). Put ("Complainstatemap", COMPLAIN.COMPLAIN_STATE_MAP); if (complain!=null) {strtitle=complain.getcomptitle (); Strstate=complain.getstate (); Complain=complainservice.findobjectbyid (Complain.getcompid ());} return "Dealui";}

Then add the hidden values in the dealui.jsp:
<s:hidden name= "Complain.compid"/><s:hidden name= "strtitle"/><s:hidden name= "StrState"/><s: Hidden name= "StartTime"/><s:hidden name= "EndTime"/><s:hidden name= "PageNo"/>

These parameters are then added to the action redirect jump for the Complain-struts.xml configuration file:
<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE struts Public "-//apache software foundation//dtd struts Configuration 2.3//en" "http://struts.apache.org/dtds/ Struts-2.3.dtd "><struts><package name=" complain-action "namespace="/tax "extends=" Base-default "> <action name= "complain_*" class= "cn.edu.hpu.tax.complain.action.ComplainAction" method= "{1}" ><result name = "{1}" >/web-inf/jsp/tax/complain/{1}.jsp</result><result name= "list" type= "Redirectaction" >< param name= "ActionName" >complain_listui</param><param name= "Complain.comptitle" >${strTitle}</ Param><param name= "complain.state" >${strstate}</param><param name= "StartTime" >${startTime} </param><param name= "EndTime" >${endtime}</param><param name= "PageNo" >${pageNo}</param ><param name= "encode" >true</param><!--need to encode--></result></action></package ></struts>

Our echo function is complete. Also retains the current page of our paging (other features of pagination we have done in baseaction, and our complainaction, has inherited baseaction).

Test, we search for "problem":

A total of 7 test data, and then we turn to the second page, the second page of the first article to accept


After jumping to the acceptance page, we fill in the Reply and click Save



Then we re-jump back to the interface and find that our query criteria and the current number of pages are


This completes the work of our paging and the status of the query condition echoing.

Reprint Please specify source: http://blog.csdn.net/acmman/article/details/50144467

"SSH Project Combat" national tax cooperation platform-32. I want to complain function 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.