提交ajax后的primefaces不会更新

时间:2012-12-03 13:01:16

标签: java ajax jsf-2 primefaces

使用PF 3.2 我遇到了这个问题 如果我提交表格并且他们是必填字段,则会出现验证和所需的消息。问题是在那之后,如果我更改了组合值-by ajax-更改输入文本,值dosn不会改变,但是监听器调用了! 的 XHTML

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:p="http://primefaces.org/ui"
  xmlns:f="http://java.sun.com/jsf/core">
<h:head>
    <title>Prime Test</title>
</h:head>


<h:body style="background: #F6F6F6;">
    <h:form id="idAjaxFormTest">
        <f:view>
           <h1> <h:outputText value="after submit ajax problem" /></h1>
            <p:messages showSummary="true" autoUpdate="true" />
            <p:panelGrid columns="2">
                <h:outputText value="Names" />
                <p:selectOneMenu value="#{ajaxTest.name}">
                    <f:selectItems value="#{ajaxTest.names}" var="varName"
                                   itemLabel="#{varName}" itemValue="#{varName}">
                    </f:selectItems>
                    <p:ajax listener="#{ajaxTest.listen}" update="idXname" />
                </p:selectOneMenu>

                <h:outputText value="Xname" />
                <p:inputText value="#{ajaxTest.xname}" id="idXname"/>

                <h:outputText value="Xuser" />
                <p:inputText required="true" transient="true" value="#{ajaxTest.xuser}" label="xUser" />
            </p:panelGrid>
            <p:commandButton value="Submit" action="#{ajaxTest.doAction}" />
        </f:view>
    </h:form>
</h:body>

package com.actions;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;


@ManagedBean(name = "ajaxTest")
@ViewScoped

public class AjaxTestBean implements Serializable{
    private List<String> names;
    private String name;
    private String xname;
    private String xuser;

public AjaxTestBean() {
    names = new ArrayList<String>();
    names.add("ahmed");
    names.add("mohamed");
    names.add("mahmoud");
    names.add("ayman");
    names.add("walid");
    names.add("khalid");
}

public void listen(){
    xname = "QQ "+ name;
    System.out.println("Listener "+ xname);
}
public void doAction(){
    System.out.println("Action Done: "+ name);
}

public List<String> getNames() {
    return names;
}

public void setNames(List<String> names) {
    this.names = names;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getXname() {
    return xname;
}

public void setXname(String xname) {
    this.xname = xname;
}

public String getXuser() {
    return xuser;
}

public void setXuser(String xuser) {
    this.xuser = xuser;
}


}

action01

action02

1 个答案:

答案 0 :(得分:3)

看起来你遇到了这个问题:

How can I populate a text field using PrimeFaces AJAX after validation errors occur?

将faces-config.xml与OmniFaces库一起添加到您的select-one-menu正确更新inputField

<lifecycle>
    <phase-listener>org.omnifaces.eventlistener.ResetInputAjaxActionListener</phase-listener>
</lifecycle>

如果您不想为所有组件执行此操作,OmniFaces会展示如何为每个组件执行此操作:http://showcase.omnifaces.org/eventlisteners/ResetInputAjaxActionListener