1 16 17 18 package org.apache.velocity.tools.struts; 19 20 import javax.servlet.http.HttpServletRequest ; 21 import javax.servlet.http.HttpSession ; 22 import javax.servlet.ServletContext ; 23 24 import org.apache.struts.util.MessageResources; 25 import org.apache.struts.action.*; 26 27 import org.apache.velocity.tools.view.context.ViewContext; 28 import org.apache.velocity.tools.view.tools.ViewTool; 29 30 31 53 public class FormTool implements ViewTool 54 { 55 56 58 59 62 protected HttpServletRequest request; 63 64 65 68 protected HttpSession session; 69 70 71 72 74 77 public FormTool() 78 { 79 } 80 81 82 88 public void init(Object obj) 89 { 90 if (!(obj instanceof ViewContext)) 91 { 92 throw new IllegalArgumentException ("Tool can only be initialized with a ViewContext"); 93 } 94 95 ViewContext context = (ViewContext)obj; 96 this.request = context.getRequest(); 97 this.session = request.getSession(false); 98 } 99 100 101 102 104 124 public ActionForm getBean() 125 { 126 return StrutsUtils.getActionForm(request, session); 127 } 128 129 130 137 public String getCancelName() 138 { 139 return org.apache.struts.taglib.html.Constants.CANCEL_PROPERTY; 140 } 141 142 143 147 public String getToken() 148 { 149 return StrutsUtils.getToken(session); 150 } 151 152 153 158 public String getTokenName() 159 { 160 return org.apache.struts.taglib.html.Constants.TOKEN_KEY; 161 } 162 163 } 164 | Popular Tags |