1 package action; 2 3 import javax.servlet.http.HttpServletRequest ; 4 import javax.servlet.http.HttpServletResponse ; 5 6 import org.apache.struts.action.Action; 7 import org.apache.struts.action.ActionErrors; 8 import org.apache.struts.action.ActionForm; 9 import org.apache.struts.action.ActionForward; 10 import org.apache.struts.action.ActionMapping; 11 import org.objectstyle.cayenne.access.DataContext; 12 import org.objectstyle.cayenne.conf.ServletUtil; 13 14 import webtest.Artist; 15 import formbean.ArtistForm; 16 17 public class SaveArtistAction extends Action { 18 19 public ActionForward execute( 20 ActionMapping mapping, 21 ActionForm form, 22 HttpServletRequest request, 23 HttpServletResponse response) 24 throws Exception { 25 26 ArtistForm artistForm = (ArtistForm) form; 27 28 ActionErrors errors = new ActionErrors(); 30 errors = artistForm.validate(mapping, request); 31 32 if (!errors.isEmpty()) { 34 saveErrors(request, errors); 35 saveToken(request); 36 return (new ActionForward(mapping.getInput())); 37 } 38 39 DataContext ctxt = 40 ServletUtil.getSessionContext(request.getSession()); 41 42 Artist anArtist = (Artist) ctxt.createAndRegisterNewObject(Artist.class); 43 anArtist.setArtistName(artistForm.getArtistName()); 44 anArtist.setDateOfBirth(new java.sql.Date (System.currentTimeMillis())); 45 46 ctxt.commitChanges(); 48 49 return (mapping.findForward("success")); 50 } 51 } 52 | Popular Tags |