Как установить фокус на h: inputText внутри rich: dataTable одним столбцом после нажатия a4j: commandButton like (+) в нижнем колонтитуле rich: dataTable? - PullRequest
1 голос
/ 28 марта 2012
I am using JSF 1.2 and  Richfaces 3.3.3 in my sample JSF  Application.

  I have a form with  rich:dataTable that having single column  with h:inputText and footer having  a4j:commandButton  with value "add".

  when I click "add" button  then new row adding in  rich:dataTable and that is working fine.
  My need is after pressing "add" button the focus have to go newly created row to  the    h:inputText   field...


  sample code :

 <rich:dataTable  value="" var="">
    <rich:column>
        <f:facet name="header">
           <h:outputText value="name" />
        </f:facet>
                  <h:inputText id="name" value="#{obj.name}">
         </rich:column>

    <f:facet name="footer">
        <a4j:commandButton value="add"  action="{actionMethod}" />
    </f:facet>
</rich:dataTable>

когда я нажимаю кнопку «добавить», добавляется новая строка в rich: dataTable, и это работает нормально. Мне нужно после нажатия кнопки «добавить» фокус должен перейти на вновь созданную строку в поле h: inputText ...

Как это сделать, используя JQuery или java-скрипт, любая идея?

1 Ответ

1 голос
/ 10 октября 2012

Пожалуйста, найдите ниже JavaScript для настройки фокуса.

function setFocus() {
            var displayedRowsCountValue = document
                    .getElementById("exampleManageBean:displayedRowsCountValue").value;

            var firstRowIndexValue = document
                    .getElementById("exampleManageBean:firstRowIndexValueId").value;
            displayedRowsCountValue = parseInt(firstRowIndexValue - 1)
                    + parseInt(displayedRowsCountValue);
            for (i = parseInt(firstRowIndexValue - 1); i < parseInt(displayedRowsCountValue); i++) {
                var tmpComponent = "selectedId[" + i + "]";
                var temp = (document.getElementsByName(tmpComponent)[1]);
                if (temp != null && temp.checked == true) {
                    var temp1 = document
                            .getElementById("exampleManageBean:exampleTable:"
                                    + i + ":exampleTextBox");
                            temp1.focus();

                        }   
                    }
            }

Отображаемое значениеRowsCountValue & firstRowIndexValueId должно быть взято из t: dataScroller

...