Autocomplete partialSubmit false Problem

UI Components for JSF
chrisu86
Posts: 17
Joined: 24 Jul 2014, 10:14

24 Jul 2014, 11:48

I have a simple form with two input fields. The first one is a <p:inputText/> and the second one is a <p:autoComplete/>.
What i want to achieve now is that the value of the <p:inputText/> is available in my autocomplete Method. Is there a way to get this working?

Here is my test page:

Code: Select all

<?xml version='1.0' encoding='ISO-8859-1' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
    </h:head>
    <h:body>
    	<p:log id="log" />
		<h:form id="test_form">
			<p:outputLabel for="fieldOne" value="fieldOne " />
			<p:inputText id="fieldOne" value="#{testBean.fieldOne}"/>
			<p:outputLabel for="fieldTwo" value="fieldTwo " />
			<p:autoComplete id="fieldTwo" value="#{testBean.fieldTwo}"  completeMethod="#{testBean.autocomplete}" >
				<p:ajax event="query" partialSubmit="false"></p:ajax>
			</p:autoComplete>
		</h:form>
    </h:body>
</html>
And this is my simple TestBean:

Code: Select all

@ManagedBean(name="testBean")
@ViewScoped
public class TestBean {
	
	private String fieldOne;
	
	private String fieldTwo;
	
	
	public String getFieldOne() {
		return fieldOne;
	}

	public void setFieldOne(String fieldOne) {
		this.fieldOne = fieldOne;
	}

	public String getFieldTwo() {
		return fieldTwo;
	}

	public void setFieldTwo(String fieldTwo) {
		this.fieldTwo = fieldTwo;
	}

	public List<String> autocomplete(String query){
		return new ArrayList<String>();
	}
}

When i type something in my autocomplete field the autocomplete method gets successfully called.
But the value of fieldOne is not available. Because of the
<p:ajax event="query" partialSubmit="false"></p:ajax>
the request Parameter contains the value of fieldOne but the Setter is never being called.

This are the POST DATA:
test_form:fieldTwo_input=a,
test_form:fieldOne=test,
javax.faces.partial.render=test_form:fieldTwo,
javax.faces.partial.execute=test_form:fieldTwo,
test_form=test_form, javax.faces.source=test_form:fieldTwo,
test_form:fieldTwo_query=a,
javax.faces.behavior.event=query,
javax.faces.partial.event=query,
javax.faces.partial.ajax=true,
javax.faces.ViewState=-5194014525765824611:-2692512311297763706
Tested on Primefaces 5.0 and Mojarra 2.1.7
Thank you in advance for your help!

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

28 Jul 2014, 09:22

First of all, your problem is not common, since you are the first (afaicr) one to ask this. The usecase might be common, but you can easily submit the other field with ajax to. So it is available serverside when you do an autocomplete.

chrisu86
Posts: 17
Joined: 24 Jul 2014, 10:14

28 Jul 2014, 09:45

First of all, thank you for your reply :)
So you mean i should put an ajax event to my non-autocomplete inputfield?

I tried it like this:

Code: Select all

<?xml version='1.0' encoding='ISO-8859-1' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
    </h:head>
    <h:body>
    	<p:log id="log" />
		<h:form id="test_form">
			<p:outputLabel for="fieldOne" value="fieldOne " />
			<p:inputText id="fieldOne" value="#{testBean.fieldOne}">
				<p:ajax partialSubmit="true"></p:ajax>
			</p:inputText>
			<p:outputLabel for="fieldTwo" value="fieldTwo " />
			<p:autoComplete id="fieldTwo" value="#{testBean.fieldTwo}" completeMethod="#{testBean.autocomplete}" >
				<p:ajax event="query" partialSubmit="false"></p:ajax>
			</p:autoComplete>
		</h:form>
    </h:body>
</html>

The value is now submitted when i leave the fieldOne.
This is ok, but couldnt it be submitted with typing in the autocomplete field?

User avatar
snooperman
Posts: 155
Joined: 06 Nov 2012, 18:43

28 Jul 2014, 09:58

What happens if you put in your second p:ajax

Code: Select all

<p:ajax event="change" update="test_form" />
?
var details = {
. . PF.version: "5.0.x",
. . JSF.version: "2.x",
. . Tomcat.version: "8.x"
}

chrisu86
Posts: 17
Joined: 24 Jul 2014, 10:14

28 Jul 2014, 10:05

Then fieldOne still remains null in my TestBean :(

Code: Select all

<?xml version='1.0' encoding='ISO-8859-1' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
    </h:head>
    <h:body>
    	<p:log id="log" />
		<h:form id="test_form">
			<p:outputLabel for="fieldOne" value="fieldOne " />
			<p:inputText id="fieldOne" value="#{testBean.fieldOne}"/>
			<p:outputLabel for="fieldTwo" value="fieldTwo " />
			<p:autoComplete id="fieldTwo" value="#{testBean.fieldTwo}"  completeMethod="#{testBean.autocomplete}" >
				<p:ajax event="change" update="test_form" />
			</p:autoComplete>
		</h:form>
    </h:body>
</html>

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

28 Jul 2014, 10:29

Try to process the other input.
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

chrisu86
Posts: 17
Joined: 24 Jul 2014, 10:14

28 Jul 2014, 10:40

Still the same :(

Code: Select all

<?xml version='1.0' encoding='ISO-8859-1' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
    </h:head>
    <h:body>
    	<p:log id="log" />
		<h:form id="test_form">
			<p:outputLabel for="fieldOne" value="fieldOne " />
			<p:inputText id="fieldOne" value="#{testBean.fieldOne}"/>
			<p:outputLabel for="fieldTwo" value="fieldTwo " />
			<p:autoComplete id="fieldTwo" value="#{testBean.fieldTwo}"  completeMethod="#{testBean.autocomplete}" >
				<p:ajax event="query" partialSubmit="false" process="fieldOne"/>
			</p:autoComplete>
		</h:form>
    </h:body>
</html>

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

28 Jul 2014, 11:16

The setter isn't called or the input isn't updated? I would also do process="@this fieldOne"
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

chrisu86
Posts: 17
Joined: 24 Jul 2014, 10:14

28 Jul 2014, 11:25

The Setter isnt called, so in my autocomplete Method fieldOne returns null.
But i need this value to filter the autocomplete suggestions...

process="@this fieldOne" doesnt work:

Code: Select all

<?xml version='1.0' encoding='ISO-8859-1' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
    </h:head>
    <h:body>
    	<p:log id="log" />
		<h:form id="test_form">
			<p:outputLabel for="fieldOne" value="fieldOne " />
			<p:inputText id="fieldOne" value="#{testBean.fieldOne}"/>
			<p:outputLabel for="fieldTwo" value="fieldTwo " />
			<p:autoComplete id="fieldTwo" value="#{testBean.fieldTwo}"  completeMethod="#{testBean.autocomplete}" >
				<p:ajax event="query" partialSubmit="false" process="@this fieldOne"/>
			</p:autoComplete>
		</h:form>
    </h:body>
</html>

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

28 Jul 2014, 11:27

Could you post the post params again?
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 29 guests