Help with picklist

Components, Ajax Framework, Utilities and More.
Post Reply
aguiarle
Posts: 7
Joined: 12 Jul 2012, 00:00

12 Jul 2012, 00:15

Good nigth,

I am using Ejb 3 with primefaces 3.2 and Glassfish 3.1.2.


My picklist when execute the commandbutton dosnt retutn any information at Listsorce e ListTarget.

Help me please.

Managed Beans

Code: Select all

package controllers;  
  
import beans.UsuariosFacade;  
import criptografia.EncryptorException;  
import entidades.Filiais;  
import entidades.Menus;  
import entidades.Usuarios;  
import java.util.ArrayList;  
import java.util.Iterator;  
import java.util.List;  
import java.util.Map;  
import java.util.logging.Level;  
import java.util.logging.Logger;  
import javax.ejb.EJB;  
import javax.ejb.TransactionAttribute;  
import javax.ejb.TransactionAttributeType;  
import javax.faces.bean.ManagedBean;  
import javax.faces.bean.SessionScoped;  
import javax.faces.component.UIComponent;  
import javax.faces.context.FacesContext;  
import javax.faces.convert.Converter;  
import javax.faces.convert.FacesConverter;  
import mensagens.Bundles;  
import mensagens.Mensagens;  
import org.primefaces.model.DualListModel;  
import sessoes.Sessoes;  
  
    
  
@ManagedBean(name = "usuariosController")  
@SessionScoped  
public class UsuariosController extends AbstractController<Usuarios>  {  
  
.....  
  
private DualListModel<Filiais> dualListModelFiliais;  
      
    @Override  
    public String prepareEdit() {  
        super.prepareEdit();  
          
        List<Filiais> filiaisTarget = (List<Filiais>) current.getFiliaisCollection();  
        List<Filiais> filiaisSource = ejbFiliais.findAll();  
        for (Iterator<Filiais> it = filiaisTarget.iterator(); it.hasNext();) {  
            Filiais filiais = it.next();  
            filiaisSource.remove(filiais);  
              
        }  
        dualListModelFiliais =  
          new DualListModel<Filiais>(filiaisSource, filiaisTarget);  
          
        return editaRegistro();  
    }  
      
      
      
    public DualListModel<Filiais> getFiliaisPickList() {    
        return dualListModelFiliais;    
    }    
    public void setFiliaisPickList(DualListModel<Filiais> dualListModelFiliais) {    
        this.dualListModelFiliais = dualListModelFiliais;  
    }  
      
    public void salvarFiliais(){  
        //sempre vem vazio aki  
        List<Filiais> listaFiliaisTarget = dualListModelFiliais.getTarget();  
          
        java.util.Collection<Filiais> filiais = (java.util.Collection<Filiais>)  listaFiliaisTarget;  
        current.setFiliaisCollection(filiais);  
        salvaRegistro();  
    }  
  
}  
      


View

Code: Select all

........  
  
  <p:dialog appendToBody="true" closable="true" header="#{bundle.EditUsuariosFiliaisTitle}"   
              resizable="false" widgetVar="dlgAlterarFiliais"    
              showEffect="clip" hideEffect="clip" modal="true">    
  
        <p align="center">  
  
            <p:pickList id="pickListFiliais" value="#{usuariosController.filiaisPickList}" widgetVar="picklistVar"    
                        var="filial" converter="filiaisControllerConverter"   
                        converterMessage="Falha no converter"  
                        itemValue="#{filial}" >  
  
                <f:facet name="sourceCaption">#{bundle.EditUsuariosFiliaisDisponiveis}</f:facet>    
                <f:facet name="targetCaption">#{bundle.EditUsuariosFiliaisPermitidas}</f:facet>    
                <p:column>  
                    #{filial.razao}  
  
                </p:column>  
                  
  
  
            </p:pickList>  
            <p align="center">  
                    <p:commandButton id="filiaisSubmit" value="#{bundle.BotaoSalvar}"   
                                     action="#{usuariosController.salvarFiliais}"   
                                     oncomplete="dlgAlterarFiliais.hide()"  
                                     update="panelDados"  
                                     immediate="false"  
                                       
                                     />  
                    <p:commandButton id="filiaisCancelar" value="#{bundle.BotaoCancelar}"   
                                     oncomplete="dlgAlterarFiliais.hide()"/>  
                </p>  
              
        </p>  
  
    </p:dialog>  

Convert

Code: Select all


@FacesConverter(forClass = Filiais.class, value="filiaisControllerConverter")  
public static class FiliaisControllerConverter implements Converter {  
  
    public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {  
        if (value == null || value.length() == 0) {  
            return null;  
        }  
        FiliaisController controller = (FiliaisController) facesContext.getApplication().getELResolver().  
                getValue(facesContext.getELContext(), null, "filiaisController");  
        return controller.ejbFacade.find(getKey(value));  
    }  
  
    java.lang.Long getKey(String value) {  
        java.lang.Long key;  
        key = Long.valueOf(value);  
        return key;  
    }  
  
    String getStringKey(java.lang.Long value) {  
        StringBuffer sb = new StringBuffer();  
        sb.append(value);  
        return sb.toString();  
    }  
  
    public String getAsString(FacesContext facesContext, UIComponent component, Object object) {  
        if (object == null) {  
            return null;  
        }  
        if (object instanceof Filiais) {  
            Filiais o = (Filiais) object;  
            return getStringKey(o.getId());  
        } else {  
            throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + FiliaisController.class.getName());  
        }  
    }  
}  


Post Reply
  • Information
  • Who is online

    Users browsing this forum: Baidu [Spider] and 10 guests