📄 savetxaction.java
字号:
package org.helpsoft.actions;
import java.text.SimpleDateFormat;
import javax.servlet.*;
import javax.servlet.http.*;
import org.helpsoft.servicelocator.*;
import org.helpsoft.session.AssociatorManageService;
import org.apache.struts.action.*;
import org.helpsoft.forms.*;
import com.helpsoft.util.log.*;
import com.helpsoft.util.*;
import com.helpsoft.util.genelv.struts.GenericAction;
import org.helpsoft.session.*;
import org.helpsoft.entity.tx.*;
import com.helpsoft.Constants;
import org.helpsoft.forms.TxForm;
/**
* Implementation of <strong>Action</strong>
*
* @author cao guangxin - www.relationinfo.com
* @struts.action path="/saveTx"
* type="org.helpsoft.actions.SaveTxAction"
* name="txForm"
* scope="request"
* input="/tx.jsp"
* @struts.action-forward name="success" path="/initTxSearch.do"
*/
public class SaveTxAction extends ServiceAction {
private transient Logger log = LogService.getLogger(this.getClass());
/**
* Performs an action.
*
* @param mapping The ActionMapping used to select this instance
* @param form The optional ActionForm bean for this request (if any)
* @param request The optional ActionForm bean for this request (if any)
* @param response The HTTP response we are creating
* @return describes where and how control should be forwarded, or <code>null</code> if the response has already
* been completed
* @throws Exception in case of an error
*/
public ActionForward doPerform(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
log.info("start doPerform");
HttpSession session = request.getSession();
TxForm subform = (TxForm) form;
String txbh = subform.getTxbh();
if (txbh != null && (txbh.equalsIgnoreCase("null") || txbh.length() < 1)) {
txbh = null;
subform.setTxbh(null);
}
org.helpsoft.session.AssociatorManageService facade = getAssociatorManageService();
// Was this transaction cancelled?
if (isCancelled(request)) {
if (mapping.getAttribute() != null) {
session.removeAttribute(mapping.getAttribute());
}
return (mapping.findForward("success"));
}
try {
// Retrieve the information
TxData data = new TxData();
PropertyUtilsExt.copyProperties(data, subform);
// Save to database..
if ("new".equals(subform.getMode())) {
if (request.getParameter("submit") != null) {
facade.addTx(data);
}
}
else {
if (request.getParameter("submit") != null) {
facade.saveTx(data);
}
else if (request.getParameter(Constants.SUBMIT_NO_VALIDATION) != null) {
facade.deleteTx(data.getTxbh());
}
}
}
catch (Throwable t) {
log.error("SaveTxAction :", t);
throw new Exception("SaveTxAction :", t);
}
// Remove the obsolete form bean
if (mapping.getAttribute() != null) {
if ("request".equals(mapping.getScope())) {
request.removeAttribute(mapping.getAttribute());
}
else {
session.removeAttribute(mapping.getAttribute());
}
}
return mapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -