Onkeypress dla wybranego komponentu.

0

Mam formularz z kilkoma polami i dwoma przyciskami w tabeli. Gdy przycisna Enter reaguje zawsze ten sam przycisk, pierwszy w tabeli. Czy i jak można przypisać aktywny przycisk w zależności o tego które z pól formularz jest aktywne. Np gdy jest aktywne pole1 przy przyciśnięciu Enter zareaguje przycisk1

<h:form id="indexForm">               
            <f:view locale="pl"/> 
            <p:growl autoUpdate="true"/>
            
            <table style="width:100%" cellpadding="5" >
                <tr>
                    <th align="right"><p:outputLabel value="Login: "/>  </th>
                    <th align="left"><id= p:inputText value="#{userBean.user.userLogin}" maxlength="8"/> </th>
                </tr>
                <tr>
                    <th align="right"><p:outputLabel value="Hasło: "/> </th>
                    <th align="left"><id="pole1" p:password value="#{userBean.user.password}"/></th>
                </tr>
                <tr>
                    <th><p:outputLabel style=" white-space: pre-wrap; word-wrap: break-word;"/><br></br></th>
                    <th><p:outputLabel style=" white-space: pre-wrap; word-wrap: break-word;"/><br></br></th>
                </tr>
                <tr>
                    <th align="right">   
                        <img src="style/identyfikator.png" width="230" height="144"/>  
                    </th>
                    <th align="left">
                        <p:password id="pole2" value="#{userBean.user.cardCode}" maxlength="12" onkeypress="if(event.keyCode == 13){event.keyCode=0;}" /><br></br>
                        <p:outputLabel style=" white-space: pre-wrap; word-wrap: break-word;"/><br></br><br></br>
                        <p:commandButton id="przycisk2" value="Zaloguj" action="#{userBean.login()}" onclick="document.getElementById('progressbar').style.display='block'"/>
                    </th>
                </tr>
            </table>
        </h:form> 
0

Problem rozwiązany przez wstawienie dodatkowego formularza.

1 użytkowników online, w tym zalogowanych: 0, gości: 1