Submit a inputfield with p:ajax#query within p:autocomplete

UI Components for JSF
Post Reply
Aditya
Posts: 163
Joined: 16 Nov 2011, 20:19

25 Jul 2014, 21:22

How do I submit some h:inputText field/send custom data while p:autocomplete sends a query for fetching suggestions from server. I tried doing like this:

<p:autoComplete completeMethod="..." >
<p:ajax event="query" onstart="method1()" process="@this, field1"/>
</p:autoComplete>
<h:inputHidden id="field1" value="#{search.value2}"/>
The field seems to be submitted along with the sent data to the server however the value is not set in managed bean. Probably the process attribute of above p:ajax does not seem to work correctly for above case. So, How do I submit this h:inputHidden#field1 along with query for suggestions ?
*****
Aditya

Using :
Primefaces 5.0 + Omnifaces 1.7 + Prettyfaces
JSF 2.2.2 -Myfaces
Tomcat 7.0.42

Aditya
Posts: 163
Joined: 16 Nov 2011, 20:19

26 Jul 2014, 21:37

Can one suggest why the process attribute does not work for me as expected ?
*****
Aditya

Using :
Primefaces 5.0 + Omnifaces 1.7 + Prettyfaces
JSF 2.2.2 -Myfaces
Tomcat 7.0.42

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

26 Jul 2014, 22:11

You have 155 posts

http://forum.primefaces.org/viewtopic.php?f=3&t=1194

Points 2,3 and 9

And with just code snippets, most likely noone will take the effort to make it a full working example to try to anlyze it. You should know all this by now. And with a full example I mean bean xhtm but all as minimal as pussible but FULLY working (no compile errors etc)

bsanders1979
Posts: 69
Joined: 02 Jun 2013, 18:37

27 Jul 2014, 06:32

My approach to these types of problems starts with looking at the uncompressed javascript source. I see that PrimeFaces.widget.AutoComplete has a search function which gets its value from _self.input, so you'll need to re-implement the method. I will assume that you are not using composite components, that the id of the autocomplete is "autocomplete", and that you are using a version of PrimeFaces which has the PF() client-side method.

Code: Select all

<p:autocomplete id="autocomplete" ... />

<script type="text/javascript">
//<![CDATA[
$(function() {
    PF("autocomplete").search = function(query) {
        query += "," + $(PrimeFaces.escapeClientId("field1")).val();
        ...Copy of original code...
    }
})
//]]/>
</script>
The key points to note here are that we are replacing the original search with a new implementation, although it's the exact same code with one line added at the beginning to facilitate the passing of the 2nd value. The script must go AFTER the component tag. The CDATA block is a precaution and may not be necessary. If the code for search changes in future releases of PF, then you would need to revisit this piece. The component names here are simplified and will need to be adjusted as needed. You may format the query as you desire, but the purpose here is to illustrate one possible solution. Who knows, maybe you want to format it as a JSON string? Hope this helps...
PF 5.0
PF Ext 0.7.1
OmniFaces 1.7
Tomcat 7.0.37
JSF 2.1.24

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

28 Jul 2014, 08:35

I have a very common problem described here with a full example :)

http://forum.primefaces.org/viewtopic.php?f=3&t=39065

Do i really have to edit primefaces source code to get this working?

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

28 Jul 2014, 09:25

See my answer in your own post

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 35 guests