0

I have a popup dialog with datatable and I want to have no focus in filter inputText fields. I want to have focus on button under this table. I tried this:

<p:focus id="focus" for="buttonFocus" context="dialog"/>
<p:dialog id="dialog" header="Выбор организации" widgetVar="vDialog" modal="true" resizable="false">  
    <p:dataTable 
    dblClickSelect="true"
    id="table"               
                 var="record"
                 value="#{myBean.tableList}"
                 rowKey="#{record.waId}"
                 filteredValue="#{myBean.filteredList}" 
                 lazy="true"                                                             
                 >                                                                      
                <p:column headerText="Name" filterBy="#{recordp.name}" sortBy="#{recordp.name}">                                    
                         #{record.name}
                </p:column>                                                                                                 
     </p:dataTable>  
        <p:commandButton id="buttonFocus" actionListener="#{myBean.fill}"/>     
</p:dialog>

it doesn't help. So, how to set focus on button in such situation?

4

1 回答 1

1

我找到了几个建议。

所以一个对我有用的是:

       <script type="text/javascript">

       PrimeFaces.widget.Dialog.prototype.applyFocus = function() {
          var firstInput = this.jq.find('#buttonFocus');
              firstInput.focus();
       }
       </script>

这种方法不需要 p:focus 。并且不要忘记在表单中添加 prependId="false",否则 id 会改变。

第二个仅适用于输入元素(不适用于按钮):

       <script type="text/javascript">

       PrimeFaces.widget.Dialog.prototype.applyFocus = function() {

       }
       </script>

在这里您需要 p:focus 元素,但就像我说的那样,这仅适用于输入。

如果您有正确版本的 primefaces(未经测试),您可以查看此博客的第三个解决方案

于 2013-09-03T11:15:42.917 回答