I'm trying to use struts for the first time, and something is not right in my setup. I've got an Action Form called TeamForm with the following contents:
package struts.forms;
import org.apache.struts.action.ActionForm;
import domain.TeamBean;
public class TeamForm extends ActionForm {
private TeamBean teamBean = new TeamBean();
public TeamBean getTeamBean(){ return teamBean; }
public void setTeamName(String teamname) { teamBean.setTeamName(teamname); } public String getTeamName() { return teamBean.getTeamName(); }
public void setMember1(String member1) { teamBean.setMember1(member1); } public String getMember1() { return teamBean.getMember1(); }
public void setMember2(String member2) { teamBean.setMember2(member2); } public String getMember2() { return teamBean.getMember2(); }
public void setMember3(String member3) { teamBean.setMember3(member3); } public String getMember3() { return teamBean.getMember3(); }
public void setMember4(String member4) { teamBean.setMember4(member4); } public String getMember4() { return teamBean.getMember4(); }
public void setMember5(String member5) { teamBean.setMember5(member5); } public String getMember5() { return teamBean.getMember5(); } }
I have an Action called CreateTeamAction with the following: package struts.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import managers.CreateTeamMgr;
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 struts.forms.TeamForm;
import domain.TeamBean;
import exceptions.ServiceLoadException;
public class CreateTeamAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
try { TeamBean teamBean = ((TeamForm)form).getTeamBean(); boolean validTeam = (new CreateTeamMgr().authenticate(teamBean));
request.setAttribute("team", teamBean);
if(validTeam) {
System.out.println("Forwarding to teamSuccess...");
return mapping.findForward("teamSuccess");
}
else {
System.out.println("Forwarding to teamFailure...");
return mapping.findForward("teamFailure");
}
} catch (ServiceLoadException e) {
System.out.println("Forwarding to failure...");
e.printStackTrace();
return mapping.findForward("teamFailure");
}
}
}
The applicable parts of my struts-config.xml are: (Please note, the " before the opening struts-config tag is not part of my file. I had to add it to make the xml show up in the preview window.):
"<struts-config
<form-beans
<form-bean
name="teamForm"
type="struts.forms.TeamForm"/>
</form-beans>
<action-mappings>
<action
path="/team"
type="struts.actions.CreateTeamAction"
name="teamForm"
scope="request">
<forward name="success" path="/teamHome.jsp"/>
<forward name="failure" path="/teamError.jsp"/>
</action>
</action-mappings>
</struts-config>
As I understand it, Struts should be using the setters in my TeamForm to populate the values for the TeamBean. Unfortunately, this isn't happening. When I try to run, all the member data for the TeamBean is set to null. Can anyone see what I'm missing?
Thanks!