Problem retrieving values from a row on datatable to modal
patrickcr Feb 24, 2010 6:09 PMHi guys i am a new user from seam framework and i want to now how to retrieve data to a modal panel from the datable. I now there is some information over the web about is, buit i have try 100 thins i dosent work. so there is my bean;
@Name("usersList")
public class UsersList implements Serializable{
/**
*
*/
private static final long serialVersionUID = -8191663213732129820L;
@Logger private Log log;
public Users userSelected= new Users();
private Collection<Users> usersList = new ArrayList<Users>(0);
@In StatusMessages statusMessages;
private Set <Integer>keys;
public void usersList()
{
try {
EntityManagerFactory emf =Persistence.createEntityManagerFactory("projectseam2");
EntityManager em = emf.createEntityManager();
String query = "select x from Users x where x.name like '%" + value +"%'";
usersList = em.createQuery(query).getResultList();
em.close();
} catch (Exception e) {
// TODO Auto-generated catch block
statusMessages.add(getFullExceptionMessage(e));
}
}
public Collection<Users> getUserlist()
{
return usersList;
}
public void getCurrentRow(Users user) {
}
public Set<Integer> getKeys() {
return keys;
}
public void setKeys(Set<Integer> keys) {
this.keys = keys;
}
public static String getFullExceptionMessage(Exception e)
{
String message = e.getLocalizedMessage();
Throwable t = e.getCause();
while(t != null)
{
message += "\n" + t.getMessage();
t = t.getCause();
}
return message;
}
}
and my usersList.xmhtml
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:a="http://richfaces.org/a4j" template="layout/template.xhtml">
<ui:define name="body">
<h:form id="usersListForm">
<rich:panel>
<f:facet name="header">usersList</f:facet>
<ui:define name="label">Search:</ui:define>
<h:inputText id="value" value="#{usersList.value}" />
<h:commandButton id="usersList" value="Search"
action="#{usersList.usersList}" for="table" />
<h:outputText value="#{usersList.value}" />
<div style="clear: both" />
</rich:panel>
<div class="actionButtons">
<rich:dataTable
value="#{usersList.userlist}" var="user" rows="5" rowKeyVar="row"
id="table" ajaxKeys="#{usersList.keys}"
>
<f:facet name="header">
<h:outputText value="Utilizadores" />
</f:facet>
<rich:column>
<f:facet name="header">
<h:outputText value="Nome" />
</f:facet>
<h:outputText value="#{user.name}" id="name" />
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="Username" />
</f:facet>
<h:outputText value="#{user.username}" id="username" />
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="Password" />
</f:facet>
<h:outputText value="#{user.password}" id="password" />
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="actions" />
</f:facet>
<a:commandLink value="editar"
onclick="#{rich:component('modal')}.show()">
<f:setPropertyActionListener value="#{user}"
target="#{usersList.currentRow(user)}" />
</a:commandLink>
</rich:column>
<f:facet name="footer">
<rich:datascroller id="ds1" page="1" rerender="table" />
</f:facet>
</rich:dataTable></div>
</h:form>
<rich:modalPanel id="modal" minHeight="200" minWidth="450"
autosized="false" moveable="false">
<f:facet name="header">
<h:outputText value="Realmente Deseja Excluir?" />
</f:facet>
<h:panelGrid columns="2">
<h:outputText value="#{users.name}" />
<a:commandButton value="Sim"
actionListener="#{usersList.excluir}"
reRender="table"
oncomplete="#{rich:component('modal')}.hide();" />
<a:commandButton value="Nao" onclick="#{rich:component('modal')}.hide(); return false" />
</h:panelGrid>
</rich:modalPanel>
</ui:define>
</ui:composition>
and my class:
package org.domain.projectseam2.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
import org.jboss.seam.annotations.Name;
/**
* Users generated by hbm2java
*/
@Name("users")
@Entity
@Table(name = "users", catalog = "jbossformacao")
public class Users implements java.io.Serializable {
private int idutilzadores;
private String username;
private String password;
private String name;
public Users() {
}
public Users(int idutilzadores, String username, String password,
String name) {
this.idutilzadores = idutilzadores;
this.username = username;
this.password = password;
this.name = name;
}
@Id
@Column(name = "idutilzadores", unique = true, nullable = false)
public int getIdutilzadores() {
return this.idutilzadores;
}
public void setIdutilzadores(int idutilzadores) {
this.idutilzadores = idutilzadores;
}
@Column(name = "username", nullable = false, length = 45)
@NotNull
@Length(max = 45)
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
@Column(name = "password", nullable = false, length = 45)
@NotNull
@Length(max = 45)
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
@Column(name = "name", nullable = false, length = 45)
@NotNull
@Length(max = 45)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
.. i dont now what is the problem because i get the data wheni call the method userlist in userlist.java and then i can execute any actions with the link on the datable. It dosent call the usersList.currentRow on
<f:setPropertyActionListener value="#{user}"
target="#{usersList.currentRow(user)}" /> .
i try a system.out.print in this method but it never works.
please if you have any ideia, please tell-me
.
Best regards
Patrick reis
@Name("usersList")
public class UsersList implements Serializable{
/**
*
*/
private static final long serialVersionUID = -8191663213732129820L;
@Logger private Log log;
public Users userSelected= new Users();
private Collection<Users> usersList = new ArrayList<Users>(0);
@In StatusMessages statusMessages;
private Set <Integer>keys;
public void usersList()
{
try {
EntityManagerFactory emf =Persistence.createEntityManagerFactory("projectseam2");
EntityManager em = emf.createEntityManager();
String query = "select x from Users x where x.name like '%" + value +"%'";
usersList = em.createQuery(query).getResultList();
em.close();
} catch (Exception e) {
// TODO Auto-generated catch block
statusMessages.add(getFullExceptionMessage(e));
}
}
public Collection<Users> getUserlist()
{
return usersList;
}
public void getCurrentRow(Users user) {
}
public Set<Integer> getKeys() {
return keys;
}
public void setKeys(Set<Integer> keys) {
this.keys = keys;
}
public static String getFullExceptionMessage(Exception e)
{
String message = e.getLocalizedMessage();
Throwable t = e.getCause();
while(t != null)
{
message += "\n" + t.getMessage();
t = t.getCause();
}
return message;
}
}
and my usersList.xmhtml
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:rich="http://richfaces.org/rich"
xmlns:a="http://richfaces.org/a4j" template="layout/template.xhtml">
<ui:define name="body">
<h:form id="usersListForm">
<rich:panel>
<f:facet name="header">usersList</f:facet>
<ui:define name="label">Search:</ui:define>
<h:inputText id="value" value="#{usersList.value}" />
<h:commandButton id="usersList" value="Search"
action="#{usersList.usersList}" for="table" />
<h:outputText value="#{usersList.value}" />
<div style="clear: both" />
</rich:panel>
<div class="actionButtons">
<rich:dataTable
value="#{usersList.userlist}" var="user" rows="5" rowKeyVar="row"
id="table" ajaxKeys="#{usersList.keys}"
>
<f:facet name="header">
<h:outputText value="Utilizadores" />
</f:facet>
<rich:column>
<f:facet name="header">
<h:outputText value="Nome" />
</f:facet>
<h:outputText value="#{user.name}" id="name" />
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="Username" />
</f:facet>
<h:outputText value="#{user.username}" id="username" />
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="Password" />
</f:facet>
<h:outputText value="#{user.password}" id="password" />
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="actions" />
</f:facet>
<a:commandLink value="editar"
onclick="#{rich:component('modal')}.show()">
<f:setPropertyActionListener value="#{user}"
target="#{usersList.currentRow(user)}" />
</a:commandLink>
</rich:column>
<f:facet name="footer">
<rich:datascroller id="ds1" page="1" rerender="table" />
</f:facet>
</rich:dataTable></div>
</h:form>
<rich:modalPanel id="modal" minHeight="200" minWidth="450"
autosized="false" moveable="false">
<f:facet name="header">
<h:outputText value="Realmente Deseja Excluir?" />
</f:facet>
<h:panelGrid columns="2">
<h:outputText value="#{users.name}" />
<a:commandButton value="Sim"
actionListener="#{usersList.excluir}"
reRender="table"
oncomplete="#{rich:component('modal')}.hide();" />
<a:commandButton value="Nao" onclick="#{rich:component('modal')}.hide(); return false" />
</h:panelGrid>
</rich:modalPanel>
</ui:define>
</ui:composition>
and my class:
package org.domain.projectseam2.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.validator.Length;
import org.hibernate.validator.NotNull;
import org.jboss.seam.annotations.Name;
/**
* Users generated by hbm2java
*/
@Name("users")
@Entity
@Table(name = "users", catalog = "jbossformacao")
public class Users implements java.io.Serializable {
private int idutilzadores;
private String username;
private String password;
private String name;
public Users() {
}
public Users(int idutilzadores, String username, String password,
String name) {
this.idutilzadores = idutilzadores;
this.username = username;
this.password = password;
this.name = name;
}
@Id
@Column(name = "idutilzadores", unique = true, nullable = false)
public int getIdutilzadores() {
return this.idutilzadores;
}
public void setIdutilzadores(int idutilzadores) {
this.idutilzadores = idutilzadores;
}
@Column(name = "username", nullable = false, length = 45)
@NotNull
@Length(max = 45)
public String getUsername() {
return this.username;
}
public void setUsername(String username) {
this.username = username;
}
@Column(name = "password", nullable = false, length = 45)
@NotNull
@Length(max = 45)
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
@Column(name = "name", nullable = false, length = 45)
@NotNull
@Length(max = 45)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
.. i dont now what is the problem because i get the data wheni call the method userlist in userlist.java and then i can execute any actions with the link on the datable. It dosent call the usersList.currentRow on
<f:setPropertyActionListener value="#{user}"
target="#{usersList.currentRow(user)}" /> .
i try a system.out.print in this method but it never works.
please if you have any ideia, please tell-me
.
Best regards
Patrick reis