0

使用 PF 3.2,如果我提交表单并且它们是必填字段,验证完成并出现必填消息,我会遇到这个问题。之后的问题是,如果我更改了通过 ajax 更改 inputtext 的组合值,则该值不会更改,但是侦听器调用了! 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;
}


}

行动01

行动02

4

1 回答 1

3

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

发生验证错误后,如何使用 PrimeFaces AJAX 填充文本字段?

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

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

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

于 2012-12-04T09:38:49.697 回答