JSF SessionScoped Bean Fields成为空的primefaces

时间:2014-10-17 11:22:04

标签: java

I Have added the code for menuController my bean is of @SessionScoped and when one of my class extends menuController and in there if I set the value of id and navigate to other page then id value becomes null.

    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.SessionScoped;

    @ManagedBean(name = "menuController")
    @SessionScoped

    public class MenuController extends BasePage implements Serializable {

        /**
         * 
         */

        private String id;


        public MenuController() {

        }

        public String getId() {
            System.out.println("MenuController id = "+id);

            return id;
        }     

        public void setId(String id) {
            this.id = id;
        }


    }

这是继承menuController并设置其id值的bean的代码。 这个bean也是@SessionScoped。当我们从menuController

获取时,设置的id的值返回null
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name = "channelLeftPanel")
@SessionScoped
public class ChannelLeftPanel extends MenuController implements Serializable {


    public ChannelLeftPanel() {
    }

    public String channelEditPage(SelectEvent event) {

        this.setId(((GenericProduct) event.getObject()).getId());

        setSessionParameter("currentView", "/includes/content/channel/editChannel.xhtml");

        if (isDebugEnable)
            logger.debug("Channel ID = " + ((GenericProduct) event.getObject()).getId());
        return "mainContentArea";
    }
}

下面是我们进行ajax调用的表单,其listner方法在menuController中设置ID并更新主要内容表单,基本上是中心区域详细信息

    <h:form id="leftPanelform">
        <p:dataTable var="channelDetail" value="#{channelLeftPanel.channelList}"
            widgetVar="cTable"
            emptyMessage="No Channels found with given criteria"
            selectionMode="single" selection="#{channelLeftPanel.selectedChannel}"
            rowKey="#{channelDetail.id}"
            filteredValue="#{channelLeftPanel.filteredChannels}" styleClass="datatableLeft" style="width:100%">

            <f:facet name="header">
                <p:outputPanel>
                    <h:outputText value="Search all fields:" />
                    <p:inputText id="globalFilter" onkeyup="PF('cTable').filter()"
                        style="width:150px" placeholder="Enter keyword" />
                </p:outputPanel>
            </f:facet>
            <p:ajax event="rowSelect" listener="#{channelLeftPanel.channelEditPage}" update=":mainAreaContentform"/> 
            <p:column filterBy="#{channelDetail.name}" filterStyle="display:none; visibility:hidden;" style="width:80%">
                <h:outputText value="#{channelDetail.name}" />
            </p:column>
            <p:column filterBy="#{channelDetail.id}" filterStyle="display:none; visibility:hidden;" style="width:20%">
                [<h:outputText value="#{channelDetail.id}" />]
            </p:column>
        </p:dataTable>




    </h:form>

0 个答案:

没有答案