问题
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 ?
回答1:
<p:autoComplete/>
's completeMethod
is executed during the APPLY_REQUEST_VALUES
phase. As you know, in the JSF Lifecycle, request values are not committed to the backing bean model until the UPDATE_MODEL_VALUES
phase, a full phase after the APPLY_REQUEST_VALUES
.
What this means is that the completeMethod
cannot access any (new) values that are entered in the view.
To access anything backing bean-dependent, you'll have to do it the hard way, by directly pulling the value off the component:
/**
Find the component
*/
UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
UIComponent hiddenInput= viewRoot.findComponent("someId");
/**
Get the value
*/
String theValue = hiddenInput.getSubmittedValue().toString();
来源:https://stackoverflow.com/questions/24974781/submit-custom-data-inputfield-while-pautocomplete-sends-a-query-for-fetching