📄 savehyaction.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.hy.*;
import com.helpsoft.Constants;
import org.helpsoft.forms.HyForm;
/**
* Implementation of <strong>Action</strong>
*
* @author cao guangxin - www.relationinfo.com
* @struts.action path="/saveHy"
* type="org.helpsoft.actions.SaveHyAction"
* name="hyForm"
* scope="session"
* input="/hy.jsp"
* @struts.action-forward name="success" path="/initHySearch.do"
*/
public class SaveHyAction 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();
HyForm subform = (HyForm) form;
String hykh = subform.getHykh();
if (hykh != null && (hykh.equalsIgnoreCase("null") || hykh.length() < 1)) {
hykh = null;
subform.setHykh(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
HyData data = new HyData();
HyklxForm theHyklxHykmmForm = subform.getHykmmHyklx();
subform.setHykmm(theHyklxHykmmForm.getHykmm());
PropertyUtilsExt.copyProperties(data, subform);
// Save to database..
if ("new".equals(subform.getMode())) {
if (request.getParameter("submit") != null) {
facade.addHy(data);
}
}
else {
if (request.getParameter("submit") != null) {
facade.saveHy(data);
}
else if (request.getParameter(Constants.SUBMIT_NO_VALIDATION) != null) {
facade.deleteHy(data.getHykh());
}
}
}
catch (Throwable t) {
log.error("SaveHyAction :", t);
throw new Exception("SaveHyAction :", 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 + -