【问题标题】:Primefaces Dialog doesn't update edit fieldsPrimefaces 对话框不更新编辑字段
【发布时间】:2015-08-02 05:09:36
【问题描述】:

我正在 Primefaces 上做一个页面。它有一个单选数据表,当我点击一个按钮时,它会显示一个对话框。

如果他的对话框只显示带有输出文本的标签,它可以正常工作,但如果我更改输入文本的标签,按钮不会更新对话框。

这是 mi xhtml 文件:

    <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>

这是我的 Bean(在 faces.config.xml 中他的范围是视图):

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());
}

}

updateInfo 方法仅用于调试目的,重点是当我换行时 在 xhtml 中,因为它工作正常......非常感谢!

对不起我的英语!

【问题讨论】:

  • 添加h:messages,看看你使用inputs时是否有验证错误
  • 你能用输入代替输出吗?请尝试没有效果。 IIRC,旧版本的 PF 在对话框中有问题(顺便说一句,您使用的是什么 PF 版本?3.4?)
  • 是的,我可以显示输出,但不能显示输入。如果我在视图按钮的操作中使用方法 updateInfo 输入,则表明 deporteActual 是选定的行。但我使用输入,值为空。我使用的是 PF 3.5...我要更新并尝试...
  • 我的意思是把输入放在你问题的例子中
  • 当然,panelGrid(描述)中的最后一个字段是输入。 。现在,在 PF 5.2 中,我可以看到 'nombre' 和 'id' 的值,但看不到 'descripcion' 的值

标签: primefaces dialog jsf-1.2


【解决方案1】:

我找到了解决方案。 xhtml文件的变化是:

 <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>

注意&lt;p:ajax&gt; 标记。似乎空白输入字段正在更新 bean 中的值...通过这个 ajax 操作,现在我用 bean 的值更新字段。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    • 2012-02-21
    • 1970-01-01
    • 2018-03-04
    相关资源
    最近更新 更多