Primefaces:带有inputTextarea的对话框不更新控制器的变量 [英] Primefaces: Dialog with inputTextarea not updating controller's variable

查看:126
本文介绍了Primefaces:带有inputTextarea的对话框不更新控制器的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个对话框:

 <p:dialog header="Ingrese Comentario" 
              widgetVar="dlg1" appendTo="@(body)" 
              modal="true" position="top"
              hideEffect="fold" showEffect="fold"
              closable="true" draggable="true"
              >
        <h:form id="d_ingresarComentario">
        <h:panelGrid columns="2">           
            <p:inputTextarea   value="#{tareaController.comentarioNuevo.comentario}"
                               rows="7" cols="60"  
                               placeholder="Ingrese su comentario aquí" 
                               counter="display1" maxlength="200" 
                               counterTemplate="{0} Caracteres faltantes." 
                               >   
            </p:inputTextarea>  
            <br/>
            <h:outputText id="display1"/>
            <f:facet name="footer">
                <p:commandButton id ="c_enviar" 
                                 immediate="true"
                                 actionListener="#{tareaController.crearComentario()}"
                                 value="Enviar" 
                                 oncomplete="dlg1.hide()" global="false">                         
                </p:commandButton>    
            </f:facet>
        </h:panelGrid>   
        </h:form>
    </p:dialog>  

按钮的侦听器工作正常,调用对话框时,文本区域将显示带有值的变量. 但是,每当我在文本区域中写入变量(comentarioNuevo.comentario)时,该变量(即字符串)都不会在控制器中更新.它始终保持其初始值. 对我在做什么错有任何想法吗?

The button's listener works fine, the text area is showed with the value's variable when the dialog is called. But whenever I write in the text area the variable (comentarioNuevo.comentario), which is a string, is not updated in the controller. It always keep its initial value. Any idea about what I am doing wrong?

我已经尝试过:在keyup上打印变量的值,是的,它总是相同的. 使用其他组件(例如h:inputTextArea或p:inputText)进行测试,并且具有相同的行为,该变量将不会更新. 是的,我的变量同时具有getter和setter.

I already tried: printing the variable's value on keyup, and yes it's always the same. Testing with other components, like h:inputTextArea or p:inputText and it have the same behavior, the variable wont get updated. Yes, my variable have both getter and setter.

我的控制器代码如下:

@ManagedBean
@ViewScoped
public class TareaController implements Serializable {
private Comentario comentario = new Comentario();

    public void crearComentario() {
        comentarioDAO.crearComentario(login.getUsuario(), expediente, comentarioNuevo);
        nuevoComentario();
    }

    public Comentario getComentarioNuevo() {
        return comentarioNuevo;
    }

    public void setComentarioNuevo(Comentario comentarioNuevo) {
        this.comentarioNuevo = comentarioNuevo;
    }
}

该Comentario是一个JPA实体,可以在 附加信息:PrimeFaces版本4.0,Mojarra 2.7,JSF 2.2

That Comentario is a JPA Entity, which works fine in other sides of the Aditional Information: PrimeFaces version 4.0, Mojarra 2.7, JSF 2.2

感谢您的帮助!

推荐答案

您已经在UICommandComponent上设置了immediate=true,因此跳过了更新模型值"阶段.删除该属性,它应该可以工作.

You've set immediate=true on a UICommandComponent, so the "Update model values" phase is skipped. Remove the attribute and it should work.

BalusC提供了以下建议:如果仅在UICommand中进行设置,则将跳过任何UIInput组件的应用请求值阶段,直到具有更新模型值阶段为止.使用它可以跳过表单的整个处理过程.例如取消"或返回"按钮."

BalusC offers this advice, "If set in UICommand only, the apply request values phase until with update model values phases will be skipped for any of the UIInput component(s). Use this to skip the entire processing of the form. E.g. 'Cancel' or 'Back' button."

  • Add immediate="true" to UICommand only
  • Okay, when should I use the immediate attribute? (same article)

这篇关于Primefaces:带有inputTextarea的对话框不更新控制器的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆