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
}
}
Related
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>
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.
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>
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}">
I am using one h:selectbooleancheckbox in each row to make 2 columns editable.
Have a look at my JSF page
<h:dataTable id="editTable" styleClass = "listtable" value="#{bean.GroupList}" var="group" border="1" first="0" rows="8" width="75%" frame="hsides" rules="all" cellpadding="5" headerClass="tableheading" rowClasses="firstrow, secondrow">
<f:facet name="header">
<h:outputText value="Groups"></h:outputText>
</f:facet>
<h:column>
<f:facet name="header">
<h:outputText value="GroupId"></h:outputText>
</f:facet>
<h:outputText value="#{group.Id}" rendered="#{not bean.checked[group.Id]}"></h:outputText>
<h:inputText value="#{group.Id}" rendered="#{bean.checked[group.Id]}" required="true"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="GroupName"></h:outputText>
</f:facet>
<h:outputText value="#{group.Name}" rendered="#{not bean.checked[group.Id]}"></h:outputText>
<h:inputText value="#{group.Name}" rendered="#{bean.checked[group.Id]}" required="true"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Check to Enable/Disable"></h:outputText>
</f:facet>
<h:selectBooleanCheckbox value="#{bean.checked[group.Id]}" />
</h:column>
</h:dataTable>
I have required="true" for GroupId and GroupName columns.
I am not getting where to keep h:messages for each column to display requiredmessage
Please help.
You need to use <h:message> instead to display errors specific to an input element. The <h:messages> will display all messages which are not covered by any <h:message>.
<h:column>
<f:facet name="header">
<h:outputText value="GroupId"></h:outputText>
</f:facet>
<h:outputText value="#{group.Id}" rendered="#{not bean.checked[group.Id]}"></h:outputText>
<h:inputText id="groupId" value="#{group.Id}" rendered="#{bean.checked[group.Id]}" required="true"/>
<h:message for="groupId" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="GroupName"></h:outputText>
</f:facet>
<h:outputText value="#{group.Name}" rendered="#{not bean.checked[group.Id]}"></h:outputText>
<h:inputText id="groupName" value="#{group.Name}" rendered="#{bean.checked[group.Id]}" required="true"/>
<h:message for="groupName" />
</h:column>