0

I'm currently dealing with a problem on a project I'm using Spring MVC with Facelets view technology.In my master template I'm currently having a menu and whenever I click a link from that menu my intent is to include another page in the current one. I followed this link How to ajax-refresh dynamic include content by navigation menu? (JSF SPA) ,but it didn't resolve my problem. As in the example, I included a page by default,which initially loads and everything seems ok but when I click on one of the links, I get a null pointer exception.

I would like to say that I read many posts where user @BalusC answered,but I still found no solution.Now I'm stuck in this part of the project and I feel it's almost impossible to continue.

The menu xhtml file is the following one:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

<h:panelGroup layout="block" id="menu-outer">
    <h:panelGroup layout="block" class="table">
        <h:form>
            <f:ajax render=":content">
                <ul id="mainNav">

                    <li>
                        <h:commandLink id="toRegister" value= "Register page" action="#{bean.setPage('registerPage')}" />   
                    </li>

                    <li>
                        <h:commandLink id="toDepartment" value= "Departments" action="#{bean.setPage('departmentPage')}"/> 
                    </li>

                    <li>
                        <h:commandLink id="toHealthcarePlan" value= "Healthcare plans" action="#{bean.setPage('healthPage')}" />    
                    </li>

                    <li>
                        <h:commandLink id="toContacts" value= "Contacts" action="#{bean.setPage('contactsPage')}" /> 
                    </li>
                </ul>
            </f:ajax>
        </h:form>
    </h:panelGroup>
</h:panelGroup>

<h:panelGroup id="content" layout="block">
    <ui:include src="/WEB-INF/view/#{bean.page}.xhtml" />
</h:panelGroup>


</ui:composition> 

The bean is the following one:

@ManagedBean
@ViewScoped
public class Bean implements Serializable{

    private String page;

    @PostConstruct
    public void init(){

        page="registerPage";
    }

    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }

}

The webapp directory is the following one(I wrote it by hand,hope I didn't miss anything).

webapp

 |-- META-INF

 |-- WEB-INF

 |    |-- view

 |    |    -- template

 |    |           |-- template.xhtml


 |    |           |-- menu.xhtml

 |    |    -- registerPage.xthml

 |    |    -- departmentPage.xthml

 |    |    -- healthPage.xthml

 |    |    -- contactsPage.xthml

 |    |-- app-servlet.xml

 |    |-- faces-config.xml  

 |    |-- web.xml   
 |               
 |-- home.xhtml

The exception is the following one:

Dec 29, 2015 11:09:18 PM com.sun.faces.context.PartialViewContextImpl processPartial
INFO: java.lang.NullPointerException
java.lang.NullPointerException
    at javax.faces.component.UIComponentBase.getRenderer(UIComponentBase.java:1402)
    at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:785)
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1181)
    at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:507)
    at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1612)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
    at javax.faces.component.UIForm.visitTree(UIForm.java:371)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623)
    at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:377)
    at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252)
    at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:931)
    at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:696)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:521)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:138)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:564)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:213)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1097)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:448)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1031)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:200)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:446)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:271)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:246)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
    at java.lang.Thread.run(Thread.java:745)
Community
  • 1
  • 1
  • I'm sorry but I don't understand what are you reffering to through "the involvement of Spring MVC" ? Honestly, I've been confused lately. Initially, I wanted to use Spring MVC + Hibernate +JSF. Then I read that JSF can't be counted as the View part of the Spring MVC and a possibility is using the Spring MVC + Facelets as the View part(This is what I intend to do). Now I realized that I completly messed up and my deadline project is approaching. Should I go back to jsp and give up trying to use Facelets? – Mihai Serban Dec 29 '15 at 23:07
  • I forgot to mention that this is the first time I'm using Spring.I read in this post http://stackoverflow.com/questions/18744910/using-jsf-as-view-technology-of-spring-mvc that JSP is deprecated and has been replaced by Facelets and I thought it would be nice to learn it,but honestly,I messed up.Thank you for your answer! – Mihai Serban Dec 29 '15 at 23:26
  • One more thing I'd like to ask.On the post I mentioned earlier an example of a small project is given https://github.com/acichon89/springmvcfacelets. Can we consider that Spring MVC and JSF run next to each other in this example?If yes, from what point of view?(probably this totally confuses me).I'm a bit confused by looking at the web.xml of that project. – Mihai Serban Dec 29 '15 at 23:56
  • Add the h:form under ui:composition and let the form contain everything and please post your imports of viewscoped and managedbean – Mahendran Ayyarsamy Kandiar Dec 30 '15 at 00:08
  • @MahendranAyyarsamyKandiar I'm afraid I just did what Tiny reffered to.I mixed Spring MVC with JSF. I have controller classes which receive the requests and this I wanted to mix with Facelets,but I failed.I will just reconsider the design. – Mihai Serban Dec 30 '15 at 00:27
  • With Spring MVC+Facelets, there are too many constraints which are confusing to a starter. Among others, you can't use JSF's ``, `` and `` to invoke Spring controller methods. And, you can't use Spring MVC's `` to invoke JSF controller methods. Right now you're essentially only using JSF and not using Spring MVC at all. Just uninstall/remove it to eliminate the major source of confusion. In Spring MVC+Facelets you'd best constrain yourself to solely using Facelets `` and Spring MVC `` tags. – BalusC Dec 30 '15 at 09:51
  • @BalusC Thank you for your answer! It slowly becomes clearer.My intent was to use Spring MVC and use Spring controller methods to handle requests(which I'm actually doing now).My confusion started when I read your post http://stackoverflow.com/questions/18744910/using-jsf-as-view-technology-of-spring-mvc and I decided to give up JSP and go for Spring MVC +Facelets.It is somehow strange because what I tried to do,include one of the pages,when I click a link(a default page was loaded) has somehow no connection to the requests made to the controller. – Mihai Serban Dec 30 '15 at 10:58
  • Choose either Java EE or Spring, not both. – BalusC Dec 30 '15 at 10:59
  • Till now I used the controller just to handle requests which will operate on the database(receive and send data). – Mihai Serban Dec 30 '15 at 10:59

0 Answers0