I'm new to JSF and Primefaces and have just started working on logging in and basic navigation and I have run into a problem already. I've gone through about 10 similar questions here on SO and none of the solutions has worked for me yet so I figured I would post up my specific problem so that someone who really knows can point me in the right direction.
Logging in: seems to work just fine as does logging out but I'm concerned because the url in the browser still says that I'm at the login screen after logging in and I used the login example straight from the Oracle EE6 docs. Login method is provided below.
public String login(){ FacesContext context = FacesContext.getCurrentInstance(); HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest(); try{ logger.log(Level.FINE, "User credentials: name: {0}, password: {1}", new Object[] {this.username, this.password}); request.login(this.username, encrypt(this.password)); logger.log(Level.FINE, "User: {0} logged in", this.username); }catch(ServletException e){ logger.log(Level.SEVERE, "User: {0} login failed, password: {1}", new Object[]{this.username, encrypt(this.password)}); context.addMessage(null, new FacesMessage("Login Failed!")); return "error"; } return "/faces/system/index";
}
After logging in I'm taken to the correct page in the correct directory and everything is being displayed corectly but when you hover over the links the status bar at the bottom of the browser displays the same url for all three links. Code for the page provided below.
<h:body> <p:layout fullPage="true"> <f:facet name="last"> <h:outputStylesheet library="css" name="discovery.css"></h:outputStylesheet> </f:facet> <p:layoutUnit styleClass="headerDiv" position="north" size="100"> <h:graphicImage library="images" name="header.jpg"></h:graphicImage> </p:layoutUnit> <p:layoutUnit styleClass="navDiv" position="west" size="200" id="navPanel"> <h:form> <h:outputText value="Navigation Menu"></h:outputText> <br/> <p:commandLink value="First Time Users" update=":main"> <f:setPropertyActionListener target="#{navigationBean.pageToDisplay}" value="tutorial.xhtml"></f:setPropertyActionListener> </p:commandLink> <br/> <p:commandLink value="Help" update=":main"> <f:setPropertyActionListener target="#{navigationBean.pageToDisplay}" value="help.xhtml"></f:setPropertyActionListener> </p:commandLink> <br/> <h:commandLink action="#{loginBean.logout()}" value="Log Out"></h:commandLink> </h:form> </p:layoutUnit> <p:layoutUnit position="center" id="main"> <ui:include src="#{navigationBean.pageToDisplay}"></ui:include> </p:layoutUnit> </p:layout> </h:body>
The NavigationBean
@Named(value = "navigationBean") @RequestScoped public class NavigationBean implements Serializable {
public NavigationBean() { }
public String getPageToDisplay() { return pageToDisplay; }
public void setPageToDisplay(String pageToDisplay) { this.pageToDisplay = pageToDisplay; }
private String pageToDisplay = "welcome.xhtml"; }
When the page loads after logging in the default page set in the navigation bean is displayed but clicking on any link other than the log out link causes the default page to disappear from the center layout unit and a blank page is displayed/ Clicking on the log out link does log you out like intended though. ANy help would be greatly appreciated.