Skip to content

Instantly share code, notes, and snippets.

@rafaeltoledo
Created November 7, 2019 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaeltoledo/a9b1e8e3bab8f7707eaa8c5f12f243cd to your computer and use it in GitHub Desktop.
Save rafaeltoledo/a9b1e8e3bab8f7707eaa8c5f12f243cd to your computer and use it in GitHub Desktop.
Mentawai 02
package net.rafaeltoledo.mentawai.pojo;
public class Funcionario {
private String nome;
private String cpf;
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
}
package net.rafaeltoledo.mentawai.filters.action;
import net.rafaeltoledo.mentawai.filters.pojo.Funcionario;
import org.mentawai.core.BaseAction;
public class ExemploVOFilterAction extends BaseAction {
@Override
public String execute() throws Exception {
Funcionario funcionario = (Funcionario) input.getValue("funcionario");
if (funcionario == null) {
return ERROR;
}
if (funcionario.getNome() == null) {
return ERROR;
}
if (funcionario.getCpf() == null) {
return ERROR;
}
funcionario.setNome(funcionario.getNome().toUpperCase());
output.setValue("funcionario", funcionario);
return SUCCESS;
}
}
package net.rafaeltoledo.mentawai.filters;
import net.rafaeltoledo.mentawai.filters.action.ExemploVOFilterAction;
import net.rafaeltoledo.mentawai.filters.pojo.Funcionario;
import org.mentawai.core.ActionConfig;
import org.mentawai.core.Forward;
import org.mentawai.filter.VOFilter;
public class ApplicationManager extends org.mentawai.core.ApplicationManager {
@Override
public void loadActions() {
ActionConfig ac = new ActionConfig("/ExemploVOFilter", ExemploVOFilterAction.class);
ac.addConsequence(ExemploVOFilterAction.SUCCESS, new Forward("/exibir.jsp"));
ac.addConsequence(ExemploVOFilterAction.ERROR, new Forward("/index.jsp"));
addActionConfig(ac);
// É aqui que toda magia acontece!
ac.addFilter(new VOFilter(Funcionario.class, "funcionario"));
}
}
<%@ page language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Entrada de Dados</title>
</head>
<body>
<form action="ExemploVOFilter.mtw" method="post">
Nome: <input name="nome" size="25" /><br />
CPF: <input name="cpf" size="25" /><br />
<input type="submit" value="Enviar" />
</form>
</body>
</html>
<%@ taglib uri="http://www.mentaframework.org/tags-mtw/" prefix="mtw" %>
<%@ page language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Saída</title>
</head>
<body>
<h3>Saída do Value Object Filter</h3>
<mtw:bean value="funcionario">
<h4>Nome: <mtw:out value="nome" /></h4>
<h4>CPF: <mtw:out value="cpf" /></h4>
</mtw:bean>
</body>
</html>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment