Submit custom data/inputfield while `p:autocomplete` sends a query for fetching suggestions

一世执手 提交于 2019-12-25 03:39:13

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!