0

Using PF 3.2 I faced this problem if I submit a form and their is a required field, validation done and required messages appeared. the problem is after that if I changed the combo value that -by ajax- changes the inputtext the value doesn't change, however the listener called! 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>

Bean

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

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
ehab refaat
  • 854
  • 2
  • 12
  • 23

1 Answers1

3

Looks like you have run into this problem:

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

Adding the following to faces-config.xml together with OmniFaces library made your select-one-menu update the inputField correctly

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

If you dont want to do it for all your components, OmniFaces has a showcase how to do it per component: http://showcase.omnifaces.org/eventlisteners/ResetInputAjaxActionListener

Community
  • 1
  • 1
Aksel Willgert
  • 11,367
  • 5
  • 53
  • 74