I am building a web application using the technologies mentioned in the post header. I have searched similar threads, but none of them provided an answer to my problem. I have configured my Maven project, the pom file is correct, JSF and PrimeFaces are working, but I encounter a problem when I do the following:
I copied the Client Side Validation example from the Prime Faces Showcase website, and on my end, it isn't working as expected.
When validation fails for a field, an error appears to the right of the field, and as long as it's there, I cannot update the field. When I try to type something, nothing happens on the screen, but if I highlight the text in the field, I can see it there.
Here's my registration.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<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">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
Hello from Facelets
<h2>Registration Form</h2>
<h:form id="form">
<p:panel id="panel" header="Form" style="margin-bottom:10px;">
<p:fieldset legend="Registration Form" widgetVar="regWidget" style="width: 600px;">
<h:panelGrid columns="3" width="550" border="0">
<h:outputLabel value="UserName" />
<p:inputText value="#{regCont.prospect.userName}"
id="userName"
required="true"
requiredMessage="UserName is required"
validatorMessage="UserName should be of length from 5 to 15 chars"
>
<f:validateLength minimum="5" maximum="15" for="userName"></f:validateLength>
</p:inputText>
<p:message for="userName"/>
<h:outputLabel value="Password" />
<p:password value="#{regCont.password}"
id="password"
required="true"
requiredMessage="Password is required"
validatorMessage="Password should be of length from 5 to 15 chars"
>
<f:validateRegex pattern="^(?=^.{8,12}$)(?!.*(.)\1{3,})(?=.*[A-Z])(?=.*[a-z]{3,})(?=.*[^a-zA-Z0-9]{2,})(?=.*[0-9]{2,})[a-zA-Z]"/>
</p:password>
<p:message for="password" />
<h:outputLabel value="FirstName" />
<p:inputText value="#{regCont.prospect.firstName}"
id="firstName"
required="true"
requiredMessage="FirstName is required"
validatorMessage="FirstName should be of length from 5 to 15 chars"
>
<f:validateLength minimum="1" maximum="45" for="firstName"></f:validateLength>
</p:inputText>
<p:message for="firstName" display="tooltip" />
<h:outputLabel value="LastName" />
<p:inputText value="#{regCont.prospect.lastName}"
id="lastName"></p:inputText>
<p:message for="lastName" display="tooltip"/>
<h:outputLabel value="Email" />
<p:inputText value="#{regCont.prospect.email}"
id="email"
validatorMessage="Invalid Email">
<f:validateRegex pattern="[a-zA-Z0-9]+#[a-zA-Z]+.[a-zA-Z]{2,3}"></f:validateRegex>
</p:inputText>
<p:message for="email" />
<h:outputLabel value="Nation" />
<p:inputText value="#{regCont.prospect.nation}"
id="nation">
</p:inputText>
<p:message for="nation" />
<h3 style="margin-top:0">User type</h3>
<h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
<p:outputLabel for="type" value="User type:" />
<p:selectOneRadio id="type" value="#{regCont.prospect.userType}">
<f:selectItem itemLabel="Delegate" itemValue="Delegate" />
<f:selectItem itemLabel="Leader" itemValue="Leader" />
</p:selectOneRadio>
</h:panelGrid>
<p:commandButton value="Register" update="panel" icon="ui-icon-check" validateClient="true" style="margin-right:10px"/>
<h:commandButton value="Reset p:ajax" style="margin-right:20px;" >
<p:ajax update="panel" resetValues="true" />
</h:commandButton>
</h:panelGrid>
</p:fieldset>
</p:panel>
</h:form>
</h:body>
</html>
And here's my RegistrationController class:
#ManagedBean(name = "regCont")
#RequestScoped
public class RegistrationController implements Controller {
#ManagedProperty(value = "#{prospect}")
private Prospect prospect;
#ManagedProperty(value = "#{user}")
private User user;
private String msg;
private String password;
public void hashPassword() throws NoSuchAlgorithmException {
byte[] salt = Passwords.getNextSalt();
prospect.setSalt(salt);
prospect.setPasswordHash(Passwords.getHashWithSalt(password, salt));
password = "";
}
public Prospect getProspect() {
return prospect;
}
public void setProspect(Prospect prospect) {
this.prospect = prospect;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
private void clearAll() {
user.setFirstName("");
user.setLastName("");
user.setNation("");
user.setEmail("");
user.setUserName("");
user.setPasswordHash(null);
prospect.setFirstName("");
prospect.setLastName("");
prospect.setNation("");
prospect.setEmail("");
prospect.setUserType("");
prospect.setUserName("");
prospect.setPasswordHash(null);
}
public void saveUser() {
UserDAO dao = new UserDAO();
dao.createEntity(user);
this.msg = "Member Info Saved Successfull!";
clearAll();
}
public void saveProspect() {
ProspectDAO dao = new ProspectDAO();
try {
hashPassword();
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex);
}
dao.createEntity(prospect);
this.msg = "Member Info Saved Successfull!";
}
public void reset() {
RequestContext.getCurrentInstance().reset("form");
}
public void updateUser(int id) {
UserDAO dao = new UserDAO();
try {
hashPassword();
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex);
}
dao.updateEntity(id);
this.msg = "Member Info Update Successfull!";
clearAll();
}
public void deleteUser(int id) {
UserDAO dao = new UserDAO();
dao.deleteEntity(id);
this.msg = "Member Info Delete Successfull!";
clearAll();
}
}
Only case this works is, when I implemented the Reset button, and on a failed validation, I click reset, then I can input values into fields.
Also, when I hover above a field (p:inputText), the cursor doesn't change to the text cursor like on other fields (eg. h:inputText). Really don't have an idea how does the same piece of code work on the PrimeFaces ShowCase web site, and not on my end?
Does anybody have an idea how can I fix this?
I'm using JSF 2.2 + PrimeFaces 5.3
I have checked as much as i can ,but i could not find where the problem is , i have seen few stack overflow Questions related to mine but mostly they all seems missing # .
and i have seen somewhere that old version of mojora lib may cause this exceptions.i checked Names i am using in hibernate beans they all looks good but am not able to locate the problem .....
My Html Page:
<?xml version="1.0" encoding="UTF-8"?>
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:t="http://myfaces.apache.org/tomahawk">
<h:body>
<ui:composition template="/WEB-INF/templates/layout.xhtml">
<ui:param name="category" value="Admin" />
<ui:param name="item" value="Create User" />
<ui:param name="user" value="#{createUserAccountBean}" />
<ui:define name="content">
<h:form id="productsForm">
<div class="headerbg">
<div id="innerheaderbg">
<div id="iconarea">
<img src="#{request.contextPath}/images/headerimages/productlist.png" />
</div>
<div id="headertextarea">
<p class="headingtext">Order</p>
<p id="breadCrumbtext">Order <img src="#{request.contextPath}/images/error-bullet.gif" />
Product Category List
</p>
</div>
<div id="otherarea"></div>
</div>
</div>
<p:growl />
<div class="widget widget-table action-table">
<div class="widget-header"> <i class="icon-th-list"></i>
<h3>Product List</h3>
<p:spacer width="10px" height="30px"/>
<h:outputLabel value="Product Category" style="color:#0A8FFF;font-weight:bold;margin-bottom:50px;"/>
<p:selectOneMenu value="#{productBean.productCategoryId}" id="pFilter" >
<f:selectItem itemLabel="--All--" itemValue="all" noSelectionOption="false"/>
<f:selectItems value="#{productCategoryBean.categoriesList}" var="category"
itemLabel="#{category.productCategoryName}"
itemValue="#{category.productCategoryId}" />
<p:ajax update=":productsForm:productsTable" event="change" listener="#{productBean.filterProducts}" />
</p:selectOneMenu>
</div> <!-- /widget-header -->
<div class="widget-content">
<p:dataTable id="productsTable" value="#{productBean.products}" var="products" rowIndexVar="rowIndex"
paginator="true" rows="10" paginatorPosition="bottom"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}" widgetVar="dt_products">
<p:column headerText="S.No">#{rowIndex+1}</p:column>
<p:column headerText="Product Name">#{products.name}</p:column>
<p:column headerText="Product Code">#{products.code}</p:column>
<p:column headerText="Price">#{products.price}</p:column>
</p:dataTable>
</div> <!-- /widget-content -->
</div>
</h:form>
<br></br>
</ui:define>
</ui:composition>
</h:body>
</html>
and here is my bean, ProductCategoryBean.java:
#Named(value = "productCategoryBean")
#Scope("session")
public class ProductCategoryBean
{
private java.util.List<ProductCategory> categoriesList;
public java.util.List<ProductCategory> getCategoriesList()
{
categoriesList.removeAll(Collections.singleton(null));
return categoriesList;
}
public void setCategoriesList(java.util.List<ProductCategory> categoriesList)
{
this.categoriesList = categoriesList;
}
}
Am Initializing categories list while Login in at LoginBean.java
#Named(value = "loginBean")
#Scope("session")
public class LoginBean {
#Inject
private UserService userService;
#Inject
private StocktrackService stocktrackService;
#Inject
private MenuController menuController;
#Inject
private CheckOut checkOut;
#Inject
private ProductCategoryBean categoryBean;
#Inject
private ProductsBean productsBean;
private String userName;
private String password;
private String statusMessage;
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
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 String getStatusMessage() {
return statusMessage;
}
public void setStatusMessage(String statusMessage) {
this.statusMessage = statusMessage;
}
public String login() throws EncryptionException, ServiceException
{
StringEncrypter se = new StringEncrypter("DES");
String encpassword = se.encrypt(getPassword());
UserAccount userAccount = userService.validateLogin(userName,
encpassword);
if (userAccount == null) {
statusMessage = "The username or password is incorrect.";
return "login.xhtml";
}
session.setAttribute("UserAccount", userAccount);
statusMessage = "";
menuController.setTopmenu(menuLoader(userAccount));
checkOut.setUserId(userAccount.getUserId());
checkOut.setUsername(userAccount.getUserName());
checkOut.setUserAccount(userAccount);
//setting category list of ProductCategoryBean
categoryBean.setCategoriesList(stocktrackService.getProductCategory());
//setting product list of ProductListBean
productsBean.setProducts(stocktrackService.getProduct());
return "/pages/leave/home.xhtml?faces-redirect=true";
}
}
Am getting the following Error:
> Feb 09, 2015 1:04:54 PM
> com.sun.faces.application.view.FaceletViewHandlingStrategy
> handleRenderException SEVERE: Error Rendering
> View[/pages/order/products.xhtml] javax.faces.FacesException:
> javax.el.PropertyNotFoundException: /pages/order/products.xhtml #52,59
> itemLabel="#{category.productCategoryName}": Property
> 'productCategoryName' not found on type java.lang.String at
> javax.faces.component.UIComponentBase$AttributesMap.get(UIComponentBase.java:2364)
> at
> org.primefaces.renderkit.InputRenderer.createSelectItem(InputRenderer.java:102)
> at
> org.primefaces.renderkit.InputRenderer.getSelectItems(InputRenderer.java:86)
> at
> org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeMarkup(SelectOneMenuRenderer.java:71)
> at
> org.primefaces.component.selectonemenu.SelectOneMenuRenderer.encodeEnd(SelectOneMenuRenderer.java:65)
> at
> javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
> at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
> at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) at
> javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
> at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
> at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
> at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
> at
> com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:419)
> at
> com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
> at
> com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
> at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
The Problem is that you are already using the parameter-name category and that it refers to a String
<ui:param name="category" value="Admin" />
And then you are reusing the parameter-name in f:selectItems,
<f:selectItems value="#{productCategoryBean.categoriesList}" var="category"
itemLabel="#{category.productCategoryName}"
itemValue="#{category.productCategoryId}" />
but as it is already defined as an ui:param you are getting the given Exception. To resolve this, just use another name for the var in f:selectItems:
<f:selectItems value="#{productCategoryBean.categoriesList}" var="productCategory"
itemLabel="#{productCategory.productCategoryName}"
itemValue="#{productCategory.productCategoryId}" />
I am developing small web app using JSF/PrimeFaces. I am able to call bean from web, however, I am unable to return web. This is what I have:
requestLeave.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Request leave</title>
</h:head>
<h:body>
<script language="javascript">
var today = new Date();
document.write(today);
</script>
<h:form id="form" >
<h:panelGrid id= "grid" columns="2" cellpadding="5">
<f:facet name="header">
<p:messages id="msgs" />
</f:facet>
<h:outputLabel for="title" value="Leave Title:" style="font-weight:bold" />
<p:inputText value="#{requestLeave.titleLeave}" required="true" requiredMessage="title is required." />
<h:outputLabel for="type" value="Type:" style="font-weight:bold" />
<p:inputText value="#{requestLeave.typeLeave}" required="true" requiredMessage="type is required." />
<p:commandButton value="Submit" actionListener="#{requestLeave.buttonAction}" />
</h:panelGrid>
</h:form>
</h:body>
</html>
RequestLeave.java
import javax.faces.bean.ManagedBean;
#ManagedBean
public class RequestLeave {
private String titleLeave;
private String typeLeave;
public String getTitleLeave() {
return titleLeave;
}
public void setTitleLeave(String titleLeave) {
this.titleLeave = titleLeave;
}
public String getTypeLeave() {
return typeLeave;
}
public void setTypeLeave(String typeLeave) {
this.typeLeave = typeLeave;
}
public String buttonAction() {
System.out.println("leave title " + titleLeave);
System.out.println("leave type " + typeLeave);
return ("index.jsp");
}
}
With this, I cannot return to index.jsp. Can anyone help me? Thanks in advance.
Change the actionListener attribute to action:
<p:commandButton value="Submit" action="#{requestLeave.buttonAction}" />
More info:
Differences between action and actionListener?
Im getting my primefaces scaffold ready for my developers and I have a problem. When I do a form submit with validation via AJAX, it displays the message right, but the return deletes all but the first field in the form. Its almost like something screwy in the return ajax call is causing everything after the first text field to fail to render. If I do a standard form submit button, it works just fine, but just with the ajax submit (which of course is the one i want to use) it acts weird. Any ideas?
My index.xhtml page. Just look for header="New Person", pasted it right out of the showcase
<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:core="http://highmark.com/dtmcore"
xmlns:inq="http://highmark.com/dtminq"
template="templates/default.xhtml">
<ui:define name="navDisplay">
<ui:include src="navBar/mainNavBar.xhtml" />
</ui:define>
<ui:define name="content">
<script type="text/javascript">
$(document).ready(
function() {
jvers = $.fn.jquery;
$("#testJQueryLoaded").text(
"jQuery Loaded Correctly version " + jvers);
});
</script>
<div class="row clearfix">
<div class="col-md-12 column">
<div class="row clearfix">
<div class="col-md-12">
<div class="jumbotron">
<h2>Inquiry App System</h2>
<p>This page right now is used primarily for testing controls
and layout</p>
<p></p>
<span id="testJQueryLoaded"></span> <br />
<h3>Your application can run on:</h3>
<h:graphicImage library="gfx" name="dualbrand_as7eap.png" />
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-12">
<div class="well">
<h:form id="form">
<p:panel id="panel" header="New Person" style="margin-bottom:10px;">
<p:messages id="messages" />
<h:panelGrid columns="3">
<h:outputLabel for="firstname" value="Firstname: *" />
<p:inputText id="firstname"
value="#{pprBean.firstname}" required="true" label="Firstname">
<f:validateLength minimum="2" />
</p:inputText>
<p:message for="firstname" />
<h:outputLabel for="surname" value="Surname: *" />
<p:inputText id="surname"
value="#{pprBean.surname}" required="true" label="Surname"/>
<p:message for="surname" />
</h:panelGrid>
</p:panel>
<p:commandButton value="Ajax Submit" update="panel,display" id="ajax"
actionListener="#{pprBean.savePerson}" styleClass="ui-priority-primary"/>
<p:commandButton value="Non-Ajax Submit" actionListener="#{pprBean.savePerson}"
ajax="false" />
<p:commandButton value="With Icon" actionListener="#{pprBean.savePerson}" id="withIcon"
update="panel,display" icon="ui-icon-disk" />
<p:commandButton actionListener="#{pprBean.savePerson}" update="panel,display" id="iconOnly"
icon="ui-icon-disk" title="Icon Only"/>
<p:commandButton value="Disabled" disabled="true" id="disabled" />
<p:panel id="display" header="Information" style="margin-top:10px;">
<h:panelGrid columns="2">
<h:outputText value="Firstname: " />
<h:outputText value="#{pprBean.firstname}" />
<h:outputText value="Surname: " />
<h:outputText value="#{pprBean.surname}" />
</h:panelGrid>
</p:panel>
</h:form>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-md-6">
<ui:include src="modules/buttonExample.xhtml" />
</div>
<div class="col-md-6">
<p:outputPanel id="displayHotkey">
<p:outputLabel value="Hotkey Result" />
<br />
<h:outputText value="#{hotkeyController.keyText}"
rendered="#{not empty hotkeyController.keyText}" />
</p:outputPanel>
</div>
</div>
<div class="row clearfix">
<div class="col-md-6">
<ui:include src="modules/datePickerExample.xhtml" />
</div>
<div class="col-md-6"></div>
</div>
<div class="row clearfix">
<div class="col-md-12">
<div class="well">
<h2>Members</h2>
<br />
<h:panelGroup rendered="#{empty members}">
<em>No registered members.</em>
</h:panelGroup>
<p:dataTable id="dataTable" var="_member" value="#{members}"
rendered="#{not empty members}"
styleClass="table table-striped table-bordered">
<p:column>
<f:facet name="header">Id</f:facet>
#{_member.id}
</p:column>
<p:column>
<f:facet name="header">Name</f:facet>
#{_member.name}
</p:column>
<p:column>
<f:facet name="header">Email</f:facet>
#{_member.email}
</p:column>
<p:column>
<f:facet name="header">Phone #</f:facet>
#{_member.phoneNumber}
</p:column>
<p:column>
<f:facet name="header">REST URL</f:facet>
/rest/members/#{_member.id}
</p:column>
<f:facet name="footer">
REST URL for all members: /rest/members
</f:facet>
</p:dataTable>
</div>
</div>
</div>
</div>
</div>
</ui:define>
<ui:define name="hotkeyMenu">
<ui:include src="hotkeyBar/hotkeyExample.xhtml" />
</ui:define>
</ui:composition>
And my template file (so far, work in progress)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>#{app.applicationName}</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>#{app.applicationName}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="" />
<meta name="author" content="" />
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
.sidebar-nav {
padding: 9px 0;
}
</style>
<h:outputStylesheet name="css/bootstrap.min.css" />
<h:outputStylesheet name="css/inquiry.css" />
<h:outputScript library="primefaces" name="jquery/jquery.js" />
<h:outputScript library="js" name="respond.min.js" />
<h:outputScript library="js" name="bootstrap.min.js" />
<!-- <h:outputScript library="js" name="bootstrap-dropdown.js"/> -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</h:head>
<h:body>
<div class="container">
<div class="row">
<div class="col-md-12 column">
<ui:insert name="navDisplay">[Navigation Display inserted here]</ui:insert>
</div>
<div class="row show-grid">
<div class="col-md-11 column">
<div class="row">
<div class="col-md-12 column">
<ui:insert name="content">[Template content will be inserted here]</ui:insert>
</div>
</div>
</div>
<div class="col-md-1 column">
<ui:insert name="hotkeyMenu">[The Hotkey vertical bar goes here.]</ui:insert>
</div>
</div>
<div class="row">
<div class="col-md-12 column">
<p>United Concordia Rocks!</p>
</div>
</div>
</div>
</div>
<!--/.fluid-container-->
</h:body>
</html>
my backing bean
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.primefaces.context.RequestContext;
#ManagedBean(name = "pprBean")
#SessionScoped
public class PPRBean implements Serializable {
private String firstname;
private String surname;
private String city;
private String suburb;
private Map<String, String> cities = new HashMap<String, String>();
private Map<String, Map<String, String>> suburbsData = new HashMap<String, Map<String, String>>();
private Map<String, String> suburbs = new HashMap<String, String>();
private Map<String, String> rooms = new HashMap<String, String>();
private Map<String, Map<String, String>> itemsData = new HashMap<String, Map<String, String>>();
private Map<String, String> items = new HashMap<String, String>();
private String room;
private String item;
private String[] selectedCities;
public PPRBean() {
cities.put("Istanbul", "Istanbul");
cities.put("Ankara", "Ankara");
cities.put("Izmir", "Izmir");
Map<String, String> suburbsIstanbul = new HashMap<String, String>();
suburbsIstanbul.put("Kadikoy", "Kadikoy");
suburbsIstanbul.put("Levent", "Levent");
suburbsIstanbul.put("Cengelkoy", "Cengelkoy");
Map<String, String> suburbsAnkara = new HashMap<String, String>();
suburbsAnkara.put("Kecioren", "Kecioren");
suburbsAnkara.put("Cankaya", "Cankaya");
suburbsAnkara.put("Yenimahalle", "Yenimahalle");
Map<String, String> suburbsIzmir = new HashMap<String, String>();
suburbsIzmir.put("Cesme", "Cesme");
suburbsIzmir.put("Gumuldur", "Gumuldur");
suburbsIzmir.put("Foca", "Foca");
suburbsData.put("Istanbul", suburbsIstanbul);
suburbsData.put("Ankara", suburbsAnkara);
suburbsData.put("Izmir", suburbsIzmir);
rooms.put("Living Room", "Living Room");
rooms.put("Kitchen", "Kitchen");
rooms.put("Bedroom", "Bedroom");
Map<String, String> livingRoomItems = new HashMap<String, String>();
livingRoomItems.put("Sofa", "Sofa");
livingRoomItems.put("Armchair", "Armchair");
livingRoomItems.put("Coffee Table", "Coffee Table");
Map<String, String> kitchenItems = new HashMap<String, String>();
kitchenItems.put("Refrigirator", "Refrigirator");
kitchenItems.put("Dishwasher", "Dishwasher");
kitchenItems.put("Oven", "Oven");
Map<String, String> bedroomItems = new HashMap<String, String>();
bedroomItems.put("Bed", "Bed");
bedroomItems.put("Wardrobe", "Wardrobe");
bedroomItems.put("Drawer Chest", "Drawer Chest");
itemsData.put("Living Room", livingRoomItems);
itemsData.put("Kitchen", kitchenItems);
itemsData.put("Bedroom", bedroomItems);
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public void savePerson(ActionEvent actionEvent) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("You've registered"));
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getSuburb() {
return suburb;
}
public void setSuburb(String suburb) {
this.suburb = suburb;
}
public Map<String, String> getCities() {
return cities;
}
public void setCities(Map<String, String> cities) {
this.cities = cities;
}
public Map<String, Map<String, String>> getSuburbsData() {
return suburbsData;
}
public void setSuburbsData(Map<String, Map<String, String>> suburbsData) {
this.suburbsData = suburbsData;
}
public Map<String, String> getSuburbs() {
return suburbs;
}
public void setSuburbs(Map<String, String> suburbs) {
this.suburbs = suburbs;
}
public void handleCityChange() {
if (city != null && !city.equals(""))
suburbs = suburbsData.get(city);
else
suburbs = new HashMap<String, String>();
}
public void handleRoomChange(ActionEvent actionEvent) {
if (room != null && !room.equals(""))
items = itemsData.get(room);
else
items = new HashMap<String, String>();
}
private boolean checked;
public boolean isChecked() {
return checked;
}
public void setChecked(boolean checked) {
this.checked = checked;
}
public String[] getSelectedCities() {
return selectedCities;
}
public void setSelectedCities(String[] selectedCities) {
this.selectedCities = selectedCities;
}
public String getSelectedCitiesAsString() {
if (selectedCities == null)
return "";
StringBuffer buffer = new StringBuffer();
for (String city : selectedCities) {
buffer.append("(");
buffer.append(city);
buffer.append(")");
}
return buffer.toString();
}
public Map<String, String> getRooms() {
return rooms;
}
public void setRooms(Map<String, String> rooms) {
this.rooms = rooms;
}
public Map<String, Map<String, String>> getItemsData() {
return itemsData;
}
public void setItemsData(Map<String, Map<String, String>> itemsData) {
this.itemsData = itemsData;
}
public Map<String, String> getItems() {
return items;
}
public void setItems(Map<String, String> items) {
this.items = items;
}
public String getRoom() {
return room;
}
public void setRoom(String room) {
this.room = room;
}
public String getItem() {
return item;
}
public void setItem(String item) {
this.item = item;
}
public void displayLocation() {
FacesMessage msg = new FacesMessage("Selected", "City:" + city + ", Suburb: " + suburb);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void reset() {
RequestContext.getCurrentInstance().reset("form:panel");
}
public void resetFail() {
this.firstname = null;
this.surname = null;
FacesMessage msg = new FacesMessage("Model reset, but it won't work.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
This is the screen as when you first come to it
If you click the ajax button, this is what returns. The normal submit works just fine
And here's what the JSF is returning in the ajax call. You can see, all the fields are included in the response, but its only displaying the first one
<?xml version="1.0" encoding="utf-8"?><partial-response><changes><update id="form:panel"><![CDATA[<div id="form:panel" class="ui-panel ui-widget ui-widget-content ui-corner-all" style="margin-bottom:10px;" data-widget="widget_form_panel"><div id="form:panel_header" class="ui-panel-titlebar ui-widget-header ui-helper-clearfix ui-corner-all"><span class="ui-panel-title">New Person</span></div><div id="form:panel_content" class="ui-panel-content ui-widget-content"><div id="form:messages" class="ui-messages ui-widget" aria-live="polite"><div class="ui-messages-error ui-corner-all"><span class="ui-messages-error-icon"></span><ul><li><span class="ui-messages-error-summary">Firstname: Validation Error: Value is required.</span></li><li><span class="ui-messages-error-summary">Surname: Validation Error: Value is required.</span></li></ul></div></div><table><tbody>
<tr><td><label for="form:firstname">Firstname: *</label></td><td><input id="form:firstname" name="form:firstname" type="text" value="" class="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all ui-state-error" /><script id="form:firstname_s" type="text/javascript">//<![CDATA[
PrimeFaces.cw('InputText','widget_form_firstname',{id:'form:firstname'});
//]]><![CDATA[]]]]><![CDATA[></script></td><td><div id="form:j_id679843775_7ac2197c" aria-live="polite" class="ui-message ui-message-error ui-widget ui-corner-all"><span class="ui-message-error-icon"></span><span class="ui-message-error-detail">Firstname: Validation Error: Value is required.</span></div></td></tr>
<tr><td><label for="form:surname">Surname: *</label></td><td><input id="form:surname" name="form:surname" type="text" value="" class="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all ui-state-error" /><script id="form:surname_s" type="text/javascript">//<![CDATA[
PrimeFaces.cw('InputText','widget_form_surname',{id:'form:surname'});
//]]><![CDATA[]]]]><![CDATA[></script></td><td><div id="form:j_id679843775_7ac21953" aria-live="polite" class="ui-message ui-message-error ui-widget ui-corner-all"><span class="ui-message-error-icon"></span><span class="ui-message-error-detail">Surname: Validation Error: Value is required.</span></div></td></tr>
</tbody>
</table></div></div><script id="form:panel_s" type="text/javascript">//<![CDATA[
PrimeFaces.cw('Panel','widget_form_panel',{id:'form:panel'});
//]]><![CDATA[]]]]><![CDATA[></script>]]></update><update id="form:display"><![CDATA[<div id="form:display" class="ui-panel ui-widget ui-widget-content ui-corner-all" style="margin-top:10px;" data-widget="widget_form_display"><div id="form:display_header" class="ui-panel-titlebar ui-widget-header ui-helper-clearfix ui-corner-all"><span class="ui-panel-title">Information</span></div><div id="form:display_content" class="ui-panel-content ui-widget-content"><table><tbody>
<tr><td>Firstname: </td><td></td></tr>
<tr><td>Surname: </td><td></td></tr>
</tbody>
</table></div></div><script id="form:display_s" type="text/javascript">//<![CDATA[
PrimeFaces.cw('Panel','widget_form_display',{id:'form:display'});
//]]><![CDATA[]]]]><![CDATA[></script>]]></update><update id="javax.faces.ViewState"><![CDATA[zSrt/a8fGazYeKThaR1kLCIZ9H+Byig1+R3m5/RMMwuGDQUZXOPr/aj4D7YpgH6NUcb5jAudj1QUNy6WMLUaVXYQrGkvy6fxpzBhHuvzVejCEMDhFVUj8d7NHCI=]]></update><extension ln="primefaces" type="args">{"validationFailed":true}</extension></changes></partial-response>
EDIT
I found it. Turns out its a bug in PrimeFaces with Websphere.
http://forum.primefaces.org/viewtopic.php?f=3&t=34650
Try
<p:commandButton value="Ajax Submit" update="panel,display" id="ajax"
actionListener="#{pprBean.savePerson}" styleClass="ui-priority-primary"
process="panel,display,#this"/>
And tell me more details about Back Bean to replicate :)
I am testing the PrimeFaces example avaible at https://www.primefaces.org/showcase/ui/overlay/dialog/loginDemo.xhtml . I correctly imported PrimeFaces and JSF 2.1 in Eclipse Dyamic web project, but I get the following error while starting the webpage (with Tomcat):
javax.faces.view.facelets.TagException: /login.xhtml at line 30 and column 36 <f:facet> Tag Library supports namespace: http://java.sun.com/jsf/html, but no tag was defined for name: facet
org.apache.myfaces.view.facelets.compiler.CompilationManager.pushTag(CompilationManager.java:282)
org.apache.myfaces.view.facelets.compiler.SAXCompiler$CompilationHandler.startElement(SAXCompiler.java:250)
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:506)
com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidator.java:745)
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:376)
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2717)
com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:607)
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:116)
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:489)
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:835)
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1210)
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:302)
javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
org.apache.myfaces.view.facelets.compiler.SAXCompiler.doCompile(SAXCompiler.java:739)
org.apache.myfaces.view.facelets.compiler.Compiler.compile(Compiler.java:128)
org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory._createFacelet(DefaultFaceletFactory.java:300)
org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory.access$000(DefaultFaceletFactory.java:53)
org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory$1.newInstance(DefaultFaceletFactory.java:114)
org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory$1.newInstance(DefaultFaceletFactory.java:111)
org.apache.myfaces.view.facelets.impl.FaceletCacheImpl.getFacelet(FaceletCacheImpl.java:83)
org.apache.myfaces.view.facelets.impl.FaceletCacheImpl.getFacelet(FaceletCacheImpl.java:50)
org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory.getFacelet(DefaultFaceletFactory.java:199)
org.apache.myfaces.view.facelets.impl.DefaultFaceletFactory.getFacelet(DefaultFaceletFactory.java:182)
org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage._getFacelet(FaceletViewDeclarationLanguage.java:2622)
org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.buildView(FaceletViewDeclarationLanguage.java:452)
org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:78)
org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:241)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:199)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.21 logs.
The LoginBean.java contains:
package classi;
import java.awt.event.ActionEvent;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import org.primefaces.context.RequestContext;
public class LoginBean
{
private String username;
private String password;
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 void login(ActionEvent actionEvent) {
RequestContext context = RequestContext.getCurrentInstance();
FacesMessage msg = null;
boolean loggedIn = false;
if(username != null &&/*&&*/ username.equals("admin") && password != null && password.equals("admin")) {
loggedIn = true;
msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Welcome", username);
} else {
loggedIn = false;
msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Login Error", "Invalid credentials");
}
FacesContext.getCurrentInstance().addMessage(null, msg);
context.addCallbackParam("loggedIn", loggedIn);
}
}
login.xhtml contains:
<?xml version="1.0" encoding="UTF-8" ?>
<!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/html"
xmlns:p="http://primefaces.org/ui">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
<h:outputLink id="loginLink" value="javascript:void(0)" onclick="dlg.show()" title="login">
<p:graphicImage value="/images/login.png" />
</h:outputLink>
<p:growl id="growl" showDetail="true" life="3000" />
<p:dialog id="dialog" header="Login" widgetVar="dlg">
<h:form>
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="username" value="Username:" />
<p:inputText value="#{loginBean.username}"
id="username" required="true" label="username" />
<h:outputLabel for="password" value="Password:" />
<h:inputSecret value="#{loginBean.password}"
id="password" required="true" label="password" />
<f:facet name="footer">
<p:commandButton id="loginButton" value="Login" update=":growl"
actionListener="#{loginBean.login}"
oncomplete="handleLoginRequest(xhr, status, args)"/>
</f:facet>
</h:panelGrid>
</h:form>
</p:dialog>
<script type="text/javascript">
function handleLoginRequest(xhr, status, args) {
if(args.validationFailed || !args.loggedIn) {
jQuery('#dialog').effect("shake", { times:3 }, 100);
} else {
dlg.hide();
jQuery('#loginLink').fadeOut();
}
}
</script>
</body>
</html>
Try to change xmlns:f="http://java.sun.com/jsf/html" to xmlns:f="http://java.sun.com/jsf/core">