Jsf Primefaces SelectOne菜单焦点不工作

Jsf Primefaces SelectOne菜单焦点不工作,jsf,primefaces,Jsf,Primefaces,我使用的是PrimeFaces 5.1在我的应用程序中,我使用了selectOneMenu在dataTable中,当我按下add more按钮需要聚焦selectOneMenu按钮时 示例代码 JavaScript function focusMenu(id) { var focusId="#{p:component('mainTable')}"+":"+id; PrimeFaces.focus(final); } xhtml <div style="padding-left:4px;h

我使用的是
PrimeFaces 5.1
在我的应用程序中,我使用了
selectOneMenu
dataTable
中,当我按下add more按钮需要聚焦
selectOneMenu
按钮时

示例代码

JavaScript

function focusMenu(id)
{
var focusId="#{p:component('mainTable')}"+":"+id;
PrimeFaces.focus(final);
}
xhtml

<div style="padding-left:4px;height: 
expression(this.scrollHeight > 399? '400px' : 'auto');max-height:400px;overflow-x:auto;overflow-y:auto;">  
<p:dataTable id="mainTable" value=#{main.UserDataTable} .....>
<p:column headerText="Drop Down">
<p:selectOneMenu id="dropdDownId"...>
.....
</p:selectOneMenu>
</p:column>
<p:column headerText="Operation">
<p:commandButton value="Add More Row" action="{user.addMoreRowAction}"
update="mainTable"/>
</p:column>
</p:dataTable>
</div>
在这里,上面的代码可以按照我的预期聚焦上次添加的
selectOneMenu
,但浏览器滚动条不会在聚焦最近添加的
selectOneMenu
组件的基础上向下移动


请帮助我解决此问题。

您可以使用
scrollTop
功能将滚动条转到焦点id。 将
focusid
传递到函数中

function setScrollPos(focusId){
    $('html,body').animate({
             scrollTop: $(focusId).offset().top-65
    }, 1000);
}
调用上述函数

function focusMenu(id)
{
var focusId="#{p:component('mainTable')}"+":"+id;
PrimeFaces.focus(final);
setScrollPos(focusId); <<------
}
功能焦点菜单(id)
{
var focusId=“#{p:component('mainTable')}”+”:“+id;
焦点(最终);
setScrollPos(聚焦);
function focusMenu(id)
{
var focusId="#{p:component('mainTable')}"+":"+id;
PrimeFaces.focus(final);
setScrollPos(focusId); <<------
}