Results 1 to 1 of 1

Thread: Error with Spring and PrimeFaces

  1. #1
    Join Date
    Jul 2011
    Posts
    1

    Unhappy Error with Spring and PrimeFaces

    I have a project with Spring 3.0, Spring Security, PrimeFaces 2.2.1 and JSF 2.0.

    When I do a page with a datatable and try to use in cell edit, it always send old data to controller, no send new changes to controller. I see that when I do click on button for save changes, it call to get list of data 19 times before to call to save method (I think that it rewrite the new data because there is a problem between Spring and primefaces).

    page.xhtml
    PHP Code:
    <ui:composition xmlns="http://www.w3.org/1999/xhtml"         
                    
    xmlns:h="http://java.sun.com/jsf/html"         
                    
    xmlns:f="http://java.sun.com/jsf/core"         
                    
    xmlns:ui="http://java.sun.com/jsf/facelets"
                    
    xmlns:p="http://primefaces.prime.com.tr/ui"
                    
    template="/plantilla.xhtml">    
        <
    ui:define name="head_title">Liberaciones Modelos y precios</ui:define>  

        <
    ui:define name="body_general">
            <
    h:form>
                <
    p:growl id="growl"/>
                <
    p:dataTable dynamic="true" var="catalogo"
                             
    lazy="false" paginatorPosition="bottom" 
                             
    paginator="false" value="#{modeloyprecioBean.modeloyPrecio}" 
                             
    selection="#{modeloyprecioBean.seleccionado}"
                             
    rowEditListener="#{modeloyprecioBean.rowEditListener}"                 
                             
    onRowEditUpdate="growl">
                    <
    f:facet name="header">  
                         
    lista de precios
                    </
    f:facet>

                    <
    p:column headerText="Operador">  
                       <
    p:cellEditor>  
                           <
    f:facet name="output">  
                               <
    h:outputText value="#{catalogo.operador}" />  
                           </
    f:facet>  
                           <
    f:facet name="input">  
                               <
    p:inputText value="#{catalogo.operador}" />  
                           </
    f:facet>  
                       </
    p:cellEditor>  
                   </
    p:column
            
            <
    p:column headerText="Marca">  
                       <
    p:cellEditor>  
                           <
    f:facet name="output">  
                               <
    h:outputText value="#{catalogo.marca}" />  
                           </
    f:facet>  
                           <
    f:facet name="input">  
                               <
    p:inputText value="#{catalogo.marca}" />  
                           </
    f:facet>  
                       </
    p:cellEditor>  
                   </
    p:column>
            
                    <
    p:column headerText="Precio">  
                       <
    p:cellEditor>  
                           <
    f:facet name="output">  
                               <
    h:outputText value="#{catalogo.precio}" />  
                           </
    f:facet>  
                           <
    f:facet name="input">  
                               <
    p:inputText required="true" value="#{catalogo.precio}"
                                            
    requiredMessage="Aviso: el precio es obligatorio."/> 
                               
                           </
    f:facet>  
                       </
    p:cellEditor>  
                   </
    p:column
                    
                    <
    p:column headerText="">  
                        <
    p:rowEditor />  
                    </
    p:column>
        </
    p:dataTable>
        </
    h:form>

        </
    ui:define>
    </
    ui:composition
    Controller:
    Code:
    @Component("modeloyprecioBean")
    @Scope("request")
    //@Service("modeloyprecioBean"), this can replace @Component with same error
    public class ModelosyPrecios implements Serializable {
        //@Resource 
        @Autowired
        private ModeloyPrecioDao dao;
        private List<ImeiModeloyPrecio> modeloyPrecio;
        private ImeiModeloyPrecio[] seleccionado;
    
        public ModelosyPrecios() {
    
        }
    
        public ImeiModeloyPrecio[] getSeleccionado() {
            return seleccionado;
        }
    
        public void setSeleccionado(ImeiModeloyPrecio[] seleccionado) {
            this.seleccionado = seleccionado;
        }
        
        
    
        public List<ImeiModeloyPrecio> getModeloyPrecio() {
            this.modeloyPrecio = dao.loadAll();
            System.out.println("---------> CARGA DATOS ");
            return modeloyPrecio;
        }
    
        public void setModeloyPrecio(List<ImeiModeloyPrecio> modeloyPrecio) {
            this.modeloyPrecio = modeloyPrecio;
        }
    
        public void setDao(ModeloyPrecioDao dao) {
            this.dao = dao;
        }
    
        public void rowEditListener(org.primefaces.event.RowEditEvent ev){
    
            try {
                ImeiModeloyPrecio fila = (ImeiModeloyPrecio)ev.getObject();
               
                if(fila.getMarca().isEmpty())
                    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Tiene que indicar una marca.", null));
                else if(fila.getOperador().isEmpty())
                    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Tiene que indicar el operador.", null));
                else {
                    System.out.println("---------> ID: "+fila.getId()+fila.getMarca()+fila.getOperador()+fila.getPrecio());
                    dao.update(fila);   
                    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Registro modificado correctamente.", null));
                }
               
            } catch (Exception e) {
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR", e.toString()));
            }       
        }
    
        
        
    }
    faces-config
    Code:
    <?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE faces-config PUBLIC
      "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
      "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
    
    <!-- =========== FULL CONFIGURATION FILE ================================== -->
    
    <faces-config xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
        version="2.0" >
    
            <!-- Allows you to inject Spring beans into JSF managed beans... -->
        <managed-bean>
            <managed-bean-name>modeloyprecioBean</managed-bean-name>
            <managed-bean-class>controlador.imei.ModelosyPrecios</managed-bean-class> 
            <managed-bean-scope>request</managed-bean-scope>
            <managed-property>
                <property-name>dao</property-name>
                <property-class>modelo.dao.ModeloyPrecioDao</property-class>
                <value>#{modeloyprecioDAO}</value>
            </managed-property>
        </managed-bean>
      
        <application>
            <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
            <resource-handler>org.primefaces.application.PrimeResourceHandler</resource-handler>
            <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
        </application>
    
    </faces-config>
    Last edited by jotremar; Jul 27th, 2011 at 07:48 AM. Reason: add faces-config

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •