I would like to know how to filter so that only the patents of vehicles that are available appear.
<p:column headerText="Patent car">
<h:outputText value="#{v.fkcar.patent}"/>
</p:column>
In the database there is a table called State with 2 income
id_state 1 ---- name_state Available and id_state 2 ---- name_state Not available
What I need is that only the patents of the vehicles that have the State in Available are shown
The State table has its respective Bean
I hope you can help me: D
Entry code Rent
<h:head>
<title>Realizar Alquiler</title>
<h:outputStylesheet library="css" name="style.css" />
</h:head>
<h:body>
<h2>Realizar Alquiler</h2>
<h:form id="fv">
<h:panelGrid columns="1" styleClass="panelGridCenter">
<h:outputText value="Precio"/>
<p:inputText value="#{alquilerBean.precio}" required="true"/>
<p:outputLabel for="datetime" value="Fecha" />
<p:calendar id="datetime" value="#{alquilerBean.fecha3}" pattern="MM/dd/yyyy HH:mm:ss" required="true"/>
Cliente
<p:selectOneMenu value="#{alquilerBean.cliente.idCliente}">
<f:selectItems value="#{clienteBean.cliente}" var="e" itemLabel="#{e.rut}" itemValue="#{e.idCliente}"/>
</p:selectOneMenu>
Patente
<p:selectOneMenu value="#{alquilerBean.vehiculo.idVehiculo}">
<f:selectItems value="#{vehiculoBean.vehiculos}" var="o" itemLabel="#{o.patente}" itemValue="#{o.idVehiculo}"/>
</p:selectOneMenu>
¿Entregado?
<p:selectOneMenu value="#{alquilerBean.entregado.idEntregado}">
<f:selectItems value="#{entregadoBean.entregado}" var="o" itemLabel="#{o.nombreEntregado}" itemValue="#{o.idEntregado}"/>
</p:selectOneMenu>
<br/>
<h:outputText value=""/>
<p:commandButton actionListener="#{alquilerBean.crear()}" value="Agregar Alquiler" update="fv"/>
</h:panelGrid>
<br/>
<p:dataTable value="#{alquilerBean.alquiler}" var="v" emptyMessage="No hay registros" >
<p:column headerText="Fecha">
<h:outputText value="#{v.fecha}"/>
</p:column>
<p:column headerText="Precio">
<h:outputText value="#{v.precio}"/>
</p:column>
<p:column headerText="Entregado">
<h:outputText value="#{v.fkEntregado.nombreEntregado}"/>
</p:column>
<p:column headerText="Rut Cliente">
<h:outputText value="#{v.fkCliente.rut}"/>
</p:column>
<p:column headerText="Patente Auto"
<h:outputText value="#{v.fkVehiculo.patente}"/>
</p:column>
</p:column>
<f:facet name="footer">
Se han alquilado #{alquilerBean.alquiler.size()} Vehiculos.
</f:facet>
</p:dataTable>
</h:form>
<br/>
<h:form>
<h:commandLink action="index">
<h:graphicImage value="resources/images/atras2.png" />
</h:commandLink>
</h:form>
</h:body> </html>
Here is the state bean code.
private int id_entregado;
private String nombre_entregado;
public EntregadoBean() {
}
public String crear(){
Entregado e = new Entregado();
e.setNombreEntregado(nombre_entregado);
entregadoFacade.create(e);
return "#";
}
public List<Entregado> getEntregado(){
return entregadoFacade.findAll();
}
public EntregadoFacadeLocal getEntregadoFacade() {
return entregadoFacade;
}
public void setEntregadoFacade(EntregadoFacadeLocal entregadoFacade) {
this.entregadoFacade = entregadoFacade;
}
public int getId_entregado() {
return id_entregado;
}
public void setId_entregado(int id_entregado) {
this.id_entregado = id_entregado;
}
public String getNombre_entregado() {
return nombre_entregado;
}
public void setNombre_entregado(String nombre_entregado) {
this.nombre_entregado = nombre_entregado;
}
}
Related
Currently I am facing a datatable rendering issue.
I have a datatable with order details with row expansion. When I click on the expansion arrow it shows line item details in another datatable.
Also have a + button to add new order and one more button inside line item table to add more line items.
[![enter image description here][1]][1]
When I click on row edit under the line item table (This is under row expansion) the row open it edit mode,but when I click on tick icon the same lineitem updated but one duplicate lineitem is shown with parent table(order) and existing parrent linetable disappeard.But when I refresh the page this duplicate row is removed.
[![enter image description here][2]][2]
[![enter image description here][3]][3]
[![enter image description here][4]][4]
After clicking the arrow it appears like this
[![enter image description here][5]][5]
Is this a know issue in primefaces 11.Is the row expansion is only for view purpose?
XHTML
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>PrimeFaces Test</title>
<h:outputScript name="test.js"/>
<h:outputStylesheet name="test.css"/>
</h:head>
<h:body>
<h1>#{testView.string}</h1>
<h:form id="form">
<div class="card">
<h5>Row Editing</h5>
<p:dataTable id="order" var="order" value="#{mainBean.orderVOs}"
editable="true" style="margin-bottom:20px" styleClass="myclass"
rowKey="#{order.orderNo}" rowIndexVar="orderIndex" showGridlines="true">
<p:ajax event="rowEdit" listener="#{mainBean.onRowEdit(order)}"
update=":form:order"/>
<p:ajax event="rowEditCancel"
listener="#{mainBean.onRowCancel(order)}" update=":form:order"/>
<p:column style="width:2rem">
<p:rowToggler/>
</p:column>
<p:column style="width:6rem">
<f:facet name="header">
<p:commandButton value="+"
styleClass="rounded-button ui-button-plus"
actionListener="#{mainBean.addOrder()}" update="order"
oncomplete="editLastDatatableRow();"/>
</f:facet>
<p:rowEditor editTitle="Edit Row" cancelTitle="Cancel Edit"
saveTitle="Save Row"/>
</p:column>
<p:column headerText="OrderNo">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{order.orderNo}"/>
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput" value="#{order.orderNo}"
style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="AddressLine1">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{order.addressLine1}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{order.addressLine1}" style="width:100%"
label="Name"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="GrandTotal">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{order.totalAmt}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{order.totalAmt}" style="width:100%"
label="Name"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:rowExpansion>
<div class="card">
<h5>Row Editing</h5>
<p:dataTable id="lineItem" var="line" value="#{order.lineItems}"
editable="true" style="margin-bottom:20px"
rowKey="#{ineItem.productDescription}" rowIndexVar="lineIndex"
styleClass="myClass${orderIndex}" size="small" showGridlines="true">
<p:ajax event="rowEdit"
listener="#{mainBean.onRowEditLine(order,line)}"
update="form:order:${orderIndex}:lineItem form:order"/>
<p:ajax event="rowEditCancel"
listener="#{mainBean.onRowCancelLine(order,line)}"
update="form:order:${orderIndex}:lineItem"/>
<p:column style="width:6rem">
<f:facet name="header">
<p:commandButton value="+"
styleClass="rounded-button ui-button-plus"
actionListener="#{mainBean.addLine(order)}"
update="form:order:${orderIndex}:lineItem"
oncomplete="editLastDatatableRowLine(${orderIndex});"/>
</f:facet>
<p:rowEditor editTitle="Edit Row" cancelTitle="Cancel Edit"
saveTitle="Save Row"/>
</p:column>
<p:column headerText="productDescription">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{line.productDescription}"/>
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput"
value="#{line.productDescription}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="quantity">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{line.quantity}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{line.quantity}" style="width:100%"
label="Name"/>
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</div>
</p:rowExpansion>
</p:dataTable>
</div>
<script type="text/javascript">
function editLastDatatableRow() {
jQuery('.myclass .ui-datatable-data tr').first().find(
'span.ui-icon-pencil').each(function() {
jQuery(this).click()
});
}
function editLastDatatableRowLine(index) {
jQuery('.myClass'+index+" "+ '.ui-datatable-data tr').first().find(
'span.ui-icon-pencil').each(function() {
jQuery(this).click()
});
}
</script>
</h:form>
</h:body>
</html>
Bean
package org.primefaces.test;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
#Named
#ViewScoped
public class MainBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 7536893702695858952L;
List<OrderVO> orderVOs;
private List<LineVO> lineItems;
#PostConstruct
public void init() {
orderVOs = new ArrayList<OrderVO>();
lineItems = new ArrayList<LineVO>();
LineVO l1 = new LineVO("desc1", "d", "s", "s", "d");
lineItems.add(l1);
OrderVO orderVO = new OrderVO();
orderVO.setOrderNo("10000");
orderVO.setAddressLine1("address1");
orderVO.setLineItems(lineItems);
orderVOs.add(orderVO);
}
public List<LineVO> getLineItems() {
return lineItems;
}
public void setLineItems(List<LineVO> lineItems) {
this.lineItems = lineItems;
}
public List<OrderVO> getOrderVOs() {
return orderVOs;
}
public void setOrderVOs(List<OrderVO> orderVOs) {
this.orderVOs = orderVOs;
}
public void onRowEdit(OrderVO orderVO) {
}
public void onRowCancel(OrderVO orderVO, LineVO lineVO) {
}
public void onRowEditLine(OrderVO orderVO, LineVO lineVO) {
}
public void onRowCancelLine(OrderVO orderVO, LineVO lineVO) {
}
public void addOrder() {
OrderVO orderVO = new OrderVO();
orderVOs.add(0, orderVO);
}
public void addLine(OrderVO orderVO) {
LineVO lineVO = new LineVO("dd", "jjj", "kk", "ooo", "iiiii");
if (orderVO.getLineItems() == null) {
orderVO.setLineItems(new ArrayList<LineVO>());
}
orderVO.getLineItems().add(0, lineVO);
}
}
Reproucable code present here .github.com/akhiltm20/primefaces-rowExpansion_innerTableIssue
[1]: https://i.stack.imgur.com/LaiIw.png
[2]: https://i.stack.imgur.com/GsK5J.png
[3]: https://i.stack.imgur.com/YYrcM.png
[4]: https://i.stack.imgur.com/9IvTZ.png
[5]: https://i.stack.imgur.com/BwA81.png
Hi I have a datatable which publishes the information very well, however, for this particular case something happens, in one column have a Boolean value that can only be true once the entire table of the database, so if I detect someone puts another record as true then update the above false and so the cycle ends. The update is done right in the database but when I want to refresh the datatable to also show the modification of another record, and does not work ...
this is my xhtml:
<ui:composition 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"
xmlns:p="http://primefaces.org/ui"
template="template.xhtml">
<ui:define name="content">
<h:form id="someForm">
<p:growl id="msg" showDetail="true" life="3000" autoUpdate="true"/>
<p:panelGrid style="100%">
<p:row>
<p:column style="350px">title 1</p:column>
<p:column>
<p:inputText id="cveSituacion" value="#{someBean.cve}" maxlength="20" />
</p:column>
</p:row>
<p:row>
<p:column style="350px">title 2</p:column>
<p:column>
<p:inputText id="name" value="#{someBean.name}" />
</p:column>
</p:row>
<p:row>
<p:column colspan="2">
<p:spacer></p:spacer>
</p:column>
</p:row>
<p:row>
<p:column>
<p:commandButton action="#{someBean.searchAll}" value="Search All" ajax="true" update="someForm" immediate="true"/>
</p:column>
</p:row>
<p:row>
<p:column colspan="4">
<p:spacer></p:spacer>
</p:column>
</p:row>
<p:row>
<p:column colspan="4">
<p:dataTable id="resultSearch" var="someVariable" value="#{someBean.listOfData}" editable="true">
<p:ajax event="rowEdit" listener="#{someBean.onEdit}" update=":someForm:msg :someForm:resultSearch" />
<p:ajax event="rowEditCancel" listener="#{someBean.onCancel}" update=":someForm:msg" />
<p:column headerText="Clave Sit Ticket" sortBy="#{someVariable.cve}">
<h:outputText value="#{someVariable.cve}" />
</p:column>
<p:column headerText="Name" sortBy="#{someVariable.name}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{someVariable.name}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{someVariable.name}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Description" sortBy="#{someVariable.desc}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{someVariable.desc}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{someVariable.desc}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Sit" sortBy="#{someVariable.situation}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{someVariable.situation}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu id="cboBox" value="#{someVariable.situation}" style="width=200px">
<f:selectItems value="#{commonCboBean.listOfData}" var="cboBox" itemValue="#{cboBox.cve}" itemLabel="#{cboBox.desc}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Default" sortBy="#{someVariable.BSitDefault}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{someVariable.BSitDefault}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu id="cboVoF" value="#{someVariable.BSitDefault}" style="width=200px">
<f:selectItems value="#{fovBean.fov}" var="fov" itemValue="#{fov.bandera}" itemLabel="#{fov.descripcion}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit" style="width:50px;" >
<p:rowEditor />
</p:column>
</p:dataTable>
</p:column>
</p:row>
</p:panelGrid>
</h:form>
</ui:define>
</ui:composition>
this is my backing bean:
#SuppressWarnings("serial")
#ManagedBean
#ViewScoped
public class SomeBean implements Serializable{
private String cve;
private String name;
private List<SomeObject> listOfData;
private SomeObject newDefault;
private SomeObject sitDefault;
private RequestContext context = null;
... some methods ....
public void onEdit(RowEditEvent event) {
/*
IF I JUST UPDATE DATA LIKE THIS: updateData(SomeObject obj) THE DATATABLE
IS UPDATED CORRECTLY, BUT IF A LEAVE THE NEXT CODE, IT DOESNT
*/
newDefault = (SomeObject)event.getObject();
if( newDefault.getFlag.equals(Constants.V) ){
List<SomeObject> list = ejb.find(newDefault.getCve);
if( list == null || list.size() <= 0 ){
updateData( newDefault );
}else{
if( list.get(0).getCve().equals( newDefault.getCve() ) ){
updateData( newDefault );
}else{
SomeObject sitDefault = list.get(0);
if( ejb.update(sitDefault) > 0 ){
updateData(newDefault);
searchAll();
}else
FacesContext.getCurrentInstance().addMessage( null,
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"sometitle",
"some messsage")
);
}
}
}else{
updateData( newDefault );
}
}
public void updateNewDefault(){
sitDefault.setBSitDefault("F");
if( ejb.update(sitDefault) > 0 ){
updateData(newDefault);
searchAll();
}else
FacesContext.getCurrentInstance().addMessage( null,
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"error",
"some error has ocurred")
);
}
private void updateData(SomeObject obj){
int result = ejb.update( obj );
if( result > 0 ){
FacesContext.getCurrentInstance().addMessage( null,
new FacesMessage(FacesMessage.SEVERITY_WARN,
"OK",
"OK"
)
);
searchAll();
}else{
FacesContext.getCurrentInstance().addMessage( null,
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"ERROR",
"SOME ERROR")
);
}
}
public void searchAll(){
setListOfData( ejb.findAll() );
}
/******** getters & setters *************/
}
Please help!!! took a while stuck with it :(
I have two primefaces dataTables. The first show the instances of a MainEntity.
The second one show a list of Words (just strings) associated with the selected MainEntity on the first datatable.
The printscreen illustrates what I mean.
My problem is, when I edit a string on the Word List, my listener method won't receive the new value. In fact, when I call the event.getNewValue() method, I get old value.
What am I missing?
I'm using JavaServer Faces 2.2, Primefaces 5.0 and Spring Framework 4.0.3.
Thanks in advance for any help.
The code for the xhtml, the managed bean and the MainEntity are as follows:
mainEntity.xhtml:
<h:body>
<h:form id="mainEntityForm">
<p:panelGrid columns="1" fullPage="true" id="dashboard">
<f:facet name="header">
<h2>MainEntity Table</h2>
</f:facet>
<p:panel>
<f:facet name="header">
MainEntity List
<p:commandButton value="New MainEntity"
actionListener="#{mainEntityController.createMainEntityDialog}"
styleClass="header-button">
<p:ajax event="dialogReturn" update=":mainEntityForm:mainEntityTable" />
</p:commandButton>
</f:facet>
<p:dataTable id="mainEntityTable" var="mainEntity" value="#{mainEntityController.mainEntities}"
editable="true" editMode="cell" widgetVar="cellMainEntity"
selectionMode="single" selection="#{mainEntityController.selectedMainEntity}"
rowKey="#{mainEntity.id}" tableStyle="width:auto">
<p:ajax event="rowSelect" update=":mainEntityForm:stringGrid :mainEntityForm:entityAGrid :mainEntityForm:entityBGrid" />
<p:ajax event="cellEdit" listener="#{mainEntityController.onEditMainEntity}" update=":mainEntityForm:mainEntityTable" />
<p:column headerText="ID">
<h:outputText value="#{mainEntity.id}" />
</p:column>
<p:column headerText="Name">
<p:cellEditor>
<f:facet name="output">
<h:outputText id="nameOutput" value="#{mainEntity.name}" />
</f:facet>
<f:facet name="input">
<h:inputText id="atyInput" value="#{mainEntity.qty}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Commands">
<p:commandButton title="Remove MainEntity" icon="ui-icon-trash"
actionListener="#{mainEntityController.deleteMainEntity(mainEntity)}"
update=":mainEntityForm:mainEntityTable" />
</p:column>
</p:dataTable>
</p:panel>
<p:panelGrid fullPage="true" id="mainEntityDetail">
<f:facet name="header">
<p:row>
<p:column colspan="4">
<h2>MainEntity Detail</h2>
</p:column>
</p:row>
</f:facet>
<p:row>
<p:column>
<p:panel>
<f:facet name="header">
Word List
<p:commandButton value="New Word"
actionListener="#{mainEntityController.addNewWord()}"
styleClass="header-button"
update=":mainEntityForm:wordGrid">
</p:commandButton>
</f:facet>
<p:dataTable id="wordGrid" var="word"
value="#{mainEntityController.selectedMainEntity.wordList}"
tableStyle="width:auto" editable="true" editMode="cell" widgetVar="cellWord">
<p:ajax event="cellEdit" listener="#{mainEntityController.onEditWord}" />
<p:column headerText="Word">
<p:cellEditor>
<f:facet name="output">
<h:outputText id="wordOutput" value="#{word}" />
</f:facet>
<f:facet name="input">
<h:inputText id="wordInput" value="#{word}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Commands">
<p:commandButton title="Remove Word"
icon="ui-icon-trash"
actionListener="#{mainEntityController.removeWord(word)}"
update=":mainEntityForm:wordGrid" />
</p:column>
</p:dataTable>
</p:panel>
</p:column>
</p:row>
</p:panelGrid>
</p:panelGrid>
</h:form>
</h:body>
MainEntityController.java (managed bean):
#ManagedBean
#SessionScoped
public class MainEntityController {
//...
private MainEntity selectedMainEntity;
public List<MainEntity> mainEntities;
//...
public MainEntity getSelectedMainEntity(){
return selectedMainEntity;
}
public void setSelectedMainEntity(MainEntity mainEntity){
this.selectedMainEntity = mainEntity;
}
//...
public void onEditWord(CellEditEvent event) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
if(newValue != null && !newValue.equals(oldValue)) {
// THE PROBLEM IS HERE
// I NEVER ACTUALLY REACH THIS CODE
// newValue is always equal to oldValue!
FacesContext context = FacesContext.getCurrentInstance();
String word = context.getApplication().evaluateExpressionGet(context, "#{word}", String.class);
System.out.println(newValue);
System.out.println(word);
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Word Changed", "Old: " + oldValue + ", New:" + newValue);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
}
MainEntity.java:
#Entity
public class MainEntity {
#Id
private String id;
#ElementCollection(fetch=FetchType.EAGER)
#CollectionTable(
name="MainEntity_Word",
joinColumns = #JoinColumn(name = "id", referencedColumnName="id")
)
#Column(name = "word")
private Set<String> wordList;
//...
public void addWord(String word) {
this.wordList.add(word);
}
public void removeWord(String word) {
this.wordList.remove(word);
}
public Set<String> getWordList() {
return wordList;
}
public void setWordList(Set<String> wordList) {
this.wordList = wordList;
}
}
Change
<h:inputText id="wordInput" value="#{word}" />
to
<p:inputText id="wordInput" value="#{word}" />
or
<h:inputText id="wordInput" value="#{word}" >
<p:ajax event="change" process="#this"/>
</h:inputText>
You need to ajaxify the input component, and at last update the outputText component.
Edited:
change this column :
<p:column headerText="Word" >
<p:cellEditor>
<f:facet name="output">
<h:outputText id="wordOutput" value="#{word}" />
</f:facet>
<f:facet name="input">
<h:inputText id="wordInput" value="#{word}" />
</f:facet>
</p:cellEditor>
</p:column>
to
<p:column headerText="Word" >
<p:cellEditor>
<f:facet name="output">
<h:outputText id="wordOutput" value="#{word}" />
</f:facet>
<f:facet name="input">
<p:inputText id="wordInput" value="#{word}" >
<p:ajax event="change" update="wordOutput" />
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
Edit 2 :
From Chapter 24 Introduction to the Java Persistence API
If an entity instance be passed by value as a detached object, such as
through a session bean’s remote business interface, the class must
implement the Serializable interface.
I finally got it working.
I suspected of the String immutable nature and what I did was to encapsulate the 'word' in a class like the following:
public class Word {
private String word;
Word (String word) {
this.setWord(word);
}
public String getWord() {
return this.word;
}
public void setWord(String word) {
this.word = word;
}
}
After that, I also had to create a set inside the managed bean (controller) to hold the set of words, like 'private Set managedWordList;'.
I also changed the getter for the list, inside the managed bean, to convert from the String set to a Word set like:
public Set<Word> getWordList() {
if (this.selectedMainEntity != null){
this.wordList = new HashSet<Word>();
for (String word : this.selectedMainEntity.getWordList()) {
this.wordList.add(new Word(word));
}
}
return this.wordList;
}
Finally, I changed the dataTable to reference the new set. From:
<p:dataTable ... value="#{mainEntityController.selectedMainEntity.wordList}"... />
To:
<p:dataTable ... value="#{mainEntityController.wordList}"... />
And only then I got it to work as I expected.
I have I datatable. I want to disable the commandlinks when I go to rowedit mode by pressing on the edit link:
JSF:
<p:growl id="messages" showDetail="true" />
<p:dataTable value="#{employeeBean.employees}"
var="employee" id="employeeDTable"
editable="true">
<p:ajax event="rowEdit" listener="#{employeeBean.edit}" update=":employeeForm:messages" />
<p:ajax event="rowEditCancel" listener="#{employeeBean.undoEdit}" update=":employeeForm:messages" />
<p:column id="id" headerText="Id">
<h:outputText value="#{employee.id}"/>
</p:column>
<p:column id="firstname" headerText="Voornaam">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{employee.firstName}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{employee.firstName}" label="firstname"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column id="editButtonsId" headerText="">
<p:rowEditor />
</p:column>
<p:column id="cashbook" headerText="">
<div align="center">
<h:panelGroup id="cashbookPanel">
<p:commandLink title="Cashbook" update="employeeDTable" styleClass="ui-icon ui-icon-cart" /> <!-- DISABLE THIS IN EDITMODE -->
</h:panelGroup>
</div>
</p:column>
</p:dataTable>
CODE:
#Component("employeeBean")
#Scope("session")
public class EmployeeBean {
List<EmployeeModel> employees;
private EmployeeModel employeeModel;
#Autowired
private EmployeeService employeeService;
public EmployeeBean() {
if(employeeService == null){
employeeService = ServiceRepository.getInstance().getEmployeeService();
}
employeeModel = new EmployeeModel();
if(employees == null){
this.employees = this.employeeService.getEmployees();
}
}
public void edit(RowEditEvent event) {
EmployeeModel employee = ((EmployeeModel) event.getObject());
EmployeeModel updatedEmployee = this.employeeService.updateEmployee(employee);
if(updatedEmployee != null){
FacesMessage msg = new FacesMessage("Employee Edited", employee.getFirstName());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
public void undoEdit(RowEditEvent event) {
}
public EmployeeModel getEmployeeModel() {
return employeeModel;
}
public void setEmployeeModel(EmployeeModel employeeModel) {
this.employeeModel = employeeModel;
}
public List<EmployeeModel> getEmployees() {
return employees;
}
public void setEmployees(List<EmployeeModel> employees) {
this.employees = employees;
}
}
Put your link and disabled link inside a <p:cellEditor/>
<p:column id="cashbook" headerText="">
<p:cellEditor>
<f:facet name="output">
<div align="center">
<h:panelGroup id="cashbookPanel">
<p:commandLink title="Cashbook" update="employeeDTable" styleClass="ui-icon ui-icon-cart" />
</h:panelGroup>
</div>
</f:facet>
<f:facet name="input">
<div align="center">
<h:panelGroup id="cashbookPanel">
<p:commandLink disabled="true" title="Cashbook" update="employeeDTable" styleClass="ui-icon ui-icon-cart" />
</h:panelGroup>
</div>
</f:facet>
</p:cellEditor>
</p:column>
I want to implement a table with row editing.
I found this exemple in the showcase, but I get this error evry time :
javax.servlet.ServletException: Setter not found for property class
java.lang.IllegalArgumentException: Setter not found for property
class
My xhtml
<a4j:status onstart="#{rich:component('statPane')}.show()"
onstop="#{rich:component('statPane')}.hide()" />
<h:form id="form">
<rich:dataScroller for="dataTableId" maxPages="8" />
<rich:extendedDataTable id="dataTableId" rows="200"
value="#{declarationReglementaireModel.detailCurrentDecReg.decReg.listLigneTa3SDTO}"
var="ligneTA3" frozenColumns="2"
style="height:300px; width:800px;" selectionMode="none">
<rich:column width="35px">
<h:panelGrid columns="1" cellpadding="2">
<a4j:commandLink class="lien_detail" render="editGrid"
execute="#this"
oncomplete="#{rich:component('editPane')}.show()">
<span class="icone icone-edit icone-align-center" />
<a4j:param value="1"
assignTo="#{modifDecRegTa3Model.currentLigneTa3Index}" />
<f:setPropertyActionListener target="#{modifDecRegTa3Model.editedRow}"
value="#{ligne}" />
</a4j:commandLink>
</h:panelGrid>
</rich:column>
<rich:column width="150px" sortBy="#{ligneTA3.idTitre}"
sortOrder="ascending">
<f:facet name="header">Référence Titre</f:facet>
<h:outputText value="#{ligneTA3.idTitre}">
</h:outputText>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="a" />
</f:facet>
<h:outputText value="#{ligneTA3.vlColA}">
</h:outputText>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="b" />
</f:facet>
<h:outputText value="#{ligneTA3.vlColB}">
</h:outputText>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="c" />
</f:facet>
<h:outputText value="#{ligneTA3.vlColC}">
</h:outputText>
</rich:column>
<rich:dataScroller for="dataTableId" maxPages="8" />
<rich:popupPanel id="statPane" autosized="true">
Please wait...
</rich:popupPanel>
<rich:popupPanel header="Modifier ligne" id="editPane" domElementAttachment="parent" width="400" height="170">
<h:panelGrid columns="3" id="editGrid">
<h:outputText value="vlColA" />
<h:outputText value="#{modifDecRegTa3Model.editedRow.vlColA}" />
<h:panelGroup />
<h:outputText value="vlColB" />
<h:outputText value="#{modifDecRegTa3Model.editedRow.vlColB}" />
<h:panelGroup />
<h:outputText value="vlColC" />
<h:inputText value="#{cmodifDecRegTa3Model.editedRow.vlColC}" required="true" requiredMessage="Price is required" id="price"/>
</h:panelGrid>
<a4j:commandButton value="Store" action="#{rechercheDecRgltCtrl.validerModifications}" render="table" execute="editPane"
oncomplete="if (#{facesContext.maximumSeverity==null}) {#{rich:component('editPane')}.hide();}" />
<a4j:commandButton value="Cancel" onclick="#{rich:component('editPane')}.hide(); return false;" />
</rich:popupPanel>
</h:form>
</h:panelGrid>
</h:form>
My Model
#ManagedBean(name="modifDecRegTa3Model")
#SessionScoped
public class ModifDecRegTa3Model {
private static final long serialVersionUID = 1L;
private LigneTa3DTO currentElement;
private Integer selectedPage;
private int currentLigneTa3Index;
private LigneTa3DTO editedRow;
public ModifDecRegTa3Model() {
super();
}
public LigneTa3DTO getCurrentElement() {
return currentElement;
}
public void setCurrentElement(LigneTa3DTO currentElement) {
this.currentElement = currentElement;
}
public Integer getSelectedPage() {
return selectedPage;
}
public void setSelectedPage(Integer selectedPage) {
this.selectedPage = selectedPage;
}
public int getCurrentLigneTa3Index() {
return currentLigneTa3Index;
}
public void setCurrentLigneTa3Index(int currentLigneTa3Index) {
this.currentLigneTa3Index = currentLigneTa3Index;
}
public LigneTa3DTO getEditedRow() {
return editedRow;
}
public void setEditedRow(LigneTa3DTO editedRow) {
this.editedRow = editedRow;
}
}
This is probably related to your bad attribute :
<a4j:commandLink class="lien_detail" />
There is no attribute class for the component a4j:commandLink you should use styleClass instead.