I am trying to create a composite component for a user search. Here is the component xhtml:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:cc="http://java.sun.com/jsf/composite"
xmlns:h="http://java.sun.com/jsf/html">
<cc:interface componentType="searchUser">
<!-- Define component attributes here -->
<cc:attribute name="value" type="java.lang.Object"
shortDescription="Selected User"/>
</cc:interface>
<cc:implementation>
<p:commandButton onclick="PF('sdgl').show();" type="button" value="search for user"/>
<p:dialog header="Search for User"
widgetVar="sdgl"
modal="true"
width="80%"
appendTo="#(body)"
>
<h:form id="searchDLGForm" >
<p:fragment autoUpdate="true">
<p:panelGrid columns="2" id="searchPanel">
<p:outputLabel value="Username: "
for="username"
/>
<p:inputText id="username" binding="#{cc.login}"/>
<p:outputLabel value="First Name: "
for="firstname"
/>
<p:inputText id="firstname" binding="#{cc.firstname}"/>
<p:outputLabel value="Last Name: "
for="lastname"
/>
<p:inputText id="lastname" binding="#{cc.lastname}"/>
<p:commandButton value="search" actionListener="#{cc.search}"/>
</p:panelGrid>
<p:dataTable value="#{cc.foundUser}" var="user" id="sdgl_res" selection="#{cc.selectedUser}"
rowKey="#{user.id}">
<p:column selectionMode="single"
style="width:16px;text-align:center"/>
<p:column headerText="First Name">
#{user.firstName}
</p:column>
<p:column headerText="Last Name">
#{user.lastName}
</p:column>
<p:column headerText="E-Mail">
#{user.email}
</p:column>
</p:dataTable>
</p:fragment>
</h:form>
</p:dialog>
</cc:implementation>
The compnent is nesten in:
<h:form id="ouMembers">
<div>
<p:panelGrid>
......
<my:searchUser id="searchDLG" value="#{ouBean.userToAdd}"/>
</p:panelGrid>
</div>
</h:form>
And the corresponding Java:
private UIInput firstname;
private UIInput lastname;
private UIInput login;
private UserModel selectedUser;
private List<UserModel> foundUser;
/**
* Returns the component family of {#link UINamingContainer}.
* (that's just required by composite component)
*/
#Override
public String getFamily() {
return UINamingContainer.COMPONENT_FAMILY;
}
/**
* return selected user
*
* #return selected user
*/
#Override
public Object getSubmittedValue() {
return selectedUser;
}
public void search(ActionEvent event) {
System.out.println("searchUser called with: " + this.login.getSubmittedValue()+ ", " +
""+this.firstname.getSubmittedValue()+"," +
""+this.lastname.getSubmittedValue());
this.foundUser = UserModel.searchUser((String)this.login.getSubmittedValue(),
(String)this.firstname.getSubmittedValue(),
(String)this.lastname.getSubmittedValue());
}
#Override
public void encodeBegin(FacesContext context) throws IOException {
UserModel value = (UserModel) getValue();
if(value!=null){
firstname.setValue(value.getFirstName());
lastname.setValue(value.getLastName());
login.setValue(value.getLogin());
}else{
firstname.setValue("");
lastname.setValue("");
login.setValue("");
}
}
+ getters setters
The problem I currently have, is that this.login.getSubmittedValue(), this.firstname.getSubmittedValue() and this.lastname.getSubmittedValue() are null in the search method. I have tried using getValue() but that also resulted in null value.
I am following http://balusc.omnifaces.org/2013/01/composite-component-with-multiple-input.html tutorial for this. Any help is greatly appreciated. thanks.
I am using:
com.sun.faces 2.2.12
primefaces 5.2
on Glassfish 4.1.0
EDIT
After removing the <h:form id="searchDLGForm" > and the appendTo="#(body)" from the dialog, it works. however I have to remove the modal="true" parameter, or the dialog is also inactive.
Related
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 am displaying error message after selecting more than one check box. As i click on edit button when i selecting more than one check box i am getting popup. Instead of popup i need to show error message.
this is my jsf page
<!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: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">
<h:head>
</h:head>
<h:body>
<h:form id="myForm">
<div id="page" class="box">
<div class="msg">
<h2>View Outbound Home Page</h2>
<hr />
<p:dialog header="Set Status:" widgetVar="assign" modal="true">
<h:panelGrid columns="2" style="width:400px; height:50px">
<p:outputLabel value="Status" />
<h:selectOneMenu id="status" value="#{leadEditBean.status}">
<f:selectItem itemLabel="--Select one Value--" />
<f:selectItems value="#{leadEditBean.typeOfStatus}" />
</h:selectOneMenu>
</h:panelGrid>
<h:commandButton value="Update"
actionListener="#{leadEditBean.changeStatus()}" />
</p:dialog>
<p:dialog header="Set Reminder Date and Time" widgetVar="setTime"
id="dialog1" resizable="true">
<h:panelGrid columns="2" cellpadding="10" cellspacing="10">
<h:outputText value="set remind time"></h:outputText>
<p:calendar showOn="button" pattern="yyyy-MM-dd hh:mm:ss"
value="#{leadEditBean.date}"></p:calendar>
<h:commandButton value="Set"
action="#{leadEditBean.setRemainderCall()}"></h:commandButton>
</h:panelGrid>
</p:dialog>
</div>
<p:messages for="outbondhome" style="text-align:center"
closable="true"></p:messages>
<div class="callbutton">
<h:panelGrid columns="4">
<p:commandButton id="statusbtn" value="Change Status"
class="button" onclick="PF('assign').show();" ajax="true"
update=":myForm:tbl" disabled="#{leadEditBean.disabled}" />
<p:commandButton id="settime" value="Set Remind Time"
class="button" onclick="PF('setTime').show();" ajax="true"
update=":myForm:tbl" disabled="#{leadEditBean.disabled}"></p:commandButton>
<h:commandButton value="Yesterday Calls"
action="#{leadEditBean.yesterdayCall}" class="button"
immediate="true" />
<h:commandButton value="Remainder Calls"
action="#{leadEditBean.reminderCallsByTime()}" class="button"
immediate="true" />
</h:panelGrid>
</div>
<br></br> <br></br>
<p:dataTable id="tbl" var="lead" value="#{leadEditBean.enquiryTOs}"
widgetVar="filteredlead" rowsPerPageTemplate="25,50,75,100,10000"
filteredValue="#{leadEditBean.filterednewLeadList}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rows="25" paginator="true" rowKey="#{lead.leadId}"
rowIndexVar="rowIndex" selection="#{leadEditBean.leadrTos}"
style="width:100%;">
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search " style="margin-left:840px;" />
<p:inputText id="globalFilter"
onkeyup="PF('filteredlead').filter()" style="width:150px"
placeholder="Enter Phone Number" maxlength="10" />
</p:outputPanel>
</f:facet>
<p:ajax event="rowSelectCheckbox"
listener="#{leadEditBean.onRowSelect}"
update=":myForm:settime :myForm:statusbtn " />
<p:ajax event="rowUnselectCheckbox"
listener="#{leadEditBean.onRowUnselect}"
update=":myForm:settime :myForm:statusbtn " />
<p:column headerText="" style="width:30px;" selectionMode="multiple">
</p:column>
<p:column headerText="Lead Id" style="width:120px;">
<h:outputText value="#{lead.leadId}" />
</p:column>
<p:column headerText="Lead Name">
<h:outputText value="#{lead.firstName}" />
</p:column>
<p:column headerText="Email">
<h:outputText value="#{lead.emailId}" />
</p:column>
<p:column headerText="Phone No" filterMatchMode="contains"
filterBy="#{lead.phoneNum}">
<h:outputText value="#{lead.phoneNum}" />
</p:column>
<p:column headerText="PinCode">
<h:outputText value="#{lead.area.pincode}" />
</p:column>
<p:column rendered="#{leadEditBean.hideColumn}">
<f:facet name="header">
<h:outputText value="Remainder Date" />
</f:facet>
#{lead.time}
</p:column>
<p:column headerText="Edit" style="width:40px;">
<p:commandButton icon="ui-icon ui-icon-pencil"
actionListener="#{leadEditBean.getLeadEnquiryEntityForEdit(lead)}"
oncomplete="PF('edit').show()" ajax="true"
update=":myForm:dialog2" />
</p:column>
</p:dataTable>
</div>
<p:dialog header="Update Lead" widgetVar="edit" id="dialog2"
resizable="true" modal="true">
<p:messages for="home"></p:messages>
<h:panelGrid columns="4" cellpadding="10" cellspacing="4">
<h:outputText value="LeadId" />
<h:outputText value="#{leadEditBean.leadList.leadId}" />
<h:outputText />
<h:outputText />
<h:outputText value="First Name" />
<h:inputText class="input"
value="#{leadEditBean.leadList.firstName}"></h:inputText>
<h:outputText value="Email" />
<h:inputText class="input" value="#{leadEditBean.leadList.emailId}"></h:inputText>
<h:outputText value="Mobile number" />
<h:inputText class="input" value="#{leadEditBean.leadList.phoneNum}"></h:inputText>
<h:outputText value="Pincode" />
<h:selectOneMenu class="input" value="#{leadEditBean.pincode}">
<f:selectItem itemValue="#{leadEditBean.pincode}" />
<f:selectItems value="#{applicationController.typeOfPincode}"></f:selectItems>
</h:selectOneMenu>
</h:panelGrid>
<h:panelGrid>
<p:commandButton id="enquiry" value="Send to Enquiry"
update=":myForm:tbl" onclick="PF('send').show();"
style="margin-left:250px" ajax="true"></p:commandButton>
</h:panelGrid>
<h:commandButton value="Update" ajax="true" update=":myForm:dialog" style="margin-left:265px"
actionListener="#{leadEditBean.updateLeadEnquiryEntity}" />
<h:commandButton value="Cancel" action="#{leadEditBean.cancel}" />
</p:dialog>
<div id="footer">
<p>copy right</p>
</div>
</h:form>
</h:body>
</html>
this is my bean
package com.model.acim.common.controller;
#Component
#ManagedBean
#RequestScoped
public class LeadEditBean extends BaseBean<T> {
#Autowired
#Qualifier("baseServiceImpl")
private BaseService<T> baseService;
private int leadID;
private String firstName;
private String lastName;
private String phoneNumber;
private String emailId;
private String address;
private String area;
private String city;
private String pincode;
private List<LeadEnquiryTO> enquiryTOs;
private AreaTO areaTO = new AreaTO();
private StateTO stateTO;
private CityTO cityTO;
private LeadEnquiryTO enquiryTO = new LeadEnquiryTO();
private LeadEnquiryTO leadList=new LeadEnquiryTO();
private LeadEnquiryTO LeadEnquiryTOUpdate=new LeadEnquiryTO();
private List<LeadEnquiryTO> newLeadList;
private List<LeadEnquiryTO> filterednewLeadList;
private List<LeadEnquiryTO> leadrTos;
List<LeadEnquiryTO> allLeads;
private Timestamp setTime;
private String branch;
private Date date;
private String status;
private List<LeadEnquiryTO> leadEnquiryToListAd = null;
HttpSession session = null;
int noOfSelctions=0;
private Boolean disabled = true;
private Boolean hideColumn = false;
private List<LeadEnquiryTO> leadEnquiryToList = null;
int emp_id;
int selectionForEdit=0;
public int getNoOfSelctions() {
return noOfSelctions;
}
public void setNoOfSelctions(int noOfSelctions) {
this.noOfSelctions = noOfSelctions;
}
public List<LeadEnquiryTO> getLeadEnquiryToList() {
return leadEnquiryToList;
}
public void setLeadEnquiryToList(List<LeadEnquiryTO> leadEnquiryToList) {
this.leadEnquiryToList = leadEnquiryToList;
}
public void getLeadEnquiryEntityForEdit(LeadEnquiryTO to){
int size = leadrTos.size();
if(size<=1){
this.setLeadID(to.getLeadId());
leadList = baseService.getLeadEnquiryEntityForEdit(to.getLeadId());
this.setLeadID(leadList.getLeadId());
this.setFirstName(leadList.getFirstName());
this.setLastName(leadList.getLastName());
this.setPhoneNumber(leadList.getPhoneNum());
this.setEmailId(leadList.getEmailId());
this.setAddress(leadList.getAddress());
String areaName = leadList.getArea().getAreaName();
this.setArea(areaName);
this.setPincode(leadList.getArea().getPincode());
this.setCity(leadList.getArea().getCity().getCityName());
}
else
{
FacesContext.getCurrentInstance().addMessage(
"home",
new FacesMessage("Please select only One Value or One Row"));
}
}
public void onRowSelect(SelectEvent event)
{
noOfSelctions = noOfSelctions+1;
#SuppressWarnings("unused")
LeadEnquiryTO sp = (LeadEnquiryTO) event.getObject();
disabled=false;
}
public void onRowUnselect(UnselectEvent event)
{
noOfSelctions=noOfSelctions-1;
#SuppressWarnings("unused")
LeadEnquiryTO sp = (LeadEnquiryTO) event.getObject();
if (noOfSelctions<=0) {
disabled=true;
} else {
disabled=false;
}
}
public void updateLeadEnquiryEntity(){
LeadEnquiryTOUpdate.setLeadId(leadList.getLeadId());
LeadEnquiryTOUpdate.setFirstName(leadList.getFirstName());
LeadEnquiryTOUpdate.setLastName(leadList.getLastName());
LeadEnquiryTOUpdate.setPhoneNum(leadList.getPhoneNum());
LeadEnquiryTOUpdate.setAddress(leadList.getAddress());
LeadEnquiryTOUpdate.setEmailId(leadList.getEmailId());
areaTO= getAreaTOByid();
LeadEnquiryTOUpdate.setArea(areaTO);
int result = baseService.updateLeadEnquiryEntity(LeadEnquiryTOUpdate);
if (result>0) {
FacesContext.getCurrentInstance().addMessage(
"leadhome",
new FacesMessage("Updated Successfully"));
} else {
FacesContext.getCurrentInstance().addMessage(
"leadhome",
new FacesMessage("Not Updated Successfully"));
}
enquiryTOs = baseService.getLeadEnquiryByEmployeeId(emp_id);
}
public void getLeadEnquiryByEmployeeId(){
session = (HttpSession) FacesContext
.getCurrentInstance().getExternalContext()
.getSession(false);
emp_id = (Integer) session.getAttribute("employeeId");
enquiryTOs = baseService.getLeadEnquiryByEmployeeId(emp_id);
}
//setters getter
}
You should consider to change your checkboxes to radio buttons. In principle this is the right metaphor for a single selection [Checkbox or radio button].
<p:column ... selectionMode="single">
I'm trying to create a filtering datatable with PrimeFaces framework.
My issue is that the datatable is displayed but filtering option doesn't work , help please !!
My page.xhtml looks like :
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition>
<h5>
<h:form>
<p:dataTable var="student" value="#{studentWizard.students}" widgetVar="studentTable" emptyMessage="Aucun élève trouvé" id="tableStudent" filteredValue="#{studentWizard.filteredStudents}" >
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Chercher tous les champs:" />
<p:inputText id="globalFilter" onkeyup="studentTable.filter()" style="width:150px" placeholder="Entrer le mot-clé"/>
</p:outputPanel>
</f:facet>
<p:column filterBy="#{student.studentCode}" headerText="Code de l'élève" filterMatchMode="contains">
<h:outputText value="#{student.studentCode}"/>
</p:column>
<p:column filterBy="#{student.firstName}" headerText="Prénom" filterMatchMode="contains">
<h:outputText value="#{student.firstName}"/>
</p:column>
<p:column filterBy="#{student.lastName}" headerText="Nom" filterMatchMode="contains">
<h:outputText value="#{student.lastName}"/>
</p:column>
<p:column headerText="Modifier" >
<p:commandButton value="Modifier" type="submit" ajax="false" icon="ui-icon-update"/>
</p:column>
</p:dataTable>
</h:form>
</h5>
</ui:composition>
</html>
and My Java Bean :
#ManagedBean(name="studentWizard")
#Component
#ViewScoped
public class StudentWizard implements Serializable {
public StudentWizard() {}
private static final long serialVersionUID = 1L;
private Student student;
private List<Student> students;
private List<Student> filteredStudents;
#PostConstruct
public void init() {
students = getAllStudent();
}
public List<Student> getFilteredStudents() {
return filteredStudents;
}
public void setFilteredStudents(List<Student> filteredStudents) {
this.filteredStudents = filteredStudents;
}
#Autowired
private StudentManager studentManager;
public void setStudentManager(StudentManager studentManager) {
this.studentManager = studentManager;
}
public Student getstudent() {
return student;
}
public StudentManager getStudentManager() {
return studentManager;
}
public void setstudent(Student student) {
this.student = student;
}
public void save() {
studentManager.saveStudent(student);
student = new Student();
}
public List<Student> getAllStudent() {
return studentManager.getAllStudent();
}
public Student getStudentById(int id) {
return studentManager.getStudentById(id);
}
public List<Student> getStudents() {
return students;
}
public void setStudents(List<Student> students) {
this.students = students;
}
}
This is my home web page
<h:body>
<p:layout style="min-width:400px;min-height:100px;">
<p:layoutUnit position="center" size="400" >
</p:layoutUnit>
</p:layout>
<p:layout style="min-width:400px;min-height:500px;">
<p:layoutUnit position="west" size="244" >
<h5>
<h:form>
<p:menu toggleable="true">
<p:submenu label="Eleves">
<p:menuitem value="Nouvel élève" action="#{menuView.setSelectedItem(1)}" update=":globalPanel" />
<p:menuitem value="Consultation" action="#{menuView.setSelectedItem(2)}" update=":globalPanel" />
</p:submenu>
<p:submenu label="Personnels">
</p:submenu>
<p:submenu label="Notes">
</p:submenu>
<p:submenu label="Caisses">
</p:submenu>
<p:submenu label="Salaires">
</p:submenu>
<p:submenu label="Référentiel">
</p:submenu>
</p:menu>
</h:form>
</h5>
</p:layoutUnit>
<p:layoutUnit position="center">
<h:panelGroup id ="globalPanel" >
<h:panelGroup id="inscriptionPanel" rendered="#{menuView.selectedItem == 1}" header="Inscription" style="margin-bottom:20px">
<ui:include src="/inscription.xhtml" />
</h:panelGroup>
<h:panelGroup id="testerPanel" rendered="#{menuView.selectedItem == 2}" header="Consultation" style="margin-bottom:20px" >
<ui:include src="/consul.xhtml" />
</h:panelGroup>
</h:panelGroup>
</p:layoutUnit>
</p:layout>
</h:body>
I have trouble displaying my property details on the dialog, after generating the table. Results are shown, but the selected row is not shown on dialog. I have taken over the example from primefaces show case.
<!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:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>TODO supply a title</title>
<h:outputStylesheet library="css" name="styles.css" />
</h:head>
<h:body>
Dear customer!
<li>#{userDataManager.displayHotelTypeChoice(userDataManager.hotelChoice)}
</li>
<li>#{userDataManager.displayPaxChoice(userDataManager.pax)}
</li>
<li>You have chosen to check in : #{userDataManager.displayCheckinDate(userDataManager.checkinDate)}
</li>
<li>You have chosen to check out : #{userDataManager.displayCheckoutDate(userDataManager.checkoutDate)}
</li>
<li>Total Days of Stay : #{userDataManager.countNightsBetween(userDataManager.checkinDate,userDataManager.checkoutDate)}
</li>
<li>Total Nights of Stay : #{userDataManager.nights}
</li>
<br>
</br>
<h:form id="form">
<p:dataTable id="hotels" var="room" value="#{propertyDataTable.searchByHotelType
(userDataManager.hotelChoice, userDataManager.pax)}"
rowKey="#{room.propertyID}"
selection="#{propertyDataTable.selectedProperty}"
selectionMode="single"
resizableColumns="true">
<f:facet name="header">
#{userDataManager.displayHotelTypeChoice(userDataManager.hotelChoice)}<br></br>
Please select only one choice
</f:facet>
<p:column headerText="Property ID" >
#{room.propertyID}
</p:column>
<p:column headerText="Accommodation" >
#{room.accommodation}
</p:column>
<p:column headerText="Pax" >
#{room.pax}
</p:column>
<p:column headerText="Stars" >
#{room.stars}
</p:column>
<p:column headerText="Type" >
#{room.type}
</p:column>
<f:facet name="footer">
In total there are #{propertyDataTable.listSize(propertyDataTable.
searchByHotelType(userDataManager.hotelChoice,
userDataManager.pax))} hotels.
<p:commandButton id="viewButton" value="View" icon="ui-icon-search"
update=":form:display" oncomplete="hotelDialog.show()">
</p:commandButton>
</f:facet>
</p:dataTable>
<p:dialog id="dialog" header="Hotel Detail" widgetVar="hotelDialog" resizable="false"
width="200" showEffect="clip" hideEffect="fold">
<h:panelGrid id="display" columns="2" cellpadding="4">
<f:facet name="header">
<!--<p:graphicImage value="/resources/images/#{propertyDataTable.selectedProperty.type}.jpg"/>-->
<p:graphicImage value="/resources/images/Grand.jpg"/>
</f:facet>
<h:outputText value="Accommodation:" />
<h:outputText value="#{propertyDataTable.selectedProperty.accommodation }" />
<h:outputText value="Feature:" />
<h:outputText value="#{propertyDataTable.selectedProperty.feature}" />
<h:outputText value="Stars:" />
<h:outputText value="#{propertyDataTable.selectedProperty.stars}" />
</h:panelGrid>
</p:dialog>
</h:form>
<br></br>
<br></br>
<h:commandButton value="Book"
action="#{navigationController.showPage()}" >
<f:param name="page" value="book" />
</h:commandButton>
<br></br>
<h:commandButton value="HOME"
action="#{navigationController.showPage()}" >
<f:param name="page" value="home" />
</h:commandButton>
</h:body>
</html>
package dataTable;
import irms.entity.accommodation.Property;
import irms.entity.accommodation.Room;
import irms.session.accommodation.PropertySession;
import irms.session.accommodation.ReservationSession;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
/**
*
* #author Lawrence
*/
#ManagedBean(name = "propertyDataTable")
#ViewScoped
public class PropertyDataTable implements Serializable{
#EJB
private ReservationSession reservationSession;
#EJB
private PropertySession propertySession;
private List<Property> propertyList;
private int choice;
private Property selectedProperty;
private List<Room> list = new ArrayList();
public PropertyDataTable() {
}
public List<Property> getAllRooms() {
return reservationSession.getAllRooms();
}
public List<Property> searchByHotelType(String hotelType, Integer pax) {
this.propertyList = propertySession.searchByHotelType(hotelType, pax);
return propertyList;
}
public int listSize(List<Property> list){
return list.size();
}
public Room getRoom(String propertyID, Integer roomID) {
return propertySession.findRoom(propertyID, roomID);
}
public List<Room> getRoomList(String propertyID){
return propertySession.getRoomList(propertyID);
}
public ReservationSession getReservationSession() {
return reservationSession;
}
public void setReservationSession(ReservationSession reservationSession) {
this.reservationSession = reservationSession;
}
public PropertySession getPropertySession() {
return propertySession;
}
public void setPropertySession(PropertySession propertySession) {
this.propertySession = propertySession;
}
public List<Property> getPropertyList() {
return propertyList;
}
public void setPropertyList(List<Property> propertyList) {
this.propertyList = propertyList;
}
public int getChoice() {
return choice;
}
public void setChoice(int choice) {
this.choice = choice;
}
public Property getSelectedProperty() {
return selectedProperty;
}
public void setSelectedProperty(Property selectedProperty) {
this.selectedProperty = selectedProperty;
}
public List<Room> getList() {
return list;
}
public void setList(List<Room> list) {
this.list = list;
}
}
You Must add ActionListener in your viewButton commandButton
change your xhtml page like this:
<!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:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>TODO supply a title</title>
<h:outputStylesheet library="css" name="styles.css" />
</h:head>
<h:body>
Dear customer!
<li>#{userDataManager.displayHotelTypeChoice(userDataManager.hotelChoice)}
</li>
<li>#{userDataManager.displayPaxChoice(userDataManager.pax)}
</li>
<li>You have chosen to check in : #{userDataManager.displayCheckinDate(userDataManager.checkinDate)}
</li>
<li>You have chosen to check out : #{userDataManager.displayCheckoutDate(userDataManager.checkoutDate)}
</li>
<li>Total Days of Stay : #{userDataManager.countNightsBetween(userDataManager.checkinDate,userDataManager.checkoutDate)}
</li>
<li>Total Nights of Stay : #{userDataManager.nights}
</li>
<br>
</br>
<h:form id="form">
<p:dataTable id="hotels" var="room" value="#{propertyDataTable.searchByHotelType
(userDataManager.hotelChoice, userDataManager.pax)}"
rowKey="#{room.propertyID}"
resizableColumns="true">
<f:facet name="header">
#{userDataManager.displayHotelTypeChoice(userDataManager.hotelChoice)}<br></br>
Please select only one choice
</f:facet>
<p:column headerText="Property ID" >
#{room.propertyID}
</p:column>
<p:column headerText="Accommodation" >
#{room.accommodation}
</p:column>
<p:column headerText="Pax" >
#{room.pax}
</p:column>
<p:column headerText="Stars" >
#{room.stars}
</p:column>
<p:column headerText="Type" >
#{room.type}
</p:column>
<f:facet name="footer">
In total there are #{propertyDataTable.listSize(propertyDataTable.
searchByHotelType(userDataManager.hotelChoice,
userDataManager.pax))} hotels.
<p:commandButton id="viewButton" value="View" icon="ui-icon-search"
update=":form:display" oncomplete="hotelDialog.show()">
<f:setPropertyActionListener value="#{room}" target="#{propertyDataTable.selectedProperty}" />
</p:commandButton>
</f:facet>
</p:dataTable>
<p:dialog id="dialog" header="Hotel Detail" widgetVar="hotelDialog" resizable="false"
width="200" showEffect="clip" hideEffect="fold">
<h:panelGrid id="display" columns="2" cellpadding="4">
<f:facet name="header">
<!--<p:graphicImage value="/resources/images/#{propertyDataTable.selectedProperty.type}.jpg"/>-->
<p:graphicImage value="/resources/images/Grand.jpg"/>
</f:facet>
<h:outputText value="Accommodation:" />
<h:outputText value="#{propertyDataTable.selectedProperty.accommodation }" />
<h:outputText value="Feature:" />
<h:outputText value="#{propertyDataTable.selectedProperty.feature}" />
<h:outputText value="Stars:" />
<h:outputText value="#{propertyDataTable.selectedProperty.stars}" />
</h:panelGrid>
</p:dialog>
</h:form>
<br></br>
<br></br>
<h:commandButton value="Book"
action="#{navigationController.showPage()}" >
<f:param name="page" value="book" />
</h:commandButton>
<br></br>
<h:commandButton value="HOME"
action="#{navigationController.showPage()}" >
<f:param name="page" value="home" />
</h:commandButton>
</h:body>
</html>
I have a jsf page that I can't update the value of some checkboxes in a list of userDamain objects, in fact this is a part of my jsf page :
<h:outputText value="USER's rights list: "></h:outputText>
<p:dataTable id="userss" var="userr" value="#{userMB.userListe}">
<p:column>
<f:facet name="header"><h:outputText value="FirstName" /></f:facet>
<h:outputText value="#{userr.firstName}" />
</p:column>
<p:column>
<h:panelGrid columns="1" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="Basic Usage: " />
<p:selectBooleanCheckbox value="#{userr.deletee}" immediate="true" actionListener="#{userr.deletee}" />
</h:panelGrid>
<p:commandButton value="Submit" update="display" oncomplete="dlg.show()" />
<p:dialog header="Selected Values" modal="true" showEffect="fade" hideEffect="fade" widgetVar="dlg">
<h:panelGrid columns="1" id="display">
<h:outputText value="Value 1: #{userr.deletee}" />
</h:panelGrid>
</p:dialog>
</p:column>
when I click on the boolean button 'Submit', the value of the userr.deletee is always false ( the default value ) and it's not updated anyway, I tried to use the Listner and actionListener in the booleanButton but it doesn't work, I also tried the postValidate event, so if someone has any idea of that, I would be graceful.
this is a part of my managed bean:
private List<UserDomain> userListe ;
public List<UserDomain> getUserListe() {
return this.userListe;
}
public void loadUserListe(){
this.userListe = new ArrayList<UserDomain>();
this.userListe.addAll(getUserServicee().getAll());
}
public void setUserListe(List<UserDomain> userListe) {
this.userListe = userListe;
}
a part of the userDomain bean:
...
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
#Transient
private boolean deletee;
public boolean isDeletee() {
return deletee;
}
public void setDeletee(boolean deletee) {
this.deletee = deletee;
}
I found out a solution which seems logic to me, I added to my checkbox an ajax behavior to execute a method and an attribute which called in this method to get the whole userDomain object, so on I can get the user.deletee value, here is a part of the code I m talking about:
<h:panelGrid columns="1" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="Delete Right: " />
<p:selectBooleanCheckbox value="#{userr.deletee}">
<f:ajax execute="#this" listener="#{userMB.saveUserRights}" />
<f:attribute name="user" value="#{userr}" />
</p:selectBooleanCheckbox>
</h:panelGrid>
I hope this will be helpful for you