Primefaces自动完成:如何在单击commandlink后将焦点设置为自动完成

Shr*_*uti 5 primefaces

场景:我使用了autcomplete的组件和infront,我使用了一个带搜索图像的命令链接.

我的目的是在点击commandlink后将光标显示在自动完成中.

我的代码如下:

自动完成:

<p:autoComplete id="senderAutocomplete" widgetVar="senderInfo"
                                                    value="#{customerReviewLazyDataModel.customerReviewVO.senderVO}"
                                                    completeMethod="#{customerReviewLazyDataModel.searchOrganizations}"
                                                    var="senderVO"  
                                                    itemValue="#{senderVO}" converter="organizationConverterForCustomerReview"
                                                    size="60">
Run Code Online (Sandbox Code Playgroud)

commandlink

<p:commandLink oncomplete="setFocus()" ajax="true">
                                                        <p:graphicImage value="/app-resources/themes/yob/images/search.png" style="margin-bottom: -4px;"></p:graphicImage>
                                                    </p:commandLink> 
Run Code Online (Sandbox Code Playgroud)

js功能

function setFocus(){
        document.getElementById("senderAutocomplete").focus();
}
Run Code Online (Sandbox Code Playgroud)

这个问题有什么解决方案吗?

use*_*983 0

您用于获取要聚焦的输入的 DOM 元素的 ID 是错误的。首先,您必须考虑表单的 id。另外 a 的输入的 idp:autoComplete有一个后缀_input。所以用这个:

document.getElementById("formId:senderAutocomplete_input").focus();
Run Code Online (Sandbox Code Playgroud)

您还应该设置process="@this"commandButton因为您只是用它来聚焦autoComplete