开发者

f:param not passed in ajax request

开发者 https://www.devze.com 2023-04-09 01:36 出处:网络
I\'m having trouble with the following code: <h:inputHidden value=\"autoCompleteHidden\" id=\"administradorAutocompleteType\">

I'm having trouble with the following code:

<h:inputHidden value="autoCompleteHidden" id="administradorAutocompleteType">
                            <f:param value="#{suggestionEntitiesDM.usuario}" name="type"></f:param>
             开发者_Python百科           </h:inputHidden>
                        <p:autoComplete id="administradorAutocomplete"
                                        value="#{empresaDM.administradorSeleccionada}"
                                        completeMethod="#{suggestionEntitiesDM.suggestionList}"
                                        var="administrador" itemLabel="#{administrador.txtNombreUsuario}"
                                        forceSelection="true" 
                                        itemValue="#{administrador}" converter="entityConverter">
                            <p:ajax event="start" update="administradorAutocomplete" process="administradorAutocompleteType"/>


                        </p:autoComplete>

What I want is to send the type parameter in request so that I can get the value by using:

String type=FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("type");

However I'm just geeting null when referencing the type String, I have even checked the request parameters using Firebug and effectively administradorAutocompleteType=autoCompleteHidden is passed but type=value is never posted. What I am doing wrong?, how can I pass additional request parameters when using the f:ajax JSF 2 tag?. Thanks a lot.


As stated in this PF forum topic, <p:ajax> is not supported in <p:autoComplete>. Also, passing additional arguments is not possible in completeMethod.

I think <p:remoteCommand> is most suitable for your purpose. It generates a JS function which allows you to set a bean property. This JS function is in turn to be called by onstart attribute of <p:autoComplete>.

<h:form>
    <p:autoComplete 
        value="#{bean.text}" 
        onstart="setType()"
        completeMethod="#{bean.complete}"
        >
    </p:autoComplete>
    <p:remoteCommand name="setType">
        <f:setPropertyActionListener target="#{bean.type}" value="foo" />
    </p:remoteCommand>
</h:form>

with

private String text;
private String type;

public List<String> complete(String query) {
    System.out.println("type: " + type); // type: foo
    // ...
}

You can set foo with whatever value you want. It'll be available as type in the scope of the complete() method.


Found a solution to the problem, the trick was to use f:attribute as suggested in this link:

f:param or f:attribute support on primefaces autocomplete?

since f:param was not being sent in the request, and the complete method required a fixed parameter to work.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号