Primefaces:带有 inputTextarea 的对话框不更新控制器的变量

Primefaces: Dialog with inputTextarea not updating controller's variable

我有这个对话框:

 <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)时,它是一个字符串,不会在控制器中更新。它始终保持其初始值。 知道我做错了什么吗?

我已经尝试过:在 keyup 上打印变量的值,是的,它总是一样的。 使用其他组件进行测试,如 h:inputTextArea 或 p:inputText 并且具有相同的行为,变量不会更新。 是的,我的变量有 getter 和 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

感谢您的帮助!

您在 UICommandComponent 上设置了 immediate=true,因此跳过了 "Update model values" 阶段。删除该属性,它应该可以工作。

BalusC 提供了这个建议,"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."

另见