没有发送ViewState [英] No ViewState is sent

查看:69
本文介绍了没有发送ViewState的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有primefaces 3.5的JSF 2.2.0-m12应用程序.由于我已将应用程序从JBoss 7.1.1移植到Tomcat 7.0.39,因此在重新加载页面后对输入字段(输入文本,滑块,按钮等)的第一个更改可以正常工作,但第二个更改则无济于事.我搜索了第一个请求和第二个请求之间的区别:

I have a JSF 2.2.0-m12 application with primefaces 3.5. Since I ported the application from JBoss 7.1.1 to Tomcat 7.0.39, the first change of an inputfield (inputtext, slider, button,...) after reloading a page works fine, but the second change does nothing. I searched for the differences between the first and the second request:

第一个请求:

  • JSF阶段:执行1到6阶段
  • 在Firebug中,网络->所有-> POST zinsrechner.xhtml->发布"是一个视图状态:

contentForm contentForm
contentForm:inputZinsatz        2.0
contentForm:j_idt157:anla...    277
contentForm:j_idt157:maxA...    25
contentForm:j_idt157:slid...    277
contentForm:j_idt72:saveA...    10000
contentForm:j_idt72:saveA...    20000
contentForm:selectSparArt       false
javax.faces.ViewState        -1622287370124327744:4775655032591022279
javax.faces.behavior.even...    slideEnd
javax.faces.partial.ajax        true
javax.faces.partial.event       slideEnd
javax.faces.partial.execu...    contentForm:j_idt157:sliderAnlageDauer
javax.faces.partial.rende...    contentForm
javax.faces.source              contentForm:j_idt157:sliderAnlageDauer

第二个请求:

  • JSF阶段:在第1阶段之后,执行了6个
  • 在Firebug的网络->所有-> POST zinsrechner.xhtml->帖子"中,视图状态:
  • JSF phases: After Phase 1 the 6 is executed
  • In Firebug 'network -> all -> POST zinsrechner.xhtml -> post' is no viewstate:

contentForm contentForm
contentForm:inputZinsatz        2.0
contentForm:j_idt157:anla...    460
contentForm:j_idt157:maxA...    25
contentForm:j_idt157:slid...    460
contentForm:j_idt72:saveA...    10000
contentForm:j_idt72:saveA...    20000
contentForm:selectSparArt       false
javax.faces.behavior.even...    slideEnd
javax.faces.partial.ajax        true
javax.faces.partial.event       slideEnd
javax.faces.partial.execu...    contentForm:j_idt157:sliderAnlageDauer
javax.faces.partial.rende...    contentForm
javax.faces.source              contentForm:j_idt157:sliderAnlageDauer

现在我不确定,是否缺少ViewState会导致错误行为.

Now I'm not sure, if the missing ViewState causes the incorrect behaviour.

在我的页面中有三种不包含表格的形式.对于每种形式,都会在即将显示的html(压缩)中呈现一个隐藏的viewstate标签:

In my pages are three not enclosing forms. For each form is a hidden viewstate tag rendered in the outcoming html(condensed):

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Zinsrechner</title>
<body>
<div class="wrapper">
    <form id="headerForm" name="headerForm" method="post"
        action="/Tools_Web/pages/rechner/zinsrechner.xhtml"
        enctype="application/x-www-form-urlencoded">
        <input type="hidden" name="headerForm" value="headerForm" />

        <header>
            <html xmlns="http://www.w3.org/1999/xhtml">
                <script type="text/javascript"> ... </script>
                <nav>...</nav>
            </html>
            <h1>Zinsrechner</h1>
        </header>
        <input type="hidden" name="javax.faces.ViewState"
            id="j_id1:javax.faces.ViewState:0"
            value="863948539220421748:307506195687956782" autocomplete="off" />
    </form>


    <div id="contentOutline">
        <div id="content">
            <div class="wrapper">
                <form id="contentForm" name="contentForm" method="post"
                    action="/Tools_Web/pages/rechner/zinsrechner.xhtml"
                    enctype="application/x-www-form-urlencoded">
                    <input type="hidden" name="contentForm" value="contentForm" />
                    <div id="sidebar"></div>
                    <div id="zinsrechner">
                        <!-- Headline -->
                        <header>
                            <div style="padding: 0 1em; float: right;">
                                <span
                                    title="Zinssatz pro Jahr"><span id="contentForm:j_idt70"
                                    class="ui-inplace ui-hidden-container"><span
                                        id="contentForm:j_idt70_display" class="ui-inplace-display"
                                        style="display: inline">2.0%</span><span
                                        id="contentForm:j_idt70_content" class="ui-inplace-content"
                                        style="display: none"><input
                                            id="contentForm:inputZinsatz" name="contentForm:inputZinsatz"
                                            type="text" value="2.0"
                                            style="width: 70px; right: 0px; top: 0 position:absolute"
                                            class="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all" />
                                        <script id="contentForm:inputZinsatz_s" type="text/javascript">PrimeFaces.cw('InputText','widget_contentForm_inputZinsatz',{id:'contentForm:inputZinsatz',behaviors:{change:function(event) {mojarra.ab('contentForm:inputZinsatz',event,'valueChange','@form','@form headerForm footerForm')},change:function(event) {PrimeFaces.ab({source:'contentForm:inputZinsatz',event:'change',process:'contentForm:inputZinsatz',update:'contentForm'}, arguments[1]);}}});</script></span></span>
                                <script id="contentForm:j_idt70_s" type="text/javascript">PrimeFaces.cw('Inplace','widget_contentForm_j_idt70',{id:'contentForm:j_idt70',effect:'fade',effectSpeed:'normal',event:'click',toggleable:true});</script>
                                </span>
                            </div>
                        </header>


                        <div>
                            <!-- More input elements -->
                        </div>
                    </div>
                    <input type="hidden" name="javax.faces.ViewState"
                        id="j_id1:javax.faces.ViewState:0"
                        value="863948539220421748:307506195687956782" autocomplete="off" />
                </form>
            </div>
        </div>
    </div>
    <form id="footerForm" name="footerForm" method="post"
        action="/Tools_Web/pages/rechner/zinsrechner.xhtml"
        enctype="application/x-www-form-urlencoded">

        <input type="hidden" name="footerForm" value="footerForm" />

        <footer></footer>
        <input type="hidden" name="javax.faces.ViewState"
            id="j_id1:javax.faces.ViewState:0"
            value="863948539220421748:307506195687956782" autocomplete="off" />
    </form>
</div>

我尝试解决此处描述的JS问题未成功: h:commandButton/h:commandLink不适用于第一次单击,仅适用再次点击

I tried unsuccessfully to solve the problem with the JS described here: h:commandButton/h:commandLink does not work on first click, works only on second click

以及web.xml中的以下配置:

and the following configurations in web.xml:

<context-param>
<param-name>com.sun.faces.autoCompleteOffOnViewState</param-name>
<param-value>false</param-value>
</context-param>

<context-param>
<param-name>com.sun.faces.enableViewStateIdRendering</param-name>
<param-value>false</param-value>
</context-param>

已编辑 这是xhtml页面:

Edited This is the xhtml page:

<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
template="/template/baseLayout.xhtml"
xmlns:ad="http://java.sun.com/jsf/composite/components/ad">
<ui:param
    name="title"
    value="Zinsrechner" />
<ui:param
    name="bgClass"
    value="whiteGrid" />
<ui:define name="content">
    <div id="zinsrechner">
        <!-- Headline -->
        <header>
            <p:selectOneButton
                id="selectSparArt"
                value="#{zinsrechner.monthly}"
                styleClass="selectSparArt">
                <f:selectItem
                    itemLabel="Anlagebetrag"
                    itemValue="#{false}" />
                <f:selectItem
                    itemLabel="Sparbetrag"
                    itemValue="#{true}" />
                <p:ajax
                    event="change"
                    update="contentForm"
                    process="selectSparArt"
                    listener="#{zinsrechner.onMonthlyChange()}" />
            </p:selectOneButton>
            <div style="padding: 0 1em; float: right;">
                <span title="Monatlicher Sparbetrag">
                    <p:inplace label="#{zinsrechner.saveAmount}€" rendered="#{zinsrechner.monthly}">
                        <p:inputText
                            style="width: 70px; margin-right: 10px;"
                            id="inputSparbetrag"
                            value="#{zinsrechner.saveAmount}">
                            <p:ajax
                                event="change"
                                update="contentForm"
                                process="inputSparbetrag"
                                listener="#{zinsrechner.onSaveAmountChange()}" />
                            </p:inputText>
                        </p:inplace>
                    </span>

                <span title="Zinssatz pro Jahr">
                    <p:inplace label="#{zinsrechner.interestRate}%">
                        <p:inputText
                            style="width: 70px; right:0px; top: 0 position:absolute"
                            id="inputZinsatz"
                            value="#{zinsrechner.interestRate}">
                            <p:ajax
                                event="change"
                                update="contentForm"
                                process="inputZinsatz"
                                listener="#{zinsrechner.onInterestRateChange()}" />
                                <f:ajax execute="@form" render="@form :headerForm :footerForm"></f:ajax>
                        </p:inputText>
                    </p:inplace>
                </span>
            </div>
        </header>

        <!-- Y-Achse -->
        <ad:yAxis
            component="#{zinsrechner}"
            editable="true"
            inputId="saveAmount"
            inputMaxValueId="saveAmountMax"
            rendered="true"
            sliderId="saveAmountSlider"></ad:yAxis>

        <!-- Chartcontainer -->
        <ad:barChart
            component="#{zinsrechner}"
            rendered="true"
            renderSumBarLeft="false"
            renderSumBarRight="false" />


        <!-- X-Achse -->
        <ad:xAxis
            component="#{zinsrechner}"
            sliderId="sliderAnlageDauer"
            editable="true"
            inputId="anlagedauer"
            inputMaxValueId="maxAnlagedauer"
            rendered="true"
            renderSumBarLeft="false"
            renderSumBarRight="false"></ad:xAxis>
    </div>
</ui:define>

我该怎么做才能将ViewStatus传递给服务器?缺少ViewState可能是行为不正确的原因吗?

What can I do to pass the ViewStatus to the server? Could the missing ViewState be the reason for the incorrect behaviour?

感谢您的帮助.如果您需要更多信息,请问!

Thanks for your help. If you need more information, just ask!

推荐答案

像BalusC和Jens所说,问题是Primefaces和JSF的版本:

Like BalusC and Jens said the problem are the versions of Primefaces and JSF:

PF 3.5不是为JSF 2.2设计的.您应该为此使用PF 4.0.请使用常规JSF组件进行测试,以排除PF 3.5的原因,或降级到JSF 2.1.

PF 3.5 is not designed for JSF 2.2. You should use PF 4.0 for that. Please test using regular JSF components to exclude PF 3.5 from being the cause, or downgrade to JSF 2.1.

降级到JSF 2.1后,它可以工作.

After downgrading to JSF 2.1 it works.

这篇关于没有发送ViewState的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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