Agenda jsp

0 respostas
alvarofederal

Como faço para poder linkar a minha jsp, com a minha action (PessoaAction), minha implementação DAO (PessoaDAOImpl) , minha entity (Pessoa) , minha interface (IPessoaService) e minha Sevice(PessoaServiceImpl)abaixo:

JSP:

<%@ taglib prefix=“s” uri="/struts-tags"%>

Inserir Pessoa


Nome:
<td><s:property value="id"/></td>
	
	<s:url id="alterarPessoa" method="carregarAlterar" action="pessoa">
		<s:param name="pessoa.id" value="top.id"/>
	</s:url>
	<td><s:a href="%{alterarPessoa}"><s:property value="nome"/></s:a></td>
</tr>

</s:iterator>
</s:form>

PessoaAction.java:

/**
*
*/
package br.com.stefanini.treinamento.talento.struts.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.config.Namespace;

import org.apache.struts2.config.ParentPackage;

import org.apache.struts2.config.Result;

import org.apache.struts2.config.Results;

import br.com.stefanini.treinamento.talento.entity.Pessoa;
import br.com.stefanini.treinamento.talento.service.IPessoaService;

import com.opensymphony.xwork2.ActionSupport;

/**

  • @author
*/

@Results ({

@Result (name=PessoaAction.RESULT_INSERIR, value="/pessoa/inserirPessoa.jsp"),

@Result (name=PessoaAction.RESULT_ALTERAR, value="/pessoa/alterarPessoa.jsp")

})

@ParentPackage (struts-talento)

@Namespace ("/")

public class PessoaAction extends ActionSupport {
protected static final String RESULT_INSERIR = "RESULT_INSERIR";
protected static final String RESULT_ALTERAR = "RESULT_ALTERAR";

private IPessoaService pessoaService;

private Pessoa pessoa;

public String carregarInserir() {
	return RESULT_INSERIR;
}

public String inserir() {
	try {
		getPessoaService().inserir(getPessoa());			
	} catch (Exception e) {
		e.printStackTrace();
		addActionError(e.getMessage());
	}
	
	return RESULT_INSERIR;
}


public String alterar() {
	try {
		Pessoa pessoaExistente = getPessoaService().findById(getPessoa().getId());
		
		pessoaExistente.setNome(getPessoa().getNome());
		
		getPessoaService().alterar(pessoaExistente);			
	} catch (Exception e) {
		e.printStackTrace();
		addActionError(e.getMessage());
	}
	
	return RESULT_INSERIR;
}


public String carregarAlterar() {
	setPessoa(getPessoaService().findById(getPessoa().getId()));
	return RESULT_ALTERAR;
}

public String remover() {
	try {
		getPessoaService().remove(getPessoa());			
	} catch (Exception e) {
		e.printStackTrace();
		addActionError(e.getMessage());
	}
	
	return RESULT_INSERIR;
}

public Pessoa getPessoa() {
	if (this.pessoa == null) {
		this.pessoa = new Pessoa();
	}

	return this.pessoa;
}

public void setPessoa(Pessoa pessoa) {
	this.pessoa = pessoa;
}

public List<Pessoa> getPessoas() {
	return getPessoaService().getTodos();
}

public IPessoaService getPessoaService() {
	return pessoaService;
}

@Resource(name="PessoaService")
public void setPessoaService(IPessoaService pessoaService) {
	this.pessoaService = pessoaService;
}

}

Entyti:
/**
*
*/
package br.com.stefanini.treinamento.talento.entity;

import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.Id;

/**

  • @author pedroigor

*/
@Entity
public class Pessoa extends AbstractEntity {

private Long id;

private String nome;

private String sexo;

@Id
@GeneratedValue
public Long getId() {
	return id;
}

public void setId(Long id) {
	this.id = id;
}

@Column
public String getNome() {
	return nome;
}

public void setNome(String nome) {
	this.nome = nome;
}

@Column
public String getSexo() {
	return sexo;
}

public void setSexo(String sexo) {
	this.sexo = sexo;
}

public void inserir(Pessoa pessoaService) {
	// TODO Auto-generated method stub
	
}

}

DAO:

/**
*
*/
package br.com.stefanini.treinamento.talento.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import br.com.stefanini.treinamento.talento.dao.IPessoaDAO;
import br.com.stefanini.treinamento.talento.entity.Pessoa;

/**

  • @author pedroigor
*/

@Repository (PessoaDAO)

public class PessoaDAOImpl extends AbstractEntityDAOImpl implements IPessoaDAO {
@Override
protected Class getEntityClass() {
	return Pessoa.class;
}

}

Service:

/**
*
*/
package br.com.stefanini.treinamento.talento.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import org.springframework.transaction.annotation.Propagation;

import org.springframework.transaction.annotation.Transactional;
import br.com.stefanini.treinamento.talento.dao.IEntityDAO;

import br.com.stefanini.treinamento.talento.entity.Pessoa;

import br.com.stefanini.treinamento.talento.service.IPessoaService;

/**

  • @author pedroigor
*/

@Service(PessoaService)

public class PessoaServiceImpl extends AbstractEntityServiceImpl implements IPessoaService {
@Override
@Transactional (propagation=Propagation.REQUIRED)
public void inserir(Pessoa entity) {
	if (entity.getNome() == null) {
		throw new IllegalArgumentException("O nome nao foi preenchido.");
	}
	
	super.inserir(entity);
}

@Override
@Resource (name="PessoaDAO")
protected void setDao(IEntityDAO<Pessoa> dao) {
	super.setDao(dao);
}

}

Isso é apenmas uma agenda, mas não consigo fazer as ligações.

  ID Nome
Remover
Criado 21 de abril de 2010
Respostas 0
Participantes 1