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

Primefaces自动完成:如何在单击commandlink后设置自动完成的焦点,primefaces,Primefaces,场景:我使用了组件,在autcomplete的前面我使用了一个带有搜索图像的命令链接 我的目的是在单击commandlink后在自动完成中显示光标 我的代码如下: 自动完成: <p:autoComplete id="senderAutocomplete" widgetVar="senderInfo" value="#{customerReviewLazyDataModel.custome

场景:我使用了组件,在autcomplete的前面我使用了一个带有搜索图像的命令链接

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

我的代码如下:

自动完成:

<p:autoComplete id="senderAutocomplete" widgetVar="senderInfo"
                                                    value="#{customerReviewLazyDataModel.customerReviewVO.senderVO}"
                                                    completeMethod="#{customerReviewLazyDataModel.searchOrganizations}"
                                                    var="senderVO"  
                                                    itemValue="#{senderVO}" converter="organizationConverterForCustomerReview"
                                                    size="60">

这个问题有什么解决办法吗

用于获取输入焦点的DOM元素的ID错误。首先,你必须考虑表单的ID。另外,
p:autoComplete
的输入id有一个后缀
\u input
。所以用这个:

document.getElementById("formId:senderAutocomplete_input").focus();

您还应该在
commandButton
上设置
process=“@this”
,因为您只是使用它来聚焦
自动完成

,我解决了这个问题,添加了一个css样式类,并使用jquery(包含在Primefaces上)来设置焦点

<p:autoComplete id="senderAutocomplete" widgetVar="senderInfo" ...

*styleClass="focusme"*
/>

commandlink是这样的:

<p:commandLink *oncomplete="$('.focusme').focus()"* ajax="true">

谢谢。你的回答解决了我的问题。我使用了“document.getElementById(“senderAutocomplete_input”).focus();”这和它的工作很好。
<p:autoComplete id="senderAutocomplete" widgetVar="senderInfo" ...

*styleClass="focusme"*
/>
<p:commandLink *oncomplete="$('.focusme').focus()"* ajax="true">