0

I click the Button "save" and then push Enter on the focused InputText. Now my other Dialog opens. When the InputText got no focus, pressing Enter wont open the other dialog. Why is that happening?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
    <h:form>
        <!-- BUTTONS -->
        <p:commandButton 
            id="defineXmlButton" 
            value="define"
            oncomplete="PF('dialogTxParams').show();"
            update="dialogTxParams" />

        <p:commandButton 
            id="openSaveChainDialogButton"
            value="save" 
            ajax="true"
            onclick="PF('saveChainDialog').show();"
            />

        <!-- DIALOGS -->
        <p:dialog header="Save Dialog" widgetVar="saveChainDialog"
                id="saveChainDialog" modal="true" resizable="false"
                closeOnEscape="true">

            <h:panelGrid columns="3" cellpadding="5" cellspacing="0">
                <p:outputLabel for="chainname">Name</p:outputLabel>
                <p:inputText id="chainname" value=""></p:inputText>
                <p:commandButton 
                    id="saveChainButton"
                    value="OK" 
                    actionListener="#{chainController.saveChain()}"
                    ajax="true" 
                    oncomplete="PF('saveChainDialog').hide();"
                    update="saveChainDialog">
                </p:commandButton>
            </h:panelGrid>

        </p:dialog>

        <p:dialog 
            header="#{txWfSenderModel.selectedWf.description}"
            id="dialogTxParams" 
            widgetVar="dialogTxParams" 
            modal="false"
            resizable="false" 
            dynamic="true" 
            fitViewport="true"
            closeOnEscape="true">

        </p:dialog> 
    </h:form>       
</h:body>
</html>

Edit: Kukeltje led to another question, which helped me to find a solution. See the comments. I solved the problem by using an own <h:form> tag for each dialog, so the default button is correct.

qecce
  • 71
  • 11
  • @Kukeltje I don't see your point. Your marked possible duplicate question is different to my question. I don't want to exactly set what happens when I press enter. I need to know, if I did something wrong and why my code acts like it does (opens the second dialog). But your link may be helpful, but I don't see it as a duplicate. – qecce Sep 16 '16 at 14:03
  • 2
    That issue is about default buttons in forms... Pressing enter in an input in a form executes the default button. In your case that is the first one. That button has `oncomplete="PF('dialogTxParams').show();` So that opens the dialog. If there is no focus in an input, it won't fire the default button. So the behaviour you see and the 'why' that you ask in the title is explained in the duplicate. If that is not the issue, please clarify what you mean by 'other dialog' refer to it by e.g. id's from the code explain better – Kukeltje Sep 16 '16 at 14:08
  • @Kukeltje Ok, if a question is also a duplicate, when the given answer helps me, but the question differs, then I am fine with that. The accepted answer there helped me to understand it + your comment. I will add my solution. – qecce Sep 16 '16 at 14:19
  • 1
    Duplicates is not about questions, but about answers. It doesn't make sense to copypaste an identical answer over different questions. Instead, those questions should be closed as duplicates so that search engines can better keep track of new keywords. – BalusC Sep 16 '16 at 21:22

0 Answers0