开发者

Primefaces enter key closes dialog

When the below dialog is opened and the user hits enter it closes. I'm assuming that I need to somehow add some attribute to the below commandButton to not allow it to submit when the user hits enter. Any idea?

<p:dialog header="#{bundle['dreamSearch.HEADER']}"
        widgetVar="webSearchDlg" modal开发者_运维知识库="true" styleClass="dialog dialog2"
        draggable="false" resizable="false" showEffect="fade"
        hideEffect="fade">
        <h:form id="dreamWebSearchFrm">
        <div class="dialog-top-reg"></div>
        <div class="dialog-middle-reg">
        <div><p:commandButton styleClass="close zoom3" onclick="webSearchDlg.hide()" /></div>
            <div class="dialog-content dialog-content2">
                <h1 class="dream-search">
                    <h:outputText value="#{bundle['dreamSearch.HEADER']}" />
                </h1>
                <p class="dream-search">
                    <h:outputText value="#{bundle['dreamSearch.SUBHEADER']}" />
                </p>
                <p:panel id="searchTextPnl">
                    <div class="dream-search-wrap">
                        <fieldset>
                            <p:inputText id="searchText" value="#{dreamSearchBean.searchText}"/>
                            <p:commandButton tabindex="-1" styleClass="form-btn1" value="#{bundle['dreamSearch.search.button.TEXT']}" 
                            actionListener="#{dreamSearch.search}" update=":dreamWebSearchFrm:resultsPnl"/>
                        </fieldset>
                    </div>
                </p:panel>
                <p:panel id="resultsPnl">
                    <div class="data-grid-wrap">
                    <h:outputFormat escape="false" value="#{bundle['dreamSearch.imageResults.TEXT']}" rendered="#{dreamSearchBean.shouldRender}">
                        <f:param value="#{dreamSearchBean.searchText}" />
                    </h:outputFormat>
                        <p:dataGrid var="dream" value="#{dreamSearchBean.dreams}" rendered="#{dreamSearchBean.shouldRender}" columns="5"
                            rows="10" paginator="true" effect="true"
                            styleClass="ui-header-visibility"
                            paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                            rowsPerPageTemplate="10,15,20" paginatorPosition="bottom">
                            <p:column>
                                <h:panelGrid columns="1" style="width:100%">
                                    <p:commandLink onclick="webSearchDlg.hide();dreamEditDlg.show();" update=":dreamEditFrm:display"> 
                                        <f:setPropertyActionListener value="#{dream}" target="#{dreamModifyBean.selectedDream}"/>
                                        <f:setPropertyActionListener value="false" target="#{dreamModifyBean.editLink}"/>
                                        <p:graphicImage value="#{dream.imageThumb}" width="100" height="100" />
                                    </p:commandLink>
                                </h:panelGrid>
                            </p:column>
                        </p:dataGrid>
                    </div>
                </p:panel>
            </div>
        </div>
        <div class="dialog-bottom-reg"></div>
    </h:form>   
    </p:dialog>


You could do it with Javascript. A similiar question with a variety of answers has been asked some time ago.

Primefaces has it's own (or some adapted JQuery / YUI) javascript bundled. Don't know how it interacts with self-made js. Give it a try!


In order to solve this, I had to ensure that the close button was the very last button within the form.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜