I've got a p:commandButton in a simple login form. The action is not firing. I've verified that the controller and function exist, checked for nested f:forms, enclosed everything in f:view, removed validation requirements, but the action doesn't fire.
The action listener just sets the login flag and then the page refreshes with new rendering. If I reference the listener function directly, it fires, but not from the commandButton.
Here's the controller bean:
@ManagedBean(name = "uiController")
@SessionScoped
public class UiController implements Serializable {
private Boolean isLoggedIn;
private String userName;
private String password;
public UiController() {
isLoggedIn = false;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Boolean getIsLoggedIn() {
return isLoggedIn;
}
public String getLoginLogoTopLine() {
return "Yoyodyne";
}
public String getLoginLogoBottomLine() {
return "Corporation";
}
public void login() {
isLoggedIn = true;
}
}
Here's the html:
<h:head>
<h:outputStylesheet library="css" name="jsfcrud.css"/>
<h:outputStylesheet library="css" name="transend-ui.css"/>
<h:outputScript library="js" name="jsfcrud.js"/>
</h:head>
<h:body id="enchilada">
<f:view>
<p:growl id="growl" life="3000" />
<h:panelGroup id="loginContainer" styleClass="ts-page-container ts-login-container" rendered="#{!uiController.isLoggedIn}">
<h:panelGroup styleClass="ts-northwest-container">
<h:outputText value="#{uiController.loginLogoTopLine}" styleClass="ts-login-logo-top" />
<h:outputText value="#{uiController.loginLogoBottomLine}" styleClass="ts-login-logo-bottom" />
</h:panelGroup>
<h:panelGroup styleClass="ts-centered-container">
<h:form id="LoginForm">
<h:inputHidden value="#{shipperCode}" />
<p:panelGrid styleClass="ts-login-panel">
<p:row>
<p:column styleClass="">
<p:panelGrid styleClass="">
<p:row>
<p:column>
<p:outputLabel styleClass="ts-login-prompt" value="#{bundle.LoginLabel_userName}" for="userName" />
</p:column>
<p:column>
<p:inputText value="#{uiController.userName}" id="userName" title="#{bundle.LoginTitle_userName}"/>
</p:column>
</p:row>
<p:row>
<p:column>
<p:outputLabel styleClass="ts-login-prompt" value="#{bundle.LoginLabel_password}" for="password" />
</p:column>
<p:column>
<p:inputText value="#{uiController.password}" id="password" title="#{bundle.LoginTitle_password}"/>
</p:column>
</p:row>
</p:panelGrid>
</p:column>
<p:column>
<p:commandButton action="#{uiController.login}" value="login" oncomplete="window.location.replace(window.location.href);"/>
</p:column>
</p:row>
</p:panelGrid>
</h:form>
<h:messages />
</h:panelGroup>
</h:panelGroup>
<h:panelGroup id="mainContainer" styleClass="ts-page-container ts-main-container" rendered="#{uiController.isLoggedIn}">
</h:panelGroup>
</f:view>
</h:body>
UPDATE
OK sorry for posting snippets in the comments. I usually work things out for myself. This is the first time I've had to ask for help and I'm not familiar with posting. Not a newb at Java, definitely a newb at this.
Here's what I now have for html:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body id="enchilada">
<f:view>
<h:form id="LoginForm">
<p:commandButton action="#{uiController.login}" value="login"/>
</h:form>
</f:view>
</h:body>
</html>
Here's the bean:
@ManagedBean(name = "uiController")
@SessionScoped
public class UiController implements Serializable {
public void login() {
System.out.println("login invoked");
}
}
There may be a problem with your namespace declarations. You have used:
Replace the above with:
To be honest, I'm not familiar with how these namespace declarations work, so I don't know if or why this would make a difference. I would have put this in a comment, but it's too long.