-
1. Re: Autocomplete and returning the id
jlpktnst Dec 1, 2011 7:32 AM (in response to mettehummel)Same question here, want to bind 2 different values, hidden id and display the text. User searches by text, but the codebehind needs id.
Doable? Right now I have a workaround which is quite bad, got id in field and a separate ajax lookup for description. But that is not good.
-
2. Re: Autocomplete and returning the id
mcmurdosound Dec 1, 2011 9:52 AM (in response to jlpktnst)You can use rich:select but without (ajax) suggestion.
Or build a converter String<->Object.
Piggybagging the id as hidden request parameter.
<rich:autocomplete autocompleteMethod="#{tableDemoManager.autocompleteDTO}" var="result" mode="ajax" showButton="true" layout="table" fetchValue="#{result.name}" onselectitem="doSelect(event);">
<rich:column>
<span data-value="#{result.name}" data-uuid="#{result.uuid}">#{result.name}</span>
</rich:column>
</rich:autocomplete>
<a4j:jsFunction name="submitUUID" action="#{tableDemoManager.submitUUID}">
<a4j:param name="uuid" assignTo="#{tableDemoManager.uuid}"/>
</a4j:jsFunction>
function doSelect(event){
var currentValue = event.rf.component.getValue();
var items = event.rf.component.items;
var item = jQuery(items).find("span[data-value='" +currentValue+"']");
var uuid = jQuery(item).attr('data-uuid');
console.log(uuid);
submitUUID(uuid);
}
-
3. Re: Autocomplete and returning the id
jlpktnst Dec 1, 2011 11:28 AM (in response to mcmurdosound)This seems useful, I will try when I can.
Another question: can I override the javascript for clientside matching when I have manual text input rich:select? I want to have containsText instead of startsWith...
-
4. Re: Autocomplete and returning the id
healeyb Feb 21, 2012 6:27 AM (in response to jlpktnst)RE: can I override the javascript for clientside matching w
(a very late answer, so for the benefit of anyone else coming across this post...) you should be able to use
rich:autocomplete clientFilterFunction="myFilter":
function myFilter(prefix, string) {
// return true on match or false
}
Regards,
Brendan.
-
5. Re: Autocomplete and returning the id
sunkaram Feb 21, 2012 11:56 AM (in response to mettehummel)did you try this:
<rich:autocomplete mode="ajax" showButton="true" layout="table" autocompleteMethod="#{patientSearch.searchPatientByAll}"
fetchValue="#{patient.patientId}" id="txtPatientSearch" var="patient">
<rich:column>
<h:outputText value="#{patient.name}" />
</rich:column><rich:column>
</rich:autocomplete>
<h:outputText value="#{patient.gender}" />
</rich:column>This shows name and gender in the autocomplete field and returns id to the backing bean...