Created
July 13, 2012 19:01
-
-
Save juliano/3106705 to your computer and use it in GitHub Desktop.
SimpleDev - Action do Struts 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>SimpleDev - Struts 2</title> | |
</head> | |
<body> | |
<h3>Novo Carro</h3> | |
<form action="adiciona"> | |
<table> | |
<tr> | |
<td>Nome: <input type="text" name="carro.nome"></td> | |
<td>Ano: <input type="text" name="carro.ano"></td> | |
<td><input type="submit"></td> | |
</tr> | |
</table> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'eclipse' | |
apply plugin: 'jetty' | |
apply plugin: 'maven' | |
version = '0.1-SNAPSHOT' | |
group = 'br.com.simpledev' | |
repositories { | |
mavenCentral() | |
} | |
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' | |
configurations { | |
provided | |
} | |
sourceSets { | |
main { compileClasspath += configurations.provided } | |
test { runtimeClasspath += configurations.provided } | |
} | |
eclipse.classpath.plusConfigurations += configurations.provided | |
dependencies { | |
compile 'org.apache.struts:struts2-core:2.3.4' | |
compile 'org.apache.struts:struts2-convention-plugin:2.3.4' | |
compile 'org.apache.struts.xwork:xwork-core:2.3.4' | |
compile 'ognl:ognl:3.0.5' | |
compile 'jstl:jstl:1.2' | |
compile 'org.javassist:javassist:3.16.1-GA' | |
compile 'org.freemarker:freemarker:2.3.19' | |
compile 'commons-logging:commons-logging:1.1.1' | |
compile 'commons-io:commons-io:2.1' | |
compile 'commons-fileupload:commons-fileupload:1.2.2' | |
provided 'javax.servlet:servlet-api:2.5' | |
testCompile 'org.mockito:mockito-core:1.9.0' | |
testCompile 'junit:junit:4.10' | |
} | |
[jettyRunWar, jettyRun]*.contextPath = '/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.simpledev.struts2.action; | |
import java.util.List; | |
import org.apache.struts2.convention.annotation.Action; | |
import org.apache.struts2.convention.annotation.Namespace; | |
import org.apache.struts2.convention.annotation.Result; | |
import br.com.simpledev.struts2.dao.CarroDao; | |
import br.com.simpledev.struts2.dao.jdbc.JdbcCarroDao; | |
import br.com.simpledev.struts2.model.Carro; | |
@Namespace(value = "/carro") | |
public class CarroAction { | |
private final CarroDao dao; | |
private List<Carro> carros; | |
private Carro carro; | |
public CarroAction() { | |
this.dao = new JdbcCarroDao(); | |
} | |
public CarroAction(final CarroDao dao) { | |
this.dao = dao; | |
} | |
@Action(value = "lista", | |
results = @Result(name = "ok", location = "/carro/lista.jsp")) | |
public String lista() { | |
carros = dao.lista(); | |
return "ok"; | |
} | |
@Action(value = "novo", | |
results = @Result(name = "ok", location = "/carro/adiciona.jsp")) | |
public String novo() { | |
return "ok"; | |
} | |
@Action(value = "adiciona", results = @Result(name = "ok", type = "redirectAction", params = { "actionName", "lista" })) | |
public String adiciona() { | |
dao.adiciona(carro); | |
return "ok"; | |
} | |
public List<Carro> getCarros() { | |
return carros; | |
} | |
public Carro getCarro() { | |
return carro; | |
} | |
public void setCarro(final Carro carro) { | |
this.carro = carro; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> | |
<html> | |
<head> | |
<title>SimpleDev - Struts 2</title> | |
</head> | |
<body> | |
<h3>Lista de carros</h3> | |
<table> | |
<tr> | |
<td>Id</td> | |
<td>Nome</td> | |
<td>Ano de fabricação</td> | |
</tr> | |
<c:forEach items="${carros}" var="carro"> | |
<tr> | |
<td>${carro.id}</td> | |
<td>${carro.nome}</td> | |
<td>${carro.ano}</td> | |
</tr> | |
</c:forEach> | |
</table> | |
<br> | |
<h5><a href="novo">Novo</a></h5> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/j2ee" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"> | |
<filter> | |
<filter-name>struts2</filter-name> | |
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> | |
</filter> | |
<filter-mapping> | |
<filter-name>struts2</filter-name> | |
<url-pattern>/*</url-pattern> | |
</filter-mapping> | |
</web-app> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment