I am using p:dataTable that contains another p:dataTable inside a row expansion.
My problem is that I can't edit the inner table since it's in a p:rowExpansion
Works fine without a p:rowExpansion, will stop where edit icon is not clickable.
<h:form>
<p:dataTable var="car" value="#{dtBasicView.cars}">
<f:facet name="header">
Expand rows to see detailed information
</f:facet>
<p:column style="width:16px">
<p:rowToggler />
</p:column>
<p:column headerText="Id">
<h:outputText value="#{car.id}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
<p:rowExpansion>
<p:dataTable var="list" value="#{car.list}" editable="true" style="margin-bottom:20px">
<f:facet name="header">
Row Editing
</f:facet>
<p:column headerText="Id">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{list.id}" /></f:facet>
<f:facet name="input"><p:inputText id="modelInput" value="#{list.id}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:32px">
<p:rowEditor />
</p:column>
</p:dataTable>
</p:rowExpansion>
</p:dataTable>
</h:form>
Related
I have a requirement for an editable datatable that has a single column, lets say brand, that when set to "Other" will replace the editor in the next column, model - with an inputText rather than a selectOne. If any particular car brand is selected then the list of models for that brand is displayed. If "Other" is chosen then they can type in a model in an input text field. I can't seem to get the mechanics of this to work in primefaces using various combinations of rendered and events. Is this sort of inline switching of editing components based on the data in the row possible? I've built a simple example using the primefaces datatable demo for cars (and adding a field Model) to illustrate what I am attempting.
Page snippet
<p:dataTable id="cars1" var="car" value="#{dtEditView.cars1}"
editable="true" style="margin-bottom:20px">
<f:facet name="header">
Row Editing
</f:facet>
<p:ajax event="rowEdit" listener="#{dtEditView.onRowEdit}"
update="cars1" />
<p:ajax event="rowEditCancel" listener="#{dtEditView.onRowCancel}"
update="cars1" />
<p:column headerText="Id">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.id}" />
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput" value="#{car.id}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Year">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.year}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{car.year}" style="width:100%" label="Year" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Brand">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.brand}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{car.brand}" style="width:100%">
<f:selectItems value="#{dtEditView.brands}" var="man"
itemLabel="#{man}" itemValue="#{man}" />
<p:ajax event="change" immediate="true" update="model model_ti"></p:ajax>
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Model">
<p:cellEditor rendered="#{car.brand != 'Other'}">
<f:facet name="output">
<h:outputText value="#{car.model}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{car.model}" style="width:100%"
id="model">
<f:selectItems value="#{dtEditView.getModels(car.brand)}"
var="man" itemLabel="#{man}" itemValue="#{man}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
<p:cellEditor rendered="#{car.brand == 'Other'}">
<f:facet name="output">
<h:outputText value="#{car.model}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{car.model}" style="width:100%"
id="model_ti" />
</f:facet>
</p:cellEditor>
</p:column>
Thanks!
I was able to solve this problem by putting an ID on the cell editor for model, and adding that to the update list when changing brand.
The p:commandLink or p:commandButton inside the p:datagrid's celleditor is not working, when i click the commandLink it redirects me to the same page. Inside the celleditor the commandLink cant find its listener, however when i take it outside the celleditor it works perfectly.
<h:form id="form">
<p:growl id="msgs" showDetail="true"/>
<p:dataTable id="project" var="car" value="#{editdeleteview.proj_rec}" rowKey="#{car.id}" selection="#{editdeleteview.selected_rec}" selectionMode="single" editable="true" style="margin-bottom:20px">
<f:facet name="header">
All Projects
</f:facet>
<p:ajax event="rowEdit" listener="#{editdeleteview.onRowEdit}" update=":form:msgs"/>
<p:ajax event="rowEditCancel" listener="#{editdeleteview.onRowCancel}" update=":form:msgs"/>
<p:column headerText="ID">
<h:outputLabel value="#{car.id}" />
</p:column>
<p:column headerText="Title">
<p:commandLink ajax="false" action="#{editdeleteview.openObjects(car)}" ><h:outputText value="#{car.title}" /></p:commandLink>
<p:cellEditor>
<f:facet name="output"><p:commandLink ajax="false" action="#{editdeleteview.openObjects(car)}" ><h:outputText value="#{car.title}" /></p:commandLink></f:facet>
<f:facet name="input"><p:inputText value="#{car.title}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Description">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{car.description}" /></f:facet>
<f:facet name="input"><p:inputText value="#{car.description}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Insertion Time">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{car.insertionTimestamp}" /></f:facet>
<f:facet name="input"><p:inputText value="#{car.insertionTimestamp}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Close Time">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{car.closeTimestamp}" /></f:facet>
<f:facet name="input"><p:inputText value="#{car.closeTimestamp}" style="width:100%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit" style="width:50px">
<p:rowEditor />
</p:column>
<p:column headerText="Delete">
<p:commandButton id="downloadLink1" value="Delete" ajax="false" class="btn btn-danger" icon="ui-icon-trash" action="#{editdeleteview.delete(car)}">
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
The p:commandLink outside the celleditor under the column title is working perfectly but inside the celleditor the commandLink is not working, the listener in the bean is
public String openObjects(Project p)
{
HttpSession session = SessionUtils.getSession();
session.setAttribute("project_id", p.getId());
session.setAttribute("project_title", p.getTitle());
//session.setAttribute("project_title", "Hamdan");
System.out.println("EditView: "+session.getAttribute("project_title").toString());
return "Objects.xhtml";
}
I have also tried this commandLink in cellEditor doesn't trigger action/actionListener but that didnt worked for me. Any help will be highly appreciated.
just use this and it will work
<f:facet name="output">
<p:commandLink action="#{editdeleteview.openObjects(car)}"
process="#this" immediate="true">
<h:outputText value="#{car.title}" />
<f:setPropertyActionListener
target="#{editdeleteview.selected_rec}" value="#{car}" />
</p:commandLink>
</f:facet>
Try setting immediate="true" on your command link component.
Have a look at this explanation by #BalusC:
Trying to understand immediate="true" skipping inputs when it shouldn't
I'm using primefaces 6.3-SNAPSHOT, this problem still exists, this is how I resolved it :
JSF :
<p:commandLink ajax="false" action="#{editdeleteview.openObjects(car)}" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{car.title}" />
</f:facet>
<f:facet name="input">
<p:inputText onclick="stopEventPropagation(event)" value="#{car.title}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:commandLink>
JAVASCRIPT :
function stopEventPropagation(event){
event.stopPropagation();
return false;
}
I've a scenario Like i'll use cell Edit in Data Table.
I've two cells
I've 1st Cell is Editable
2nd Cell Value needs to be Displayed by doing some arithmetic operations on 1st Cell input (Eg: 2nd cell value =(1st cell value)*.14
My Code is Like
<p:dataTable id="cars2" var="car" value="#{dtEditView.cars2}" editable="true" editMode="cell" widgetVar="cellCars">.
<p:ajax event="cellEdit" listener="#{dtEditView.onCellEdit}" update=":form:msgs" />
<p:column headerText="Cell 1">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{car.id}" /></f:facet>
<f:facet name="input"><p:inputText id="modelInput" value="#{car.id}" style="width:96%"/>
<p:ajax event="keyup" listener="#{car.yearupdate}" update="2:3"></p:ajax></f:facet>
</p:cellEditor>
</p:column>
<p:column id="2" headerText="Cell 2">
<f:facet name="output"><h:outputText id="3" value="#{car.year}" /></f:facet>
</p:column>
</p:dataTable>
I want to Know the Java Code for Listener method code to update the 2nd cell value
In xhtml we need to call the listener (p:ajax tag).
in bean update the other column data in bulk ( iterate over all search records and update corressponding valuefor all recs ) ..
xhtml code like
<p:dataTable id="listDetails" value="${managedBean.searchList}" var="row">
<p:ajax event="rowEdit" listener="#{managedBean.onRowEdit}"
update=":managedBean:messages" />
<p:ajax event="rowEditCancel" listener="#{managedBean.onRowCancel}" update=":managedBean:messages" />
<p:column priority="17"
headerText="col 1"
styleClass="wrap text-right" style="width: 140px;">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{row.val1}" />
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput" value="#{row.val1}"
<p:ajax event="blur" listener="#{managed.valueUpdate}"
update="tempValue></p:ajax>
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column priority="2" headerText="Col 2" exportable="true">
<p:cellEditor>
<f:facet name="output">
<h:outputText id="value" value="#{row.value}" />
</f:facet>
<f:facet name="input">
<h:outputText id="tempValue" value="#{row.tempValue}" />
</f:facet>
</p:cellEditor>
</p:column>
in Bean
public void valueUpdate(){
for (BO bo : searchList) {
if(bo.val1!=null)
{
bo.value = bo.val1+50; // here u can do calc and assihn to the
bo.tempValue=bo.value;
}
}
}
I have a datatable with an input field on each row. I need to know how to get the cost values entered on each row when a save button is pressed?
<p:dataTable value="#{eventCreateEditCostModel.costEntities}" var="eventCost"
rowKey="#{eventCost.eventCostId}"
sortMode="multiple"
resizableColumns="true"
widgetVar="eventCostTable"
rows="10">
<f:facet name="header">
Event Costs Listing
</f:facet>
<p:column headerText="ID">
<h:outputText value="#{eventCost.eventCostId}" />
</p:column>
<p:column headerText="Name">
<h:outputText value="#{eventCost.name}" />
</p:column>
<p:column headerText="Cost">
<pe:inputNumber value="#{eventCost.cost}" decimalPlaces="2" label="Cost"
minValue="0" maxValue="999999999" thousandSeparator="true" title="Cost" symbol="$"/>
</p:column>
</p:dataTable>
My web page looks like this:
<h:form>
<p:dataTable var="car" value="#{tableBean.carsSmall}">
<f:facet name="header">
Expand rows to see detailed information
</f:facet>
<p:column style="width:16px">
<p:rowToggler />
</p:column>
<p:column style="width:250px">
<f:facet name="header">
Model
</f:facet>
<h:outputText value="#{car.model}" />
</p:column>
<p:column style="width:250px">
<f:facet name="header">
Year
</f:facet>
<h:outputText value="#{car.year}" />
</p:column>
<p:rowExpansion>
<p:fieldset legend="Detail">
<p:dataTable value="#{car.colors}" var="color">
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{color.disable}" />
</f:facet>
<f:facet name="input">
<h:selectBooleanCheckbox value="#{color.disable}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit">
<p:rowEditor />
</p:column>
</p:dataTable>
</p:fieldset>
</p:rowExpansion>
</p:dataTable>
</h:form>
This component is automatically updating the wrong values in database, for example it is setting false for the color.disable property upon just expanding the row.
I am using:
JSF 2.0.9
Primefaces 2.2.1