I want to know if anyone here knows how to get an array from a controller using Struts?
showTeams.jsp
<%@page import="java.util.ArrayList"%>
<%@page import="nl.***.controller.TeamController"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@include file="includes/layout.jsp" %>
<div class="col-lg-12">
<h1>Alle Teams</h1>
<table>
<caption><h1>List of Teams</h1></caption>
<th>ID Team</th>
<th>Naam Team</th>
<tr>
<c:forEach var="team" items="${teams}">
<td>${team.getId}<td>
<td>${team.getName()}<td>
</c:forEach>
</tr>
</table>
</div>
<a href="index.jsp">Back to Start</a>
<%@include file="includes/footer.jsp" %>
TeamController.java
package nl.***.controller;
import java.util.ArrayList;
import nl.***.datalayer.DAOTeam;
import nl.***.models.Team;
import com.opensymphony.xwork2.ActionSupport;
/**
*
* @author
*/
public class TeamController extends ActionSupport{
private String name;
ArrayList<Team> teams = new ArrayList<Team>();
public String execute() throws Exception{
return "createTeam";
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String addTeamToDB(String name){
try{
Team t = new Team(name);
DAOTeam.getInstance().createTeam(t);
return "<h1>Team " + name + " is toegevoegd aan de Database</h1>";
}catch(Exception e){
return "<h1>FAILED with message" + e.getMessage() + "</h1>";
}
}
public String getAllTeams(){
teams = DAOTeam.getInstance().loadTeams();
System.out.println("ik ben er!!@#!EWDSRETGDFQTWTRE"); //for testing, removed when done
//mapping.findForward("showTeams");
return "getallteams";
}
}
struts.xml
<struts>
<constant name="struts.devMode" value="true" />
<package name="teamcreate" extends="struts-default">
<action name="createTeam"
class="controller.TeamController"
method="execute">
<result name="createTeam">/view/prossesTeam.jsp</result>
</action>
</package>
<package name="teamLoad" extends="struts-default">
<action name="showTeams"
class="controller.TeamController"
method="getallteams">
<result name="getallteams">/view/showTeams.jsp</result>
</action>
</package>
</struts>
When I load the page it does not have the array 'teams' defined in the controller. I've tried changing values in struts.xml but still nothing. If tried to make an if statement in the execute function in TeamController to make sure it even ran but I got nothing I don't know what I'm doing wrong.
EDIT:
What I essentially want is that when you go to showTeams.jsp, it should show you a table with all the teams using Struts.
struts iteratortag too.