pourquoi je ne passe pas dans mon action
Je ne vois pas purquoi je ne passe pas dans mon action :
voici mon formulaire :
Code:
1 2 3 4 5 6 7 8 9 10
|
<html:form action="/addrecord">
lastname : <html:text property="lastname" /><br/>
firstname : <html:text property="firstname" /><br/>
phone : <html:text property="phone" /><br/>
departement : <html:text property="departement" /><br/>
<html:submit />
</html:form> |
mon fichier de struts :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="addRecordForm" type="phoneBookForm.AddRecordForm" />
</form-beans>
<global-exceptions>
</global-exceptions>
<action-mappings>
<action path="/listrecords"
input="/index.jsp"
type="phoneBookAction.ListRecordAction"
scope="session">
<forward name="page" path="/index.jsp" />
<forward name="success" path="/resultlistrecord.jsp" />
</action>
<action path="/addrecordredirection"
type="org.apache.struts.actions.ForwardAction"
parameter="/addrecord.jsp">
</action>
<action path="/addrecord"
name="addRecordForm"
input="/addrecord.jsp"
type="phoneBookAction.AddRecordAction"
scope="session"
validate="true">
<forward name="page" path="/addrecord.jsp" />
<forward name="success" path="/resultlistrecord.jsp" />
</action>
</action-mappings>
</struts-config> |
mon action qui se trouve dans la package phoneBookAction :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
package phoneBookAction;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import phoneBookForm.AddRecordForm;
import phoneBookBo.Employee;
import phoneBookBo.Personne;
public class AddRecordAction extends Action{
ActionForward executeGet(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
return mapping.findForward("page");
}
ActionForward executePost(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
AddRecordForm addRecordForm = (AddRecordForm) form;
String lastname = addRecordForm.getLastname();
String firstname = addRecordForm.getFirstname();
String phone = addRecordForm.getPhone();
String departement = addRecordForm.getDepartement();
Employee employee = new Employee(new Personne(firstname,lastname ), phone, departement);
HashMap<String, Employee> map = new HashMap();
if(request.getSession().getAttribute("map")!=null){
map = (HashMap<String, Employee>) request.getSession().getAttribute("map");
}
employee.addRecord(map, employee.getPhone());
request.getSession().setAttribute("map", map);
return mapping.findForward("success");
}
} |
pourquoi je ne passe pas dans mon action
lorsque je lance mon test :
Code:
1 2 3 4 5 6 7 8 9
|
public void addRecordsRecordHF() {
setRequestPathInfo("/addrecord");
actionPerform();
verifyNoActionErrors();
verifyForwardPath("/resultlistrecord.jsp");
} |
J'ai cette erreur au niveau du verifyForwardPath
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
junit.framework.AssertionFailedError: Was expecting '/resultlistrecord.jsp' but it appears the Action has tried to return an ActionForward that is not mapped correctly.
at servletunit.struts.MockStrutsTestCase.verifyForwardPath(MockStrutsTestCase.java:603)
at test.ListRecordsActionTest.addRecordsRecordHF(ListRecordsActionTest.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) |
please help me:?
pourquoi je ne passe pas dans mon action
au fait, je me demande pourquoi mon test ne passe pas dans l'action AddRecordAction lors de l'exececution de la methode perform() dans mon test, pourtant je passe bel bien dans mon form.
J'ai tout tenté mais je reste bloqué la dessus:oops:
fk04
Par défaut pourquoi je ne passe pas dans mon action
Je sais maintenant :
C'est parce que je n'avais defini les methodes executePost et executeGET
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
ActionForward foward = null;
if("GET".equals(request.getMethod())){
foward = this.executeGet(mapping, form, request, response);
}else{
foward = this.executePost(mapping, form, request, response);
}
return foward;
}
MERCI A BELET:yaisse2: