错误:ViewMap中的非序列化属性值 [英] Error : non-serializable attribute value into ViewMap

查看:108
本文介绍了错误:ViewMap中的非序列化属性值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在2个系统(笔记本电脑)中使用相同的应用程序,但它在一个系统中工作但在另一个系统中没有。我在另一个系统中得到以下错误。我也发布了下面的代码。我想要做的是使用调用不同托管bean方法的按钮级联下拉列表,并使用placeOrder按钮在数据库中添加记录。但是我在页面时收到以下错误loading

i have the same application in 2 systems(laptops) but its working in one but not in another.i get the following error in another system. i have also posted the code below.what i want to do is cascading dropdown with a button that calls method of a different managed bean, and a placeOrder button to add a record in database.but i get the following error at the time of page loading

WARNING: Setting non-serializable attribute value into ViewMap: (key: stockOrderBean, value class: beans.stockOrderBean)
    SEVERE: Error Rendering View[/ClientTemplate/stockTrade.xhtml]
    java.io.NotSerializableException: beans.stockOrderBean

    WARNING: JSF1087: Unable to generate Facelets error page as the response has already been committed.
    SEVERE: javax.faces.FacesException: beans.stockOrderBean

xhtmlcode:

xhtmlcode:

                <h:outputText value="Exchange :"/>

                <p:selectOneMenu value="#{stockOrderBean.exchange}" style="width: 200px">
                    <f:selectItem itemLabel="Select Exchange"/>
                    <f:selectItem itemLabel="NSE" itemValue="nse"/> 
                    <f:selectItem itemLabel="BSE" itemValue="bse"/>
                    <p:ajax update="sym" listener="#{stockOrderBean.wow}"/>
                </p:selectOneMenu>
                <h:outputText value="Select ScripSymbol :"/>

                <p:selectOneMenu value="#{stockOrderBean.scripID}" style="width: 200px" id="sym">
                    <f:selectItem itemLabel="Select scrip"/>
                    <f:selectItems var="scrip" value="#{stockOrderBean.sl}" itemLabel="#{scrip.scripSymbol}" itemValue="#{scrip.scripID}"/>
                </p:selectOneMenu>

                <p:commandButton value="Get Quote"  actionListener="#{stockOrderBean.equity.setQuote}" oncomplete="cd.show()" update=":frmdialog" />

                <h:panelGrid columns="2" id="d1" style="width:565px">
                    <h:outputText value="How would you like to place order"/>                                
                    <p:selectOneRadio value="#{stockOrderBean.transType}">
                        <f:selectItem itemLabel="Market Order" itemValue="MarketOrder"/>
                        <p:ajax update="frmTrade:d1"/>
                        <f:selectItem itemLabel="Limit Order" itemValue="LimitOrder"/>
                        <p:ajax update="frmTrade:d1"/>
                   </p:selectOneRadio>                            
                   <h:outputText value="Trigger Price"/>
                   <p:inputText value="#{stockOrderBean.triggerPrice}" disabled="#{stockOrderBean.transType == 'LimitOrder'}"/>
                   <h:outputText value="Limit Price"/>
                   <p:inputText value="#{stockOrderBean.limitPrice}" disabled="#{stockOrderBean.transType == 'MarketOrder'}"/>                                
                </h:panelGrid>                

                <h:outputText value="Select your Demate Account"/>

                <p:selectOneMenu value="#{stockOrderBean.demateAccount}" style="width: 120px">
                    <f:selectItem itemLabel="#{stockOrderBean.demateAccount}" itemValue="#{stockOrderBean.demateAccount}"/>
                </p:selectOneMenu>

                <p:commandButton value="Place New Order"  actionListener="#{stockOrderBean.placeOrder}"/>
         <p:commandButton value="Reset New Order" type="reset"/>

</h:form>        
        <p:dialog widgetVar="cd" header="Scrip Quotes Detail" resizable="true">
            <h:form id="frmdialog">                        
                <table>
                            <tr>
                            <td>
                                Ask :
                            </td>
                            <td>                                        
                                <b><h:outputText value="#{stockOrderBean.equity.ask}"/></b>
                            </td>

                    </table>
               </h:form>
       </p:dialog>           

sockOrderBean代码:

sockOrderBean code:

    @javax.faces.bean.ManagedBean
@javax.faces.bean.ViewScoped
public class stockOrderBean{

    @WebServiceRef(wsdlLocation = "WEB-INF/wsdl/localhost_8080/StatelessWebService/StatelessWebService.wsdl")
    private StatelessWebService_Service service;
//properties with getter setter
 @ManagedProperty(value="#{equtiyBean}")
    private equityBean equity = new equityBean();
public void placeOrder(...){
//method not called
}

相同的代码在一个系统中工作但在另一个系统中没有。可能是什么原因以及如何解决它?

the same code is working in one system but not on another.what could be the reason and how do i solve it?

推荐答案

某些服务器配置需要在硬盘上保存HTTP会话,或者需要通过网络将它们传输到某个中央数据存储区,通常目标是在群集中的多个服务器之间共享会话,或者最大限度地减少过多的内存使用量。这反过来要求所有会话属性实现 Serializable 以便服务器可以使用 ObjectOutputStream 将Java对象转换为可以保存在磁盘上或通过网络传输的字节,并且 ObjectInputStream 将这些字节转换回Java对象。

Some server configurations need to save HTTP sessions on harddisk or need to transfer them over network to some central datastore, often with the goal to share the session between multiple servers in a cluster, or to minimize excessive memory usage. This in turn requires that all session attributes implement Serializable so that the server could use ObjectOutputStream to convert Java objects to bytes which can then be saved on disk or transferred over network and ObjectInputStream to convert those bytes back to Java objects.

如果存储在HTTP会话中的对象未实现 Serializable ,那么您将获得 NotSerializableException 在邮件中包含完整限定的类名。然后,您应该修复该类以实现 Serializable

If an object which is stored in the HTTP session does not implement Serializable, then you will get a NotSerializableException with the full qualified class name in the message. You should then fix the class to implement Serializable.

public class StockOrderBean implements Serializable {
    // ...
}

在JSF中,这个适用于所有视图和会话范围的托管bean。请求和应用程序作用域bean不需要实现 Serializable 。请注意,所有bean属性也应该是 Serializable 。但是只要遇到一个,你就会得到足够清楚的 NotSerializableException

In JSF, this applies to all view and session scoped managed beans. Request and application scoped beans doesn't need to implement Serializable. Note that all of the bean properties should also be Serializable. But you will get a clear enough NotSerializableException whenever one is encountered.

这篇关于错误:ViewMap中的非序列化属性值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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