hello,
I am new to ui development, and I am in need of your help with the below task:
I purchased adamantium themes and I am trying to implement login functionality from login.xhtml to dashboard.xhtml.
So, I changed <p:button> type to <p:commandButton> to enable action property, so that I can navigate to dashboard.xhtml.
I am trying to call loginBean.validate() method, which currently returns a static string "valid".
using this outcome, I am mapping the navigation from login.xhtml to dashboard.xhtml in faces-config file.
After deploying the application, when I click on Submit command button in login page, nothing happens, the click event is not even reaching loginBean.
Can some one please help me fix this issue.
thanks.
<p:commandButton> action not working
-
- Posts: 5281
- Joined: 29 Jun 2013, 12:38
Please try with <p:commandButton process="@this" ..>.
This is not a Layout or theme issue. it is a Primefaces issue.
This is not a Layout or theme issue. it is a Primefaces issue.
Github Profile: https://github.com/mertsincan
Hi I have the same issue.
Command Button appears to do nothing in my case. I have added both my xhtml and backing bean code here could you please tell me what I am doing wrong here.
<ui:composition 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"
template="/WEB-INF/template.xhtml">
<ui:define name="content">
<div class="Container100 Responsive NoIndent" >
<div class="Card TexAlCenter">
<h1 class="BigTopic">Sign Up</h1>
<span class="gray">Try now, its free.</span>
</div>
</div>
<div class="Wid70 MarAuto">
<div class="Wid70 MarAuto WidAutoOnMobile TexAlCenter">
<div class="Wid70 MarAuto WidAutoOnMobile">
<div class="EmptyBox30"></div>
<div class="EmptyBox10 ShowOnMobile"></div>
<div class="EmptyBox50 ShowOnDesktop"></div>
<div class="EmptyBox20 ShowOnMobile"></div>
<div class="Card ui-fluid ShadowEffect">
<div class="Container50">
<p:panelGrid columns="2">
<p:inputText placeholder="First Name" id="firstname" style="padding:15px !important;" value="#{newMember.firstname}"/>
<p:message for="firstname" errorClass="invalid" />
</p:panelGrid>
</div>
<div class="Container50">
<p:panelGrid columns="2">
<p:inputText placeholder="Last Name" id="lastname" style="padding:15px !important;" value="#{newMember.lastname}"/>
<p:message for="lastname" errorClass="invalid" />
</p:panelGrid>
</div>
<div class="Container100">
<p:panelGrid columns="2">
<p:inputText placeholder="Email" id="email" style="padding:15px !important;" value="#{newMember.email}"/>
<p:message for="email" errorClass="invalid" />
</p:panelGrid>
</div>
<div class="Container100">
<p:panelGrid columns="2">
<p:inputText placeholder="Mobile Phone" id="mobilephoneNumber" style="padding:15px !important;" value="#{newMember.mobilephonenumber}"/>
<p:message for="mobilephoneNumber" errorClass="invalid" />
</p:panelGrid>
</div>
<div class="Container100">
<p:panelGrid columns="2">
<p:password id="password" value="#{newMember.password}" match="confirm" placeholder="Password" required="true" style="padding:15px !important;" />
<p:message for="password" errorClass="invalid" />
</p:panelGrid>
</div>
<div class="Container100">
<p:panelGrid columns="2">
<p:password id="confirm" value="#{newMember.password}" placeholder="Confirm Password" required="true" style="padding:15px !important;" />
<p:message for="confirm" errorClass="invalid" />
</p:panelGrid>
</div>
<div class="EmptyBox20"></div>
<div class="Container100">
<p:commandButton type="button" id="register" action="#{memberController.register()}" process="@this" ajax="false" value="Create an Account" styleClass="GreenButton"/>
</div>
<div class="Container100">
<h:messages styleClass="messages" errorClass="invalid" infoClass="valid" warnClass="warning" globalOnly="true" />
</div>
<div class="EmptyBox10"></div>
<div class="Separator"></div>
<div class="EmptyBox10"></div>
</div>
</div>
</div>
</div>
</ui:define>
</ui:composition>
==================Backing Bean========================
package dbteam.com.jsf.starter.controller;
import javax.annotation.PostConstruct;
import javax.enterprise.inject.Model;
import javax.faces.bean.ManagedBean;
import javax.enterprise.inject.Produces;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.inject.Inject;
import javax.inject.Named;
import dbteam.com.jsf.starter.model.Member;
import dbteam.com.jsf.starter.service.MemberRegistration;
// The @Model stereotype is a convenience mechanism to make this a request-scoped bean that has an
// EL name
// Read more about the @Model stereotype in this FAQ:
// http://sfwk.org/Documentation/WhatIsThe ... Annotation
@ManagedBean
//@Model
public class MemberController {
@Inject
private FacesContext facesContext;
@Inject
private MemberRegistration memberRegistration;
@Produces
@Named
private Member newMember;
@PostConstruct
public void initNewMember() {
newMember = new Member();
}
public void register() throws Exception {
try {
memberRegistration.register(newMember);
FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_INFO, "Registered!", "Registration successful");
facesContext.addMessage(null, m);
initNewMember();
} catch (Exception e) {
String errorMessage = getRootErrorMessage(e);
FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, "Registration unsuccessful");
facesContext.addMessage(null, m);
}
}
private String getRootErrorMessage(Exception e) {
// Default to general error message that registration failed.
String errorMessage = "Registration failed. See server log for more information";
if (e == null) {
// This shouldn't happen, but return the default messages
return errorMessage;
}
// Start with the exception and recurse to find the root cause
Throwable t = e;
while (t != null) {
// Get the message from the Throwable class instance
errorMessage = t.getLocalizedMessage();
t = t.getCause();
}
// This is the root cause message
return errorMessage;
}
}
Command Button appears to do nothing in my case. I have added both my xhtml and backing bean code here could you please tell me what I am doing wrong here.
<ui:composition 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"
template="/WEB-INF/template.xhtml">
<ui:define name="content">
<div class="Container100 Responsive NoIndent" >
<div class="Card TexAlCenter">
<h1 class="BigTopic">Sign Up</h1>
<span class="gray">Try now, its free.</span>
</div>
</div>
<div class="Wid70 MarAuto">
<div class="Wid70 MarAuto WidAutoOnMobile TexAlCenter">
<div class="Wid70 MarAuto WidAutoOnMobile">
<div class="EmptyBox30"></div>
<div class="EmptyBox10 ShowOnMobile"></div>
<div class="EmptyBox50 ShowOnDesktop"></div>
<div class="EmptyBox20 ShowOnMobile"></div>
<div class="Card ui-fluid ShadowEffect">
<div class="Container50">
<p:panelGrid columns="2">
<p:inputText placeholder="First Name" id="firstname" style="padding:15px !important;" value="#{newMember.firstname}"/>
<p:message for="firstname" errorClass="invalid" />
</p:panelGrid>
</div>
<div class="Container50">
<p:panelGrid columns="2">
<p:inputText placeholder="Last Name" id="lastname" style="padding:15px !important;" value="#{newMember.lastname}"/>
<p:message for="lastname" errorClass="invalid" />
</p:panelGrid>
</div>
<div class="Container100">
<p:panelGrid columns="2">
<p:inputText placeholder="Email" id="email" style="padding:15px !important;" value="#{newMember.email}"/>
<p:message for="email" errorClass="invalid" />
</p:panelGrid>
</div>
<div class="Container100">
<p:panelGrid columns="2">
<p:inputText placeholder="Mobile Phone" id="mobilephoneNumber" style="padding:15px !important;" value="#{newMember.mobilephonenumber}"/>
<p:message for="mobilephoneNumber" errorClass="invalid" />
</p:panelGrid>
</div>
<div class="Container100">
<p:panelGrid columns="2">
<p:password id="password" value="#{newMember.password}" match="confirm" placeholder="Password" required="true" style="padding:15px !important;" />
<p:message for="password" errorClass="invalid" />
</p:panelGrid>
</div>
<div class="Container100">
<p:panelGrid columns="2">
<p:password id="confirm" value="#{newMember.password}" placeholder="Confirm Password" required="true" style="padding:15px !important;" />
<p:message for="confirm" errorClass="invalid" />
</p:panelGrid>
</div>
<div class="EmptyBox20"></div>
<div class="Container100">
<p:commandButton type="button" id="register" action="#{memberController.register()}" process="@this" ajax="false" value="Create an Account" styleClass="GreenButton"/>
</div>
<div class="Container100">
<h:messages styleClass="messages" errorClass="invalid" infoClass="valid" warnClass="warning" globalOnly="true" />
</div>
<div class="EmptyBox10"></div>
<div class="Separator"></div>
<div class="EmptyBox10"></div>
</div>
</div>
</div>
</div>
</ui:define>
</ui:composition>
==================Backing Bean========================
package dbteam.com.jsf.starter.controller;
import javax.annotation.PostConstruct;
import javax.enterprise.inject.Model;
import javax.faces.bean.ManagedBean;
import javax.enterprise.inject.Produces;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.inject.Inject;
import javax.inject.Named;
import dbteam.com.jsf.starter.model.Member;
import dbteam.com.jsf.starter.service.MemberRegistration;
// The @Model stereotype is a convenience mechanism to make this a request-scoped bean that has an
// EL name
// Read more about the @Model stereotype in this FAQ:
// http://sfwk.org/Documentation/WhatIsThe ... Annotation
@ManagedBean
//@Model
public class MemberController {
@Inject
private FacesContext facesContext;
@Inject
private MemberRegistration memberRegistration;
@Produces
@Named
private Member newMember;
@PostConstruct
public void initNewMember() {
newMember = new Member();
}
public void register() throws Exception {
try {
memberRegistration.register(newMember);
FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_INFO, "Registered!", "Registration successful");
facesContext.addMessage(null, m);
initNewMember();
} catch (Exception e) {
String errorMessage = getRootErrorMessage(e);
FacesMessage m = new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, "Registration unsuccessful");
facesContext.addMessage(null, m);
}
}
private String getRootErrorMessage(Exception e) {
// Default to general error message that registration failed.
String errorMessage = "Registration failed. See server log for more information";
if (e == null) {
// This shouldn't happen, but return the default messages
return errorMessage;
}
// Start with the exception and recurse to find the root cause
Throwable t = e;
while (t != null) {
// Get the message from the Throwable class instance
errorMessage = t.getLocalizedMessage();
t = t.getCause();
}
// This is the root cause message
return errorMessage;
}
}
-
- Posts: 5281
- Joined: 29 Jun 2013, 12:38
Please replace ManagedBean with @Named and remove import javax.faces.bean.ManagedBean.
Code: Select all
@Named("memberController")
public class MemberController {
....
}
Github Profile: https://github.com/mertsincan
-
- Posts: 5281
- Joined: 29 Jun 2013, 12:38
I think this isn't a Layout issue or Theme issue. If you try it without Adamantium, I think you'll replicate this issue.
Github Profile: https://github.com/mertsincan
-
- Information
-
Who is online
Users browsing this forum: No registered users and 20 guests