1

I am doing a page on Primefaces. It has a datatable with single selection, and when i do clic on a button, it shows a Dialog.

If he dialog only shows labels with ouputtext, it works fine, but if I change the labels for inputtexts, the button doesn't update the dialog.

This is mi xhtml file:

    <p:dataTable id="deportes" var="deporte" value="#{deporteBean.deportesModel}" rowKey="#{deporte.idDeporte}" 
             selection="#{deporteBean.deporteActual}" selectionMode="single">

        <f:facet name="header">
            <h:outputLabel value="#{messages.sports_info_edit}"/>            
        </f:facet>

        <p:column headerText="#{messages.sports_general_name}">
            #{deporte.idDeporte}
        </p:column>

        <p:column headerText="#{messages.sports_general_name}">
            #{deporte.nombre}
        </p:column>

        <p:column headerText="#{messages.sports_general_description}" >
            #{deporte.descripcion}
        </p:column>

        <f:facet name="footer">
                <p:commandButton  action="#{deporteBean.updateInfo}"  actionListener="#{deporteBean.updateInfo}" id="viewButton"  value="#{messages.sports_info_viewDetail}" icon="ui-icon-search"
                    oncomplete="deporteDialog.show()" update=":form:display" />                                         
    </f:facet>
</p:dataTable>

<p:dialog id="dialog" header="Detalle del deporte" widgetVar="deporteDialog" resizable="false" 
          width="400" showEffect="clip" hideEffect="fold" modal="true"> 

    <h:panelGrid id="display" columns="2" cellpadding="4" >

        <f:facet name="header">
            <h:outputText value="#{deporteBean.deporteActual.nombre}" />
        </f:facet>

        <h:outputText value="Id" />
        <h:outputText value="#{deporteBean.deporteActual.idDeporte}"  />

        <h:outputText value="Nombre:" />
        <h:outputText id="txtNombre" value="#{deporteBean.deporteActual.nombre}" />            

        <h:outputText value="Descripcion:" />
        <h:inputText value="#{deporteBean.deporteActual.descripcion}" />
    </h:panelGrid>



    <p:commandButton id="aceptarButton" value ="#{messages.sports_info_save}" icon="ui-icon-disk"
        action="#{deporteBean.save}" immediate="true"
        update=":form:display" oncomplete="deporteDialog.hide()">
    </p:commandButton>
</p:dialog>

And this is my Bean (in faces.config.xml his scope is view):

package com.sportsWorld.web.view;
import java.util.ArrayList;
import java.util.List;
import dtorres.gymAdmin.dto.*;
public class DeporteBean {
private List<Deporte> deportes;
private Deporte deporteActual;
private DeporteDataModel deportesModel;

public DeporteBean (){
    deportes = new ArrayList<Deporte>();
    deportes.add(new Deporte(1,"Tenis de mesa","Velocidad, precisión, concentración y reacción en el deporte más difícil del mundo."));
    deportes.add(new Deporte(2,"Fútbol 5","Lo mejor del deporte rey en un espacio pequeño"));
    deportes.add(new Deporte(3,"Escalada","Fuerza, concentración y equilibrio se ponen a prueba en este magnfífico deporte para quienes no temen a las alturas"));
    deportes.add(new Deporte(4,"Natación","Bla bla bla"));
    deportes.add(new Deporte(5,"Gimnasio","Bla bla bla"));
    deportes.add(new Deporte(6,"Spinning","Bla bla bla"));
    deportes.add(new Deporte(7,"Bolos", "Bla bla bla"));
    deporteActual = null;
    deportesModel = new DeporteDataModel(deportes);
}

public List<Deporte> getDeportes() {
    return deportes;
}



public void setDeportes(List<Deporte> deportes) {
    this.deportes = deportes;
}



public Deporte getDeporteActual() {
    return deporteActual;
}



public void setDeporteActual(Deporte deporteActual) {
    this.deporteActual = deporteActual;
}



public DeporteDataModel getDeportesModel() {
    return deportesModel;
}



public void setDeportesModel(DeporteDataModel deportesModel) {
    this.deportesModel = deportesModel;
}

public void save(){
    System.out.println(deporteActual.getNombre());
}


public void updateInfo(){
    System.out.println("Entra a UpdateInfo");
    System.out.println("UpdateInfo + " + deporteActual.getNombre());
}

}

The updateInfo method is only for debug purposes, the point is that when I change the line in the xhtml for it works fine... Thanks a lot!!

Sorry for my english!

  • add an `h:messages` to see if there are validation errors when you use inputs – Kukeltje May 20 '15 at 19:30
  • Can you show with the inputs instead of the outputs? And please try without the effects. IIRC, an a old version of PF had problems with that in dialogs (what PF version are you using btw? 3.4?) – Kukeltje May 20 '15 at 19:53
  • Yes, i can show the outputs, but not the inputs. If i use inputs the method updateInfo in the action of the view Button, shows that deporteActual is the selected row. But i I use inputs, the value is null. I was using PF 3.5... i'm gonna update and try... – Diego Torres May 21 '15 at 16:29
  • I meant in to put the inputs in the example in your question – Kukeltje May 21 '15 at 16:50
  • Of course, the last field in the panelGrid (description) is an input. . Now, with PF 5.2 I can see the value of 'nombre' and 'id', but not the value of 'descripcion' – Diego Torres May 21 '15 at 18:27

1 Answers1

1

I found the solution. The changes in the xhtml file are:

 <p:dataTable id="deportes" var="deporte" value="#{deporteBean.deportesModel}" rowKey="#{deporte.idDeporte}"  scrollWidth="true" 
             selection="#{deporteBean.deporteActual}" selectionMode="single"
             >
            <p:ajax event="rowSelect" listener="#{deporteBean.updateInfo}"  update=":form:display"/>  
            <f:facet name="header">
                <h:outputLabel value="#{messages.sports_info_edit}"/>            
            </f:facet>

            <p:column headerText="#{messages.sports_general_name}">
                #{deporte.idDeporte}
            </p:column>

            <p:column headerText="#{messages.sports_general_name}">
                #{deporte.nombre}
            </p:column>

            <p:column headerText="#{messages.sports_general_description}" >
                #{deporte.descripcion}
            </p:column>

            <f:facet name="footer">
                    <p:commandButton  actionListener="#{deporteBean.updateInfo}" 
                                      id="viewButton"  
                                      value="#{messages.sports_info_viewDetail}" 
                                      icon="ui-icon-search"
                                      oncomplete="PF('deporteDialog').show()" 
                                      update=":form:display"/>
            </f:facet>
    </p:dataTable>

Note the <p:ajax> tag.. it seems that the blank input field was updating the value in the bean... whith this ajax action, now i update the field with the bean's value.