jsf h:dataTable - not refreshing after deleting row - jsf

Hello Guys i need your help as usual
Jsf h:dataTable - not refreshing after deleting row.
Not until i have to restart the programm.
what can i do please to resolve this problem?
Thanks John.
ManagedBean
public List<Customer> getCustomerList() {
if (customerList == null) {
customerList = new ArrayList<Customer>(bookstoreManager.getAllCustomers());
for (Customer cus : customerList) {
System.out.println("Hello" + cus.getFirstName() + "......." + cus.getLastName());
}
}
return customerList;
}
Business Logik
public List<Customer> getAllCustomers() {
TypedQuery<Customer> query = em.createQuery("Select c from Customer c", Customer.class);
return query.getResultList();
}
XHTML Code
<ui:define name="content">
<h:body>
<h:outputStylesheet name="css/style.css" />
<h:form id="form">
<h:dataTable var="cus" cellpadding="5" cellspacing="5" border="1"
width="400" styleClass="customerList"
value="#{customerBean.getCustomerList()}">
<h:column>
<f:facet name="header">
<h:outputText value="#{texts.firstName}" />
</f:facet>
<h:outputText value="#{cus.firstName}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{ texts.lastName}" />
</f:facet>
<h:outputText value="#{cus.lastName}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{texts.address}" />
</f:facet>
<h:outputText value="#{cus.address}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{texts.creditCard}" />
</f:facet>
<h:outputText value="#{cus.creditCard}" />
</h:column>
<h:column>
<h:commandLink action="#{customerBean.selectCustomer(cus)}"
value="Edit" />
</h:column>
<h:column headerText="Delete">
<h:commandLink value="#{texts.delete}"
action="#{customerBean.deleteCustomer(cus)}" />
</h:column>
</h:dataTable>
</h:form>
</h:body>
</ui:define>

Related

JSF h:commandButton is not working inside h:DataTable

I'm trying to delete a specific data in a table, i try to get the column id by using commandButton but it doesn't work, i tried to just show a message in the console when the button is clicked but no luck at all, i tried also some solutions that were offered in this community but it didn't work for me.
Ps: i tried to use ViewScoped instead of request, but it didnt work too.
Here is a part of my code:
<f:view>
<h:form>
<h:commandButton
value="Afficher les demandes"
action="#{demandeBean1.listedemandes}"
styleClass="btn btn-success" />
</h:form>
<h:form>
<h:dataTable
value="#{demandeBean1.demandes}"
var="demande"
styleClass="table table-bordered"
cellspacing="4"
width="60%"
rowClasses="paire,impaire"
headerClass="titre">
<h:column>
<f:facet name="header">
<h:outputText value="Date de demande" />
</f:facet>
<h:outputText value="#{demande.dateDmd}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Date de debut" />
</f:facet>
<h:outputText value="#{demande.dateDbtAbs}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Date de fin" />
</f:facet>
<h:outputText value="#{demande.dateFinAbs}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Nombre de jours" />
</f:facet>
<h:outputText value="#{demande.nbrJr}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Type" />
</f:facet>
<h:outputText value="#{demande.type}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Status" />
</f:facet>
<h:outputText value="#{demande.status}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Action" />
</f:facet>
<h:commandButton
value="Supprimer"
styleClass="btn btn-danger"
actionListener="#{demandeBean1.supprimer(demande.idDmd)}">
</h:commandButton>
</h:column>
</h:dataTable>
</h:form>
</f:view>
My Bean:
#Named
#RequestScoped
public class DemandeBean implements Serializable {
private int idDmd;
private Date dateDbtAbs;
private Date dateDmd;
private Date dateFinAbs;
private int nbrJr;
private String status;
private String type;
private List<Demande> demandes;
public DemandeBean() {}
public void supprimer(int id) {
System.out.println("It works"); //this is not displaying
}
}

Delete Rows Using Checkbox in JSF

I am trying to delete multiple rows of employee data using checkboxes. However i am having a hard time finding a way to do this. The following is some code:
DeleteEmployees.xhtml
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:loadBundle basename="resources.application" var="msg"/>
<head>
<title><h:outputText value="#{msg.welcomeTitle}" /></title>
</head>
<h:body>
<h:dataTable value="#{empController.list}" var="emp" border="2">
<h:column>
<f:facet name="header">
<h:outputText value="First Name"/>
</f:facet>
<h:outputText value="#{emp.firstName}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Last Name"/>
</f:facet>
<h:outputText value="#{emp.lastName}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Email"/>
</f:facet>
<h:outputText value="#{emp.email}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Phone"/>
</f:facet>
<h:outputText value="#{emp.phone}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Hire Date"/>
</f:facet>
<h:outputText value="#{emp.hireDate}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Manager ID"/>
</f:facet>
<h:outputText value="#{emp.managerId}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Department ID"/>
</f:facet>
<h:outputText value="#{emp.departmentId}"/>
</h:column>
<h:column>
<f:facet name="header">Delete</f:facet>
<h:form>
<h:selectBooleanCheckbox value="#{empController.checked[emp.id]}"/>
</h:form>
</f:facet>
</h:column>
</h:dataTable>
<h:commandButton value="Delete Employees" action="#{empController.delEmp}"/>
</h:body>
</html>
In my Managed bean i have this method in order to delete the ID. However the objects are not being deleted. I need some guidance here thank you!
public void delEmp(){
list = em.getAllEmployees();
for(Employee e : list){
if(checked.get(e.getId())){
em.deleteEmployee(e.getId());
}
}
checked.clear();
}
Your h:commandButton is not nested within the h:form. It needs to be nested for the form data to submit. Note that this is not a JSF limitation, but an HTML limitation.
See also
Call another form from the command button

Passing parameters between xhtml

I'm trying to pass a parameter between two xhtml, I have the next code for the first xhtm
<h:dataTable value="#{ofertaController.items}" var="item" border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all" style="border:solid 1px">
<h:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListOfertaTitle_idoferta}"/>
</f:facet>
<h:outputText value="#{item.idoferta}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListOfertaTitle_fechaInicio}"/>
</f:facet>
<h:outputText value="#{item.fechaInicio}">
<f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListOfertaTitle_fechaFin}"/>
</f:facet>
<h:outputText value="#{item.fechaFin}">
<f:convertDateTime pattern="MM/dd/yyyy HH:mm:ss" />
</h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListOfertaTitle_descripcion}"/>
</f:facet>
<h:outputText value="#{item.descripcion}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListOfertaTitle_precioInicial}"/>
</f:facet>
<h:outputText value="#{item.precioInicial}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListOfertaTitle_precioFinal}"/>
</f:facet>
<h:outputText value="#{item.precioFinal}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListOfertaTitle_negocioCif}"/>
</f:facet>
<h:outputText value="#{item.negocioCif}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value=" "/>
</f:facet>
<h:commandLink action="#{ofertaController.prepareView}" value="#{bundle.ListOfertaViewLink}"/>
<h:outputText value=" "/>
<h:commandLink action="#{ofertaController.prepareEdit}" value="#{bundle.ListOfertaEditLink}"/>
<h:outputText value=" "/>
<h:commandLink action="#{ofertaController.destroy}" value="#{bundle.ListOfertaDestroyLink}"/>
<h:link outcome="/cupon/compra" value="Comprar">
<f:param name="idOferta" value="#{item.idoferta}" />
</h:link>
</h:column>
</h:dataTable>
As you can see I have a:
<h:link outcome="/cupon/compra" value="Comprar">
<f:param name="idOferta" value="#{item.idoferta}" />
</h:link>
And I get the next url:
http://localhost:8080/agrupados/faces/cupon/compra.xhtml?idOferta=1
This idOferta=1 I want to use it in a Managed bean but always, it appears as null, why?. The xhtml which I linked before is this one:
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="#{bundle.CreateCuponLabel_email}" for="email" />
<h:inputText id="email" value="#{cuponController.selected.email}" title="#{bundle.CreateCuponTitle_email}" required="true" requiredMessage="#{bundle.CreateCuponRequiredMessage_email}"/>
</h:panelGrid>
<br />
<h:commandLink action="#{cuponController.create}" value="#{bundle.CreateCuponSaveLink}" />
<br />
<br />
<h:commandLink action="#{cuponController.prepareList}" value="#{bundle.CreateCuponShowAllLink}" immediate="true"/>
<br />
<br />
<h:link outcome="/index" value="#{bundle.CreateCuponIndexLink}"/>
<br/>
<h:commandButton id="compra" value="COMPRAR" action="#{compra.addCompra}" />
</h:form>
And the ManagedBean is this one where is the addCompra:
#ManagedBean(name="compra")
#RequestScoped
public class Compra {
#EJB
private NegocioFacade negocioFacade;
#EJB
private OfertaFacade ofertaFacade;
#ManagedProperty(value = "#{param.idOferta}")
private String idOferta;
//(String)
public Compra() {
}
public void addCompra(){
System.out.println(idOferta);
FacesContext fc=FacesContext.getCurrentInstance();
String idoferta=ofer(fc);
System.out.println(idoferta);
}
public String ofer(FacesContext fc){
Map<String,String> params = fc.getExternalContext().getRequestParameterMap();
return params.get("idOferta");
}
}
What can I do?, how can I get this idOferta=1?. Thanks so much for all guys
you can use f:viewParam like this:
<f:metadata>
<f:viewParam name="idOferta" value="#{compra.idOferta}" />
</f:metadata>
just don't forget to add the getter-setter methods for idOferta to class compra, and remove the #ManagedProperty annotation.

Conditional column rendering

I'm working with jsf 2.0. I have this datatable
<h:dataTable value="#{agreement.licenseProducts}"
var="licenseProduct"
styleClass="pnx-table pnx-table-bdr pnx-table-unstyled mp-license-info">
<h:column>
<f:facet name="header">
<h:outputText value="Product" />
</f:facet>
<h:outputText value="#{licenseProduct.description}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Serial Number" />
</f:facet>
<h:outputText value="#{licenseProduct.serialNumber}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{agreement.labelForConcurrency}" />
</f:facet>
<h:outputText value="#{licenseProduct.concurrent}" />
</h:column>
<ui:fragment rendered="#{agreement.managementTool != 'NONE'}">
<h:column>
<f:facet name="header">
<h:outputText value="#{agreement.labelForLicenseType}" />
<span class="pnx-icon-right pnx-icon-info pnx-tooltip">
<div class="pnx-tooltip-content">
<h:outputText value="Tooltip content" />
</div>
</span>
</f:facet>
<h:outputText value="#{licenseProduct.licenseBase}" />
</h:column>
</ui:fragment>
<h:column>
<f:facet name="header">
<h:outputText value="#{agreement.labelForSeatCount}" />
</f:facet>
<h:outputText value="#{licenseProduct.seats}" />
</h:column>
</h:dataTable>
The problem is that the ui:fragment part is not working. No matter what the attribute's value is, it will NEVER show the column.
Any ideas?
--EDIT--
Just in case, I have other ui:fragments that depend on that same attribute, and they do render correctly depending on the attribute's value. I'm sure it has to do with the dataTable and the columns.
The rendered's attribute of <h:column> tag performs simply the job :
<h:column rendered="#{agreement.managementTool != 'NONE'}">
...
</h:column>

<h:dataTable value is not null, but the page is empty

I have two dataTables, one nest anther. The code as below :
<h:dataTable value="#{allUserBean.userList}" var="pmUsers">
<h:column headerClass="tableHeader column8Header">
<f:facet name="header">
<h:commandLink actionListener="#{allUser.sortByEmpNo}" immediate="true">
<h:panelGrid columns="2" columnClasses="colSortText,colSortImg">
<h:outputText value="Emp No." />
<h:panelGrid rendered="#{allUserBean.sortType == 0}">
<h:graphicImage url="/images/sortup.gif" rendered="#{allUserBean.up}" />
<h:graphicImage url="/images/sortdown.gif" rendered="#{!allUserBean.up}" />
</h:panelGrid>
</h:panelGrid>
</h:commandLink>
</f:facet>
<h:outputText value="#{pmUsers.employeeNo}" />
</h:column>
<h:dataTable var="iterm" value="#{pmUsers.userMultyResumeList}"">
<h:outputText value="#{iterm}" />
</h:dataTable> `
The show successful, but the other dataTable of userMultyResumeList can't be showed.
I used the testing code , it is false. so the value is not null, i don't know why
The userList code as :
private List<User> userList;
userList = userService.getUsersByPMGroupNotIncluded("", groupIds);
<h:dataTable var="iterm" value="#{pmUsers.userMultyResumeList}"">
Please repalce this line with this
<h:dataTable var="iterm" value="#{pmUsers.userMultyResumeList}">

Resources