是什么原因导致此页完整的请求? [英] What causes a full request on this page?

查看:155
本文介绍了是什么原因导致此页完整的请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑下面的JSF页面:

Consider the following jsf page:

<h:body>
    <h:form id="SessionStartDialog">
        <table>
            <tr>
                <td class="label">
                    <h:outputLabel
                        value="Enter your username:" 
                        for="UsernameField"/>
                </td>
                <td class="input">
                    <h:inputText 
                        id="UsernameField"
                        value="#{login.username}"
                        validator="#{login.validateUsername}"
                        tabindex="1">
                        <f:ajax render="SelectWorkingSetListbox
                                StartSessionButton UsernameMessage" />
                    </h:inputText>
                    <h:message 
                        id="UsernameMessage"
                        for="UsernameField" />
                </td>
            </tr>
            <tr>
                <td class="label">
                    <h:outputLabel
                        value="Choose a working-set:" 
                        for="SelectWorkingSetListbox"/>
                </td>
                <td class="input">
                    <h:selectOneMenu
                        id="SelectWorkingSetListbox"
                        tabindex="2"
                        disabled="#{!login.showWorkingSets}"
                        value="#{login.selectedWorkingSetName}">
                        <f:selectItems 
                            value="#{login.workingSetNames}"/>
                        <f:ajax />
                    </h:selectOneMenu>
                </td>
            </tr>
        </table>
        <h:commandButton 
            id="StartSessionButton"
            styleClass="StartSessionButton"
            disabled="#{!login.showWorkingSets}"
            value="Start Session" 
            tabindex="3"
            action="#{login.startSession}" >
            <f:ajax execute="@form"/>
        </h:commandButton>
    </h:form>
</h:body>

东西在那里使Safari浏览器报告一个错误,Ajax和完整请求被混合。我不明白为什么,因为这会导致请求所有组件包含&LT; F:AJAX&GT; 标签都有效。有什么问题吗?

Something in there causes Safari to report an error that ajax and full requests are being mixed. I do not understand why, as all components that cause requests contain <f:ajax>-tags. What is the problem here?

更新

我已经创建了一个触发此错误的一个小例子:

I have created a minimal example that triggers this error:

<h:body>
    <h:form>
        <f:ajax render="TextField">
            <h:inputText value="#{theBean.text}" />                
        </f:ajax>
        <h:outputText id="TextField" value="#{theBean.text}" />
    </h:form>
</h:body>

theBean 是一个简单的视图作用域的bean和文本类型的属性字符串。出于某种原因,这会触发在Safari 5.1以下消息:

theBean is a simple view-scoped bean and text a property of type String. For some reason this triggers the following message in Safari 5.1:

HTTPError这样的:HTTP传输返回一个0状态code。这是   通常混合Ajax和全面的请求的结果。这通常是   不需要的,出于性能和数据完整性的原因。

httpError: The Http Transport returned a 0 status code. This is usually the result of mixing ajax and full requests. This is usually undesired, for both performance and data integrity reasons.

更新2 这样做的原因似乎是,按键入里面输入 -field始终触发一个完整的形式提交。我不知道如何prevent这一点。如显示在第一个例子中,我想用户输入用户名,然后形式的其它组分得到启用(仅如果用户名是已知的)。我将如何正确地实现这一点?

Update 2 The reason for this seem to be that hitting enter inside the input-field always triggers a full form submit. I have no idea how to prevent this. As shown in the first example, I want to user to enter a username, and then the other components of the form get enabled (only if the username is known). How would I implement this correctly?

推荐答案

我会捕捉<大骨节病>输入开关键&LT;形式GT; 而是触发的onchange &LT;输入&GT; 元素,其中该密钥是pressed

I'd capture the Enter key on the <form> and instead trigger onchange on the <input> element where this key was pressed.

<h:form onkeydown="enterToChange(event)">
    ...
</h:form>

function enterToChange(event) {
  if (event.keyCode == 13 && event.target.tagName != 'textarea') {
    event.stopPropagation(); // Don't bubble up.
    event.preventDefault();  // Prevent default behaviour (submitting the form).
    event.target.onchange(); // Trigger onchange where key was actually pressed.
  }
}

请注意,这忽略了文本域,你会当然想保持预期的行为(插入新行)回车键。

Note that this ignores the enter key on textareas where you'd of course like to keep the intended behaviour (inserting a new line).

您可以根据需要添加额外的检查,看是否提交按钮是不是禁用,如果是这样的话,那么就大胆的事件去了。

You could if necessary add an extra check to see if the submit button is not disabled and if that is the case, then just let the event go.

这篇关于是什么原因导致此页完整的请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆