0

我正在使用 Icefaces 3.2 和 JSF 2.1.8。我在 xhtml 主页面中包含以下视图。单击链接后,看起来myViewBean哪个正在@ViewScoped丢失其状态。具有获取和设置所需项目列表的myLink逻辑。在渲染响应阶段,似乎有 empty 。如果将更改为,它将以预期的方式工作,但我还有 10 个其他 bean,所有这些都需要更改为 SessionScoped。是什么让 bean 失去了它的状态?或者有没有其他方法可以使用 ViewScoped?actionListenermyViewBeanmyViewBeanempList@ViewScoped@SessionScoped

main.xhtml

<!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:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:ui="http://java.sun.com/jsf/facelets" >
<f:view contentType="text/html">
        <h:head>
        </h:head>
        <h:body id="bodyId" bgcolor="white">
            <table border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td>
                    <ice:panelGroup>
                        <ice:form id="mainForm" name="mainForm">
                            <table>
                                <tbody>
                                    <tr>
                                        <td>
                                            <ui:include src="myTabs.xhtml"/>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </ice:form>
                    </ice:panelGroup>
                    </td>
                </tr>
            </table>
        </h:body>
</f:view>
</html>

myTabs.xhtml

<f:subview 
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:ui="http://java.sun.com/jsf/facelets">
<div>
    <table class="icePnlTbSet" id="myTabSet"
        border="0" cellpadding="0" cellspacing="0">
        <tbody>
            <tr>
                <td>
                <table cellpadding="0" cellspacing="0">
                    <tbody>
                        <tr>
                            <!-- My Tab 1 -->
                            <td class="icePnlTb" style="vertical-align: bottom;" title="tab1">
                            <table cellpadding="0" cellspacing="0">
                                <tbody>
                                    <tr>
                                        <td class="LftTop"><img alt="" src="/images/spacer.gif "
                                            width="4" height="1" /></td>
                                        <td class="MidTop"><img alt="" src="/images/spacer.gif "
                                            width="4" height="1" /></td>
                                        <td class="RtTop"><img alt="" src="/images/spacer.gif "
                                            width="4" height="1" /></td>
                                    </tr>
                                    <tr>
                                        <td class="LftMid"><img alt="" src="/images/spacer.gif "
                                            width="4" height="1" /></td>
                                        <td class="MidMid">
                                            <ice:commandLink id="myLink" value="MyTab 1" title=""
                                                actionListener="#{mySessionBean.tabChanged}">
                                                <f:param value="0" name="tab" />
                                            </ice:commandLink>
                                        </td>
                                        <td class="RtMid"><img alt="" src="/images/spacer.gif "
                                            width="4" height="1" /></td>
                                    </tr>
                                    <tr>
                                        <td class="LftBtm"><img alt="" src="/images/spacer.gif "
                                            width="4" height="1" /></td>
                                        <td class="MidBtm"><img alt="" src="/images/spacer.gif "
                                            width="4" height="1" /></td>
                                        <td class="RtBtm"><img alt="" src="/images/spacer.gif "
                                            width="4" height="1" /></td>
                                    </tr>
                                </tbody>
                            </table>
                            </td>
                            <!-- Repeat for n tabs -->
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
        </tbody>
    </table>
</div>
<ui:include src="tabcontent1.xhtml" />
 </f:subview>

tabcontent1.xhtml

<f:subview 
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ice:panelGroup>
    <ice:dataTable  id="empTable" value="#{myViewBean.empList}"
            var="emp">
            ...
    </ice:dataTable>
</ice:panelGroup>
</f:subview>
4

1 回答 1

0

@ViewScoped bean 仅在您从操作方法(将导航回同一页面)返回 null 或 void 时才保存数据,一旦您离开视图,数据就会丢失。

也许你可以试试@RequestScoped。

于 2013-07-25T06:18:24.400 回答