Eu tenho este projecto para migrar o projecto não é meu por isso tá a ser dificil e precisava de uma ajudinha
estou a tentar conseguir mostrar uma lista de projectos
esta é a minha classe da minha action:
package app.action;
import java.sql.SQLException;
import org.apache.struts2.interceptor.SessionAware;
import app.Definition;
import app.model.Project;
import app.model.User;
import app.service.Api;
import com.opensymphony.xwork2.Preparable;
public class ProjectAction extends BaseAction
implements
SessionAware,
Preparable {
private static final long serialVersionUID = -7749384177808789345L;
private Api api;
private Project project;
private Project[] projects = new Project[0];
private int chosenId;
private User user;
private static final int DEFAULT_ID = 0;
public void prepare() {
setDefaultChosenId(DEFAULT_ID);
this.api = (Api) getSession().get(Definition.SESSION_API);
this.user = (User) getSession().get(Definition.SESSION_USER);
}
public void setDefaultChosenId(int id) {
this.chosenId = id;
}
public Project getProject() {
return project;
}
public void setProject(Project project) {
this.project = project;
}
public String getListProjects() throws SQLException {
if (api != null) {
projects = api.getProjectList();
return SUCCESS;
} else {
return null;
}
}
public Api getService() {
return api;
}
public void setService(Api service) {
this.api = service;
}
public Project[] getProjects() {
return projects;
}
public void setProjects(Project[] projects) {
this.projects = projects;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public int getChosenId() {
return chosenId;
}
}
esta agora é o meu struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="ph-support" namespace="/" extends="ph-default">
<action name="Access" class="app.action.AccessAction">
<result type="redirect-action">Login_input.do</result>
</action>
<action name="Login_*" method="{1}"
class="app.action.LoginAction">
<result name="input">/pages/Login.jsp</result>
<result>Controller?action=main</result>
</action>
<action name="Logout" class="app.action.LogoutAction">
<result>/pages/Login.jsp</result>
</action>
<action name="Home">
<result>/pages/Home.jsp</result>
</action>
<action name="Project_*" method="{1}" class="app.action.ProjectAction">
<result name="success">/pages/listProjects_exp.jsp</result>
<result name="blank">/pages/projectPosition.jsp</result>
<!-- lixo --><result name="black">/pages/projectPosition.jsp</result>
</action>
<action name="Client_*" method="{1}">
<result name="success">/pages/projectPosition.jsp</result>
</action>
</package>
</struts>
e por fim a jsp onde deveriam aparecer os resultados
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page
import="java.util.ResourceBundle,
app.util.LanguageResourceBundle,app.Definition,app.Action,app.util.DataFormat,app.model.Project,app.model.State,app.model.Client"%>
<%
/* Initialitation */
String state = (request.getParameter(Definition.PARAM_STATE) == null) ? ""
: request.getParameter(Definition.PARAM_STATE);
String creationFrom = (request.getParameter(Definition.PARAM_CREATION_FROM) == null) ? ""
: request.getParameter(Definition.PARAM_CREATION_FROM);
String creationUntil = (request.getParameter(Definition.PARAM_CREATION_UNTIL) == null) ? ""
: request.getParameter(Definition.PARAM_CREATION_UNTIL);
String client = (request.getParameter(Definition.PARAM_CLIENT) == null) ? ""
: request.getParameter(Definition.PARAM_CLIENT);
String project = (request.getParameter(Definition.PARAM_SELECTED_PROJECT_ID) == null) ? ""
: request.getParameter(Definition.PARAM_SELECTED_PROJECT_ID);
String message = (request.getAttribute("message") == null) ? ""
: request.getAttribute("message").toString();
Project[] projectList = (request.getAttribute(Definition.ATRIB_PROJECT_LIST) == null) ? new Project[0]
: (Project[]) request.getAttribute(Definition.ATRIB_PROJECT_LIST);
State[] stateList = (request.getAttribute(Definition.ATRIB_STATE_LIST) == null) ? new State[0]
: (State[]) request.getAttribute(Definition.ATRIB_STATE_LIST);
Client[] clientList = (request.getAttribute(Definition.ATRIB_CLIENT_LIST) == null) ? new Client[0]
: (Client[]) request.getAttribute(Definition.ATRIB_CLIENT_LIST);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href="styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="common.js"></script>
<script type="text/javascript" src="listProjects.js"></script>
<%@taglib prefix="s" uri="/struts-tags"%>
<title>Lista de Projectos</title>
</head>
<body>
<s:form action="Project">
<div align="center">
<table class="container" width="1000">
<tr>
<td>
<table class="container">
<tr>
<td>
<table class="container">
<tr>
<td width="500" class="title">Lista de Projectos</td>
<td width="500" class="data" align="right"><a class="link"
name="linkToBlank" id="linkToBlank"
href="<%=Action.goto_(Action.PROJECT_BLANK)%>"
title="Novo Projecto"
onmouseover="javascript: onMouseOverLink(this.id);"
onmouseout="javascript: onMouseOutLink(this.id);"> Novo </a>
| <a class="link" name="linkToMain" id="linkToMain"
href="<s:url action="Home.action" ></s:url>"
title="Ir ao início da aplicação"
onmouseover="javascript: onMouseOverLink(this.id);"
onmouseout="javascript: onMouseOutLink(this.id);"> Início </a>
| <a class="link" name="linkLogout" id="linkLogout"
href="Logout.do"
title="Sair da aplicação"
onmouseover="javascript: onMouseOverLink(this.id);"
onmouseout="javascript: onMouseOutLink(this.id);"
onclick="return confirm('Confirma que deseja sair da aplicação?');">
Sair</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table class="header">
<tr>
<td width="100">Criado:</td>
<td width="450">Nome</td>
<td width="140">Cliente</td>
<td width="100">Início</td>
<td width="100">Fim</td>
<td width="100">Estado</td>
<td width="17"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<div
style="overflow: auto; width: 1000px; height: 164px; align: left;">
<table class="container">
<%
int cont = 0;
String bgcolor = "";
for (int i = 0; i < projectList.length; i++) {
if (projectList[i].isVisible()) {
if (cont % 2 != 0)
bgcolor = "bgcolor=\"#EEEEEE\"";
else
bgcolor = "";
%>
<s:iterator value="projects">
<tr <%=bgcolor%> name="project" id="project"
title="<s:property value="project.name"/>"
onmouseover="javascript: emorunemphasizeElementExcept('project', <%=cont%>, 'emphasizedRow', 'selectedRow');"
onmouseout="javascript: emorunemphasizeElementExcept('project', <%=cont%>, '', 'selectedRow');"
onclick="javascript: selectElement('project', <%=cont%>, '', 'selectedRow');
selectComboOption('Definition.PARAM_PROJECT_ID', '<s:property value="project.id"/>');"
ondblclick="javascript:document.form2.submit();">
<td width="100" class="data"><s:property value="DataFormat.dateToString(project.creationDate())"/></td>
<td width="450" class="data"><s:property value="project.name"/></td>
<td width="140" class="data"><s:property value="project.client.name"/></td>
<td width="100" class="data"><s:property value="dataFormat.dateToString(project.initDate)"/></td>
<td width="100" class="data"><s:property value="dataFormat.dateToString(project.endDate)"/></td>
<td width="100" class="data"><s:property value="project.state.name"/></td>
<s:hidden name="projects[%{#rowStatus.index}].project.description" value="%{project.description}"/>
<s:hidden name="projects[%{#rowStatus.index}].project.adjustment" value="%{project.adjustment}"/>
<s:hidden name="projects[%{#rowStatus.index}].project.id" value="%{project.id}"/>
<s:hidden name="projects[%{#rowStatus.index}].project.partialCost" value="%{project.partialCost}"/>
<s:hidden name="projects[%{#rowStatus.index}].project.subtotals" value="%{project.subtotals}"/>
<s:hidden name="projects[%{#rowStatus.index}].project.taskList" value="%{project.taskList}"/>
<s:hidden name="projects[%{#rowStatus.index}].project.totalTime" value="%{project.totalTime}"/>
<s:hidden name="projects[%{#rowStatus.index}].project.transitionList" value="%{project.transitionList}"/>
<s:hidden name="projects[%{#rowStatus.index}].project.visible" value="%{project.visible}"/>
<s:hidden name="projects[%{#rowStatus.index}].project.description" value="%{project.description}"/>
<s:hidden name="projects[%{#rowStatus.index}].pricing.id" value="%{pricing.id}"/>
<s:hidden name="projects[%{#rowStatus.index}].pricing.name" value="%{pricing.name}"/>
<s:hidden name="projects[%{#rowStatus.index}].pricing.prices" value="%{pricing.prices}"/>
<s:hidden name="projects[%{#rowStatus.index}].state.id" value="%{state.id}"/>
<s:hidden name="projects[%{#rowStatus.index}].state.name" value="%{state.name}"/>
<s:hidden name="projects[%{#rowStatus.index}].client.id" value="%{client.id}"/>
<s:hidden name="projects[%{#rowStatus.index}].client.email" value="%{client.email}"/>
<s:hidden name="projects[%{#rowStatus.index}].client.name" value="%{client.name}"/>
</tr>
</s:iterator>
<%
cont++;
}
}
for (int i = cont; i < 11; i++) {
if (cont % 2 != 0)
bgcolor = "bgcolor=\"#EEEEEE\"";
else
bgcolor = "";
%>
<tr <%=bgcolor%> name="project" id="project"
onmouseover="javascript: emorunemphasizeElement('project', <%=i%>, 'emphasizedRow');"
onmouseout="javascript: emorunemphasizeElement('project', <%=i%>, '');">
<td width="100" class="data"> </td>
<td width="450" class="data"> </td>
<td width="140" class="data"> </td>
<td width="100" class="data"> </td>
<td width="100" class="data"> </td>
<td width="100" class="data"> </td>
</tr>
<%
cont++;
}
%>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table class="container">
<tr>
<td>
<table class="header">
<tr>
<td width="1000">Filtragem</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="data"> </td>
</tr>
<tr>
<td>
<form action="<%=Action.goto_(Action.PROJECT_LIST)%>" method="post"
name="form1" id="form1">
<table class="container">
<tr>
<td width="240" class="label"><label for="state">Estado </label>
<select name="Definition.PARAM_STATE" class="comboBox"
id="Definition.PARAM_STATE"
onChange="javascript:document.form1.submit();">
<option value=""></option>
<%
String selected = "";
for (int i = 0; i < stateList.length; i++) {
if (state.equals("" + stateList[i].getId()))
selected = "selected=\"selected\"";
else
selected = "";
%>
<option value="<%=stateList[i].getId()%>" <%=selected%>><%=stateList[i].getName()%> </option>
<%
}
%>
</select></td>
<td width="400" class="label" title="dd-mm-aaaa">Criado <label
for="Definition.PARAM_CREATION_FROM">desde </label>
<input type="text" class="textBox"
name="Definition.PARAM_CREATION_FROM"
id="Definition.PARAM_CREATION_FROM" value="<%=creationFrom%>"
size="11" maxlength="10" /> <label
for="Definition.PARAM_CREATION_UNTIL">até </label>
<input type="text" class="textBox"
name="Definition.PARAM_CREATION_UNTIL"
id="Definition.PARAM_CREATION_UNTIL" value="<%=creationUntil%>"
size="11" maxlength="10" /> </td>
<td width="220" class="label"><label for="state">Cliente </label>
<select name="Definition.PARAM_CLIENT" class="comboBox"
id="Definition.PARAM_CLIENT"
onChange="javascript:document.form1.submit();">
<option value=""></option>
<%
for (int i = 0; i < clientList.length; i++) {
if (client.equals("" + clientList[i].getId()))
selected = "selected=\"selected\"";
else
selected = "";
if (clientList[i].getId() != 0) {
%>
<option value="<%=clientList[i].getId()%>" <%=selected%>><%=DataFormat.cutStringInf(clientList[i].getName(), 18)%> </option>
<%
}
}
%>
</select></td>
<td width="140" align="right"><input type="button"
class="button" name="clear" id="clear" value="Limpar"
title="Limpar filtro" onmouseover="onMouseOverButton(this.id)"
onmouseout="onMouseOutButton(this.id)"
onclick="javascript:cleanForm();"> <input type="submit"
class="button" name="search" id="search" value="Filtrar"
title="Aplicar filtro na lista de projectos"
onmouseover="onMouseOverButton(this.id)"
onmouseout="onMouseOutButton(this.id)"></td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td>
<table class="header">
<tr>
<td width="1000">Ir ao projecto </td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="data"> </td>
</tr>
<tr>
<td>
<form action="<%=Action.goto_(Action.PROJECT_INFO)%>" method="post"
name="form2" id="form2">
<table class="container">
<tr>
<td width="1000" class="data" align="center"><label
for="project">Projecto </label> <select
name="Definition.PARAM_SELECTED_PROJECT_ID"
class="comboBox-fixed"
id="Definition.PARAM_SELECTED_PROJECT_ID%" width="800"
onchange="javascript: selectElement('project', this.selectedIndex - 1, '', 'selectedRow');">
<option value=""></option>
<%
for (int i = 0; i < projectList.length; i++) {
if (projectList[i].isVisible()) {
if (project.equals("" + projectList[i].getId()))
selected = "selected=\"selected\"";
else
selected = "";
%>
<option value="<%=projectList[i].getId()%>" <%=selected%>><%=DataFormat.cutStringInf(projectList[i].getName(), 36)%> </option>
<%
}
}
%>
</select> <input type="submit" class="button"
name="Definition.PARAM_LP_GOTO" id="Definition.PARAM_LP_GOTO"
value="Ir" title="Ir ao projecto selecionado"
onmouseover="onMouseOverButton(this.id)"
onmouseout="onMouseOutButton(this.id)"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
<table class="message">
<tr>
<td> <%=message%> </td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</s:form>
</body>
</html>
ja me esquecia esta e o método getListProjects
public Project[] getProjectList() throws SQLException {
List projectList = new ArrayList();
Project[] projects = new Project[0];
State[] states = getStateList();
Client[] clients = getClientList();
Pricing[] pricings = getPricingList();
String query = "SELECT * FROM t_project ORDER BY t_project_creation DESC";
PreparedStatement preparedStatement = Transact.prepareQuery(con, query);
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
Project project = new Project();
project.setId(resultSet.getInt(1));
project.setName(resultSet.getString(2));
project.setClient(Client.getClientById(clients, resultSet.getInt(3)));
project.setCreationDate(new java.util.Date(resultSet.getTimestamp(4).getTime()));
project.setInitDate(new java.util.Date(resultSet.getTimestamp(5).getTime()));
project.setEndDate(new java.util.Date(resultSet.getTimestamp(6).getTime()));
project.setDescription(resultSet.getString(7));
project.setState(State.getStateById(states, resultSet.getInt(8)));
project.setPricing(Pricing.getObject(resultSet.getInt(9), pricings));
project.setAdjustment(resultSet.getInt(10));
project.setVisible(resultSet.getBoolean(11));
projectList.add(project);
}
resultSet.close();
preparedStatement.close();
projects = (Project[]) projectList.toArray(new Project[projectList.size()]);
return projects;
}
desculpem se é muito código para analisar mas eu tou mesmo sem ideias para por isto a funcionar! Quem conseguir fica com a minha eterna amizade :lol: