0

I am using PrimeFaces 3.5, JSF 2.0.

I have got some problem while navigating to the page using p:commandButton, I have login page when clicked login button after entering credentials it does not navigate to respective page instead it returns on the same page.

Any help will be really appreciated :-)

Here is my code,

Login.xhtml

<ui:composition ….

 <p:panel>
   <p:outputLabel value="#{res.Username}" />
   <p:inputText id="username" value="#{loginController.username}" />
   
   <p:outputLabel value="#{res.Password}" />
   <p:password id="password" value="#{loginController.password}" />
   
   <p:commandButton id="login"
    action="#{loginController.validateUsernamePassword}"
    value="#{res.Login}" update=":mainPanel:gs_MainPanel"/>
 </p:panel>

</ui:composition>

Home.xhtml

<html  …

    <ui:composition template="/content/main.xhtml">

        <ui:define name="header">
            <ui:include src="/content/header.xhtml"/>
        </ui:define>

        <ui:define name="menu">
            <ui:include src="/content/menu.xhtml"/>
        </ui:define>

        <ui:define name="mainPanel">       
                <p:panel id="gs_MainPanel" header="#{menuBean.current.screenHeader}" >
                 <p:messages severity="error" showDetail="true" showSummary="false" autoUpdate="true" closable="true"/>
                    <ui:include src="#{menuBean.current.screenName}"/>
                </p:panel>
        </ui:define>

    </ui:composition>
</html>

main.xhtml

<html …

    <h:head>
   
    </h:head>

    <h:body>
     
        <p:growl id="globalMessages" severity="info, warn" showDetail="true" showSummary="false" />
        
        <p:dialog modal="true" width="250" widgetVar="statusDialog" header="Loading..."  draggable="false" closable="false">  
       <p:graphicImage library="images" name="ajax-loader.gif" />  
 </p:dialog>

        <p:layout fullPage="true">  

            <p:layoutUnit position="north" size="58" gutter="0" > 
                <h:form id="headerForm">
                    <ui:insert name="header"></ui:insert>
                </h:form>
            </p:layoutUnit>    

            <p:layoutUnit size="210" position="west" gutter="0" header="#{res.menu_config_header}" resizable="true"  collapsible="true">   
                <h:form id="leftNavigationForm">       
                    <ui:insert name="menu"></ui:insert>
                </h:form>    
            </p:layoutUnit>  

            <p:layoutUnit  position="center" gutter="0" resizable="true"> 
                <h:form id="mainPanel" >
                    <ui:insert name="mainPanel"/>
                </h:form> 
            </p:layoutUnit>  

        </p:layout> 

    </h:body> 

</html>

menu.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:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <ui:composition>
     <p:menu style="width:200px;"> 
     <p:submenu label="#{res.menuDropDown_AuctionSystem}" styleClass="gs_menuitem_header">                         
                    <p:menuitem id="login" styleClass="gs_menuitem_text" value="#{res['SignIn']}" 
                       actionListener="#{homeController.viewLoginPage()}" update=":mainPanel:gs_MainPanel"/>
                    
                </p:submenu>
     </p:menu>      
    </ui:composition>
</html>

MenuBean.java

This is my session scoped managed bean

public class MenuBean implements Serializable{
private static final long serialVersionUID = 1L;

private MenuSelectionEnum current;

public MenuBean() {
    current = MenuSelectionEnum.home;
}

public MenuSelectionEnum getCurrent() {
    return current;
}

public void setCurrent(MenuSelectionEnum current) {
    this.current = current;
}

}

MenuSelectionEnum.java

public enum MenuSelectionEnum implements Serializable {
home("Home_Title", "homeRightPanel"),login("Login_Title", "login"),register("Register_Title", "registerUser");

public static final String PREFIX = "/content/";

public static final String SUFFIX = ".xhtml";

private String screenHeader;

private String screenName;

private MenuSelectionEnum(String screenHeader, String screenName){
    this.screenHeader = screenHeader;
    this.screenName = PREFIX + screenName + SUFFIX;
}

public String getScreenHeader(){
    return JSFUtility.getLocalMessageValue(screenHeader);
}

public void setScreenHeader(String screenHeader){
    this.screenHeader = screenHeader;
}

public String getScreenName(){
    return screenName;
}

public void setScreenName(String screenName){
    this.screenName = screenName;
}

}

web.xml

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

<context-param>
    <param-name>primefaces.THEME</param-name>
    <param-value>bootstrap</param-value>
</context-param>

<context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
</context-param>

<context-param>
    <param-name>javax.faces.FULL_STATE_SAVING_VIEW_IDS</param-name>
    <param-value>faces/home.xhtml</param-value>
</context-param>


<!-- Welcome page -->
<welcome-file-list>
    <welcome-file>faces/home.xhtml</welcome-file>
</welcome-file-list>

<!-- JSF mapping -->
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<!-- Map these files with JSF -->
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

<!-- Session time out -->
<session-config>
    <session-timeout>30</session-timeout>
</session-config>

<!-- Error Page -->
<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/viewexpired.xhtml</location>
</error-page>

<!-- Spring Security Config -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/webApplication-context.xml</param-value>
</context-param>

<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/log4j.xml</param-value>
</context-param>

<!-- <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
    </filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> </filter-mapping> -->

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

0 Answers0