RichFaces + modalpanel

0 respostas
G

Tenho um datatable, que recebe um list (por enquanto estatico, dps vai ser d um banco de dados), e usando o ajaxkeys eu edito apenas uma linha, ao invez de carregar toda a tabela, ou seja so da update na linha q eu clicar..

me basiei em um exemplo aki

meu mb

package example.beans;

import example.dao.UserDAO;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import example.model.User;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.faces.event.ActionEvent;

public class UserBean implements Serializable {

    private List<User> users;
    private User selectedUser;
    private Set<Integer> rowsToUpdate;
    private UserDAO udao = new UserDAO();

    public List<User> getUsers() {
        setUsers(new ArrayList<User>());
        users.add(new User("Joe", "[email removido]"));
        users.add(new User("Charley", "[email removido]"));
        users.add(new User("John", "[email removido]"));
        users.add(new User("Greg", "[email removido]"));
        users.add(new User("Prescila", "[email removido]"));
        rowsToUpdate = new HashSet<Integer>();
        return users;
    }

     public void save(ActionEvent event) {
        rowsToUpdate.clear();
        System.out.println(users.indexOf(selectedUser));
        rowsToUpdate.add(users.indexOf(selectedUser));
    }

    public User getSelectedUser() {
        return selectedUser;
    }

    public void setSelectedUser(User selectedUser) {
        this.selectedUser = selectedUser;
    }

    public Set<Integer> getRowsToUpdate() {
        return rowsToUpdate;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }
   
}

meu bean

package example.model;

import java.io.Serializable;

public class User implements Serializable{

    public User() {
        
    }

 @Override
 public String toString() {
  return name + " " + email;
 }
 private String name;
 private String email;
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getEmail() {
  return email;
 }
 public void setEmail(String email) {
  this.email = email;
 }
 public User(String name, String email) {
  super();
  this.name = name;
  this.email = email;
 }
}
meu jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>

<html>
    <f:view>
        <head>
            <title>RichFaces</title>
        </head>
        <body>
            <h:form>
                <rich:panel header="Usuarios">
                    <rich:dataTable value="#{userBean.users}" var="user"
                                    ajaxKeys="#{userBean.rowsToUpdate}">
                        <h:column>
                            <a4j:commandButton value="Edit"
                                               oncomplete="#{rich:component('useredit')}.show()"
                                               reRender="userinfo">
                                <f:setPropertyActionListener value="#{user}"
                                                             target="#{userBean.selectedUser}" />
                            </a4j:commandButton>
                        </h:column>

                        <h:column>
                            <h:outputText id="name" value="#{user.name}"/>
                        </h:column>
                        <h:column>
                            <h:outputText id="email" value="#{user.email}"/>
                        </h:column>
                    </rich:dataTable>
                </rich:panel>
            </h:form>
            <a4j:keepAlive beanName="userBean"/>
            <rich:modalPanel id="useredit" label="Usuario">
                <h:form>
                    <h:panelGrid id="userinfo">
                        <h:outputLabel for="nameInput" value="Name:"/>
                        <h:inputText id="nameInput" value="#{userBean.selectedUser.name}"/>
                        <h:outputLabel for="emailInput" value="Email:"/>
                        <h:inputText id="emailInput" value="#{userBean.selectedUser.email}"/>
                        <h:panelGrid columns="2">
                            <a4j:commandLink onclick="#{rich:component('useredit')}.hide();return false">
                                Close
                            </a4j:commandLink>
                            <a4j:commandLink actionListener="#{userBean.save}"
                                             oncomplete="#{rich:component('useredit')}.hide()"
                                             reRender="name, email">
                                Save
                            </a4j:commandLink>
                        </h:panelGrid>
                    </h:panelGrid>
                </h:form>
            </rich:modalPanel>
        </body>
    </f:view>
</html>

qnd tento salvar oq mudo no modal, ele retorna -1 do indexof, ou seja n axa o objeto na lista. Resumindo, não consigo salvar/modificar as alteraçoes na lista.

Criado 27 de fevereiro de 2009
Respostas 0
Participantes 1