Struts2 + @ManyToMany + checkboxlist não funciona o request do checkboxlist  XML
Índice dos Fóruns » Java Avançado
Autor Mensagem
klaiddias
What is classpath?
[Avatar]

Membro desde: 24/06/2004 09:34:24
Mensagens: 5
Offline

PessoALL, estou com problemas e a dias nao estou conseguindo resolver;

Não estou conseguindo fazer a [b]Aciont[/b] recuperar os itens do meu "checkboxlist" que foram marcados, tenho um relacionamento [b]@ManyToMany[/b] que está funcionando perfeitamente porém não está gravando porque os valores não estão sendo recuperados do form;

[b]Formulário[/b]
[code]
<s:form namespace="/cadastro" action="usuario!gravar" validate="true" focusElement="email">
<s:textfield name="email" id="email" key="i18n.email" required="true"/>
<s:textfield name="senha" id="senha" key="i18n.senha" required="true"/>
<s:checkboxlist
list="%{listPerfils}"
listKey="id"
listValue="descricao"
key="i18n.perfil"
name="perfils"
/>
<s:submit name="btn_submit" key="i18n.salvar"/>
</s:form>
[/code]

[b]Action[/b]
[code]
public class UsuarioAction extends UsuarioDTO implements Preparable/*, ModelDriven<UsuarioDTO>*/ {


private static final long serialVersionUID = 8856864734519504058L;
private UsuarioService usuarioService;
private PerfilService perfilService;


public UsuarioAction(UsuarioService usuarioService, PerfilService perfilService){
this.usuarioService = usuarioService;
this.perfilService = perfilService;

}

public String execute(){
return SUCCESS;
}

@Override
public void prepare() throws Exception {
LOG.info("UsuarioAction.prepared");
}
public String gravar(){
this.usuarioService.gravar(parseModel());
this.addActionMessage(getText("i18n.gravadoComSucesso"));
return SUCCESS;
}

@SkipValidation
public String excluir(){
this.usuarioService.remover(parseModel().getId());
addActionMessage(getText("i18n.excluidoComSucesso"));
return SUCCESS;
}

/**
* @return Retorna a lista de usuários
*/
public List<UsuarioDTO> getUsuarios() {
return this.usuarioService.findAll();
}


/**
* @return the perfils
*/
public List<PerfilDTO> getListPerfils() {
return perfilService.findAll();
}

private UsuarioDTO parseModel(){
UsuarioDTO usuario = new UsuarioDTO();
usuario.setId(this.getId());
usuario.setEmail(this.getEmail());
usuario.setSenha(this.getSenha());
usuario.setPerfils(this.getPerfils());
return usuario;
}
}
[/code]

[b]Entity[/b]
[code]
@Entity
@Table(name="tb001_cliente", uniqueConstraints = {
@UniqueConstraint(columnNames="tb001_email")
}
)
@SequenceGenerator(name="sq001_cliente", sequenceName="sq001_cliente", allocationSize=1)
public class UsuarioDTO extends ActionSupport implements Serializable {
private static final long serialVersionUID = 6157460162534656163L;

@Id
@Column(name="tb001_id")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="sq001_cliente")
private Long id;

@Column(name="tb001_email", nullable=false, length=120)
private String email;

@Column(name="tb001_senha", nullable=false, length=20)
private String senha;


@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name="tb002_cliente_perfil",
joinColumns = {@JoinColumn(name="tb001_id")},
inverseJoinColumns = {@JoinColumn(name="tb003_id")}
)
private List<PerfilDTO> perfils;

/**
* @return the id
*/
public Long getId() {
return id;
}

/**
* @return the email
*/
public String getEmail() {
return email;
}

/**
* @return the senha
*/
public String getSenha() {
return senha;
}

/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}

/**
* @param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}

/**
* @param senha the senha to set
*/
public void setSenha(String senha) {
this.senha = senha;
}

/**
* @return the perfils
*/
public List<PerfilDTO> getPerfils() {
return perfils;
}

/**
* @param perfils the perfils to set
*/
public void setPerfils(List<PerfilDTO> perfils) {
this.perfils = perfils;
}

}
[/code]

[b]Perfil[/b]
[code]

@Entity
@Table(name="tb003_perfil")
@SequenceGenerator(name="sq003_perfil", sequenceName="sq003_perfil", allocationSize=1)
public class PerfilDTO extends ActionSupport implements java.io.Serializable {
private static final long serialVersionUID = -3213592458450026858L;

@Id
@Column(name="tb003_id")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="sq003_perfil")
private Long id;

@Column(name="tb003_descricao")
private String descricao;

/**
* @return the id
*/
public Long getId() {
return id;
}

/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}

/**
* @return the descricao
*/
public String getDescricao() {
return descricao;
}

/**
* @param descricao the descricao to set
*/
public void setDescricao(String descricao) {
this.descricao = descricao;
}
}
[/code]


Link completo para aplicacao para download com libs e source.
[url]https://rapidshare.com/files/3837313139/app_modelo.war[/url]

Agradeço a ajuda.
[MSN]
 
Índice dos Fóruns » Java Avançado
Ir para:   
Powered by JForum 2.1.8 © JForum Team