在JSF中呈现错误并读取足够的bean属性时出错

时间:2015-09-07 22:05:29

标签: java spring jsf

我曾经让我的平台配置工作正常,然后我添加了一个身份验证过程,这不再起作用了。它说firstedit没有被渲染,并且渲染视图是不工作的。

AVERTISSEMENT: JSF1063 : AVERTISSEMENT ! Définition d’une valeur d’attribut non-sérialisable dans HttpSession (clé : UserloginMB, classe de la valeur : empsuite.managedbean.UserloginManagedBean).
sept. 07, 2015 9:18:56 PM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
GRAVE: Error Rendering View[/module/config/index.xhtml]
javax.el.ELException: /module/config/index.xhtml @15,60 rendered="#{platformMB.firstedit == '0'}": Error reading 'firstedit' on type empsuite.managedbean.PlatformManagedBean
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:458)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1850)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:890)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:458)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:134)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.ELException: Error reading 'firstedit' on type empsuite.managedbean.PlatformManagedBean
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:101)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:167)
    at org.apache.el.parser.AstEqual.getValue(AstEqual.java:37)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    ... 37 more
Caused by: java.lang.NullPointerException
    at empsuite.managedbean.PlatformManagedBean.getPlatformList(PlatformManagedBean.java:133)
    at empsuite.managedbean.PlatformManagedBean.getFirstedit(PlatformManagedBean.java:69)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:97)
    ... 43 more

sept. 07, 2015 9:18:56 PM com.sun.faces.context.ExceptionHandlerImpl log
FATAL: JSF1073 : javax.el.ELException intercepté durant le traitement de RENDER_RESPONSE 6 : UIComponent-ClientId=, Message=/module/config/index.xhtml @15,60 rendered="#{platformMB.firstedit == '0'}": Error reading 'firstedit' on type empsuite.managedbean.PlatformManagedBean
sept. 07, 2015 9:18:56 PM com.sun.faces.context.ExceptionHandlerImpl log
FATAL: /module/config/index.xhtml @15,60 rendered="#{platformMB.firstedit == '0'}": Error reading 'firstedit' on type empsuite.managedbean.PlatformManagedBean
javax.el.ELException: /module/config/index.xhtml @15,60 rendered="#{platformMB.firstedit == '0'}": Error reading 'firstedit' on type empsuite.managedbean.PlatformManagedBean
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
    at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:458)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1850)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:890)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:458)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:134)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.ELException: Error reading 'firstedit' on type empsuite.managedbean.PlatformManagedBean
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:101)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
    at org.apache.el.parser.AstValue.getValue(AstValue.java:167)
    at org.apache.el.parser.AstEqual.getValue(AstEqual.java:37)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
    ... 37 more
Caused by: java.lang.NullPointerException
    at empsuite.managedbean.PlatformManagedBean.getPlatformList(PlatformManagedBean.java:133)
    at empsuite.managedbean.PlatformManagedBean.getFirstedit(PlatformManagedBean.java:69)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:97)
    ... 43 more

文件导致错误:

<h:form id="formConfig">
   <h:panelGroup rendered="#{platformMB.firstedit == '0'}">
           <p:messages id="messages" showSummary="false" showDetail="true" autoUpdate="true" closable="true" />
            <p:dataTable id="platform" var="platform" value="#{platformMB.platformList}" style="width: 90%" editable="true">  
                <p:ajax event="rowEdit" listener="#{platformMB.onEdit}" update=":formConfig:messages"/>
                <p:ajax event="rowEditCancel" listener="#{platformMB.onCancel}" update=":formConfig:messages"/>             

                <p:column headerText="Titre">
                    <f:facet name="Config">
                        <h:outputText value="TitreSite"/>
                    </f:facet>
                    <p:cellEditor>
                          <f:facet name="output">
                            <h:outputText value="#{platform.titresite}"/>
                        </f:facet>
                        <f:facet name="input">
                               <p:inputText  value="#{platform.titresite}" label="Titre">
                               <f:validateLength minimum="10" maximum="100"/>
                               </p:inputText>
                        </f:facet>             
                    </p:cellEditor>
                </p:column>
                <p:column headerText="Description">
                    <f:facet name="Config">
                        <h:outputText value="Description"/>
                    </f:facet>
                    <p:cellEditor>
                          <f:facet name="output">
                            <h:outputText value="#{platform.description}"/>
                        </f:facet>
                        <f:facet name="input">
                               <p:inputText value="#{platform.description}" label="Description">
                                <f:validateLength minimum="0" maximum="1000"/>
                               </p:inputText>
                        </f:facet>             
                    </p:cellEditor>
                </p:column>
                 <p:column headerText="Url">
                    <f:facet name="Config">
                        <h:outputText value="Url"/>
                    </f:facet>
                    <p:cellEditor>
                          <f:facet name="output">
                            <h:outputText value="#{platform.url}"/>
                        </f:facet>
                        <f:facet name="input">
                               <p:inputText value="#{platform.url}" label="Url">
                                 <f:validateLength minimum="0" maximum="45"/>
                               </p:inputText>
                        </f:facet>             
                    </p:cellEditor>
                </p:column>                
                                 <p:column headerText="Adresse">
                    <f:facet name="Config">
                        <h:outputText value="Adresse"/>
                    </f:facet>
                    <p:cellEditor>
                          <f:facet name="output">
                            <h:outputText value="#{platform.adress}"/>
                        </f:facet>
                        <f:facet name="input">
                               <p:inputText value="#{platform.adress}" label="Adresse">
                               <f:validateLength minimum="20" maximum="500"/>
                               </p:inputText>
                        </f:facet>             
                    </p:cellEditor>
                </p:column>     
                                 <p:column headerText="Phone">
                    <f:facet name="Config">
                        <h:outputText value="Phone"/>
                    </f:facet>
                    <p:cellEditor>
                          <f:facet name="output">
                            <h:outputText value="#{platform.phone}"/>
                        </f:facet>
                        <f:facet name="input">
                               <p:inputText value="#{platform.phone}" label="Télephone">
                               <f:validateLength minimum="8" maximum="11"/>
                               </p:inputText>
                        </f:facet>             
                    </p:cellEditor>
                </p:column>           
                                 <p:column headerText="E-mail Principal">
                    <f:facet name="Config">
                        <h:outputText value="E-mail Principal"/>
                    </f:facet>
                    <p:cellEditor>
                          <f:facet name="output">
                            <h:outputText value="#{platform.primarymail}"/>
                        </f:facet>
                        <f:facet name="input">
                               <p:inputText validatorMessage="E-mail : l'adresse e-mail saisie est incorrecte" value="#{platform.primarymail}" label="E-mail">
                               <f:validateRegex pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
                               </p:inputText>
                        </f:facet>             
                    </p:cellEditor>
                </p:column>     
                <p:column style="width:20%">
                <f:facet name="Config">Mise à jour</f:facet>
                <p:rowEditor/>
            </p:column>       

            </p:dataTable>


        </h:panelGroup>
        <h:panelGroup rendered="#{platformMB.firstedit == '1'}">

        <table>
            <tr>
                <td><h:outputLabel for="titresite" value="Titre de l'institution : "/></td>
                <td><p:inputText id="titresite" value="#{platformMB.titresite}">
                    <f:validateLength minimum="10" maximum="100"/>
                    <p:ajax event="blur" update="titresiteMsg"/>
                </p:inputText>
                    <p:message id="titresiteMsg" for="titresite" display="icon"/>
                </td>
            </tr>
            <tr>
                <td><h:outputLabel for="description" value="Description de l'institution : "/></td>
                <td><p:inputText id="description" value="#{platformMB.description}">
                    <f:validateLength minimum="0" maximum="1000"/>
                    <p:ajax event="blur" update="descriptionMsg"/>
                </p:inputText>
                    <p:message id="descriptionMsg" for="description" display="icon"/>
                </td>
            </tr>
                        <tr>
                <td><h:outputLabel for="url" value="Adresse du site Web d'accueil : "/></td>
                <td><p:inputText id="url" value="#{platformMB.url}">
                    <f:validateLength minimum="0" maximum="45"/>
                    <p:ajax event="blur" update="urlMsg"/>
                </p:inputText>
                    <p:message id="urlMsg" for="url" display="icon"/>
                </td>
            </tr>
                              <tr>
                <td><h:outputLabel for="adress" value="Adresse de l'institution : "/></td>
                <td><p:inputText id="adress" value="#{platformMB.adress}">
                    <f:validateLength minimum="20" maximum="500"/>
                    <p:ajax event="blur" update="adressMsg"/>
                </p:inputText>
                    <p:message id="adressMsg" for="adress" display="icon"/>
                </td>
            </tr>
                                          <tr>
                <td><h:outputLabel for="phone" value="Téléphone de l'institution : "/></td>
                <td><p:inputText id="phone" value="#{platformMB.phone}">
                    <f:validateLength minimum="8" maximum="11"/>
                    <f:converter converterId="javax.faces.Integer"/>
                    <p:ajax event="blur" update="phoneMsg"/>
                </p:inputText>
                    <p:message id="phoneMsg" for="phone" display="icon"/>
                </td>
            </tr>
                                                      <tr>
                <td><h:outputLabel for="primarymail" value="E-mail principal de l'institution : "/></td>
                <td><p:inputText id="primarymail" value="#{platformMB.primarymail}">
                    <f:validateRegex pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$" />
                    <p:ajax event="blur" update="primarymailMsg"/>
                </p:inputText>
                    <p:message id="primarymailMsg" for="primarymail" display="icon"/>
                </td>
            </tr>
            <tr>
                <td><p:commandButton id="addPlatform" value="Sauvegarder" action="#{platformMB.addPlatform}" ajax="false"/></td>
                <td><p:commandButton id="reset" value="Reset" action="#{platformMB.reset}" ajax="false"/></td>
            </tr>
        </table>

            </h:panelGroup>
        </h:form>

和DAO:

package empsuite.managedbean;

@ManagedBean(name="platformMB")
@ApplicationScoped
public class PlatformManagedBean implements Serializable{

    private static final long serialVersionUID = 1L;
    private static final String SUCCESS = "";
    private static final String ERROR   = "";

    @ManagedProperty(value="#{PlatformService}")
    PlatformService platformService;
    List<Platform> platformList;
    String titresite;
    String description;
    String url;
    String adress;
    int phone;
    String primarymail;
    int id;

    int firstedit;


    public int getFirstedit() { 
         if(getPlatformList().isEmpty()){
             return 1; 
        // Donc on affiche le formulaire d'ajout 
        }
        else  {return 0;
        // Sinon lecture et modification sans ajout
        }
            }
    public void setFirstedit(int firstedit) {this.firstedit = firstedit;    }



    public List<Platform> getPlatformList() {
        if(platformList == null){
            platformList = new ArrayList<Platform>();
            platformList.addAll(getPlatformService().getPlatform());
        }
        return platformList;
    }

    public void setPlatformList(List<Platform> platformList) {
        this.platformList = platformList;
    }

}

正如我所说的那样,它工作正常,直到我添加了对这个网络应用程序的身份验证,但没有任何与此文件相关的内容,没有添加任何授权,没有触及这一点的任何内容。

注意:当我强制浏览器访问该页面时,似乎firstedit获取值1并显示Add Platform panelGrid,就像Platform表没有数据一样(逻辑是这样的如果firstedit为1(表格为空),则显示添加表单并将其设置为0,如果表格中有1个条目,则显示编辑表单

编辑 HQL甚至没有执行,就像它在执行HQL之前读取int并知道该int是否应该计算0或1,这指向null。但为什么呢?

编辑2 当我删除rendered="#{platformMB.firstedit == '0'}"时,带有空指针的platformList会出错吗?

1 个答案:

答案 0 :(得分:1)

您致电getPlatformService().getPlatform(),但您的getPlatformService()会回复null。检查platformService与初始化相关的代码/配置。