I have implemented primefaces roweditor for components like inputtext,autocomplete . I am trying to implement for selectmanymenu but could not get the result. If i use cell editor then i need to use input and output value should refer the same . Here selectmanymenu value would be the list not a single variable. So i am not sure how to handle it.
I would like know the proper implementation of p:selectManyMenu with p:cellEditor. I am not sure that we have option to do this also.
I have searched in stackoverflow as well as in google, did not get any answers for this.
Please help me out.
Below is the code details
<p:dataTable
value="#{projectViewBean.projectListToEdit}"
editable="true" var="proj" id="editProjLst">
<p:ajax event="rowEdit" listener="#{projectEntryBean.onEdit}"/>
<p:ajax event="rowEditInit" listener="#{projectEntryBean.onRowEditInit}"></p:ajax>
<p:column headerText="Project Status" id="sts">
<p:cellEditor>
<f:facet name="output">
<p:outputLabel value="#{proj.projectStatus}"></p:outputLabel>
</f:facet>
<f:facet name="input">
<p:selectOneMenu
value="#{proj.projectStatus}"
id="pjstval">
<f:selectItems value="#{projectEntryBean.projectStatusList}"
id="pjstlst" />
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Phase" id="dbphase">
<p:cellEditor>
<f:facet name="output">
<p:outputLabel value="#{proj.projectPhaseValue}"></p:outputLabel>
</f:facet>
<f:facet name="input">
<p:autoComplete
completeMethod="#{projectEntryBean.autoSearchProjectPhase}"
value="#{proj.projectPhaseValue}"
dropdown="true" scrollHeight="200" emptyMessage="No Phase Found"
minQueryLength="1" forceSelection="true"></p:autoComplete>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Project Manager" id="pjtmgr">
<p:cellEditor id="pm">
<f:facet name="output">
<p:outputLabel value="#{projectEntryBean.pjtView.projectUserList}"></p:outputLabel>
</f:facet>
<f:facet name="input">
<p:selectManyMenu
value="#{proj.projectManager}"
id="projectmanagerval">
<f:selectItems value="#{projectEntryBean.pjtView.projectUserList}"
id="pmlst" />
</p:selectManyMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:32px">
<p:rowEditor />
</p:column>
</p:dataTable>
Finally i am able to achieve it by using converter. It might be helpful for someone. Please see the solution
<p:column headerText="Project Manager" id="pjtmgr">
<p:cellEditor id="pm">
<f:facet name="output">
<p:outputLabel value="#{proj.projectManager}">
<f:converter converterId="vendorConverter"></f:converter>
</p:outputLabel>
</f:facet>
<f:facet name="input">
<p:selectManyMenu
value="#{proj.projectManager}"
id="projectmanagerval">
<f:selectItems value="#{projectEntryBean.pjtView.projectUserList}"
id="pmlst" />
</p:selectManyMenu>
</f:facet>
</p:cellEditor>
</p:column>
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 element where I use a rowEditor. Additionally it is possible to add a new record which is implemented as inputFields in the footer of the table. All elements are validated. The problem is, that when a user hits the rowEditor the validation complains that the values for a new record are not set.
How can I avoid that the new record fields are being validated when the rowEditor is clicked?
I fiddled around a bit with proccess & immediate on the ajax events but I'm not able to figure this out. Is this possible and if yes, how? I'm thankful for help.
<p:dataTable var="contact"
value="#{data.activeCustomer.contacts.toArray()}"
id="contactsTable"
emptyMessage="#{ivy.cms.co('/Translations/Administration/noRecordsFoundSearch')}"
editable="true">
<p:ajax event="rowEdit" listener="#{logic.onEdit(contact)}" />
<p:ajax event="rowEditCancel" listener="#{logic.onCancel}" />
<f:facet name="header">
#{ivy.cms.co('/Translations/Administration/Contacts/labelContacts')}
</f:facet>
<p:column
headerText="#{ivy.cms.co('/Translations/Administration/Contacts/prename')}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{contact.prename}" />
</f:facet>
<f:facet name="input">
<p:inputText required="true"
requiredMessage="#{ivy.cms.co('/Translations/CustomerAdministration/Validation/enterPrename')}"
value="#{contact.prename}"></p:inputText>
</f:facet>
</p:cellEditor>
<f:facet name="footer">
<p:inputText required="true"
requiredMessage="#{ivy.cms.co('/Translations/CustomerAdministration/Validation/enterPrename')}"
value="#{data.contactPrename}" />
</f:facet>
</p:column>
<p:column
headerText="#{ivy.cms.co('/Translations/Administration/Contacts/surname')}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{contact.surname}" />
</f:facet>
<f:facet name="input">
<p:inputText required="true"
requiredMessage="#{ivy.cms.co('/Translations/CustomerAdministration/Validation/enterSurname')}"
value="#{contact.surname}"></p:inputText>
</f:facet>
</p:cellEditor>
<f:facet name="footer">
<p:inputText required="true"
requiredMessage="#{ivy.cms.co('/Translations/CustomerAdministration/Validation/enterSurname')}"
value="#{data.contactSurname}" />
</f:facet>
</p:column>
<p:column
headerText="#{ivy.cms.co('/Translations/Administration/Contacts/phone')}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{contact.phone}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{contact.phone}"
requiredMessage="#{ivy.cms.co('/Translations/CustomerAdministration/Validation/enterPhone')}"
required="true"></p:inputText>
</f:facet>
</p:cellEditor>
<f:facet name="footer">
<p:inputText
requiredMessage="#{ivy.cms.co('/Translations/CustomerAdministration/Validation/enterPhone')}"
required="true" value="#{data.contactPhone}" />
</f:facet>
</p:column>
<p:column
headerText="#{ivy.cms.co('/Translations/Administration/Contacts/email')}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{contact.email}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{contact.email}" required="true"
requiredMessage="#{ivy.cms.co('/Translations/CustomerAdministration/Validation/enterEmail')}">
<f:validator validatorId="EmailValidator" />
</p:inputText>
</f:facet>
</p:cellEditor>
<f:facet name="footer">
<p:inputText required="true"
requiredMessage="#{ivy.cms.co('/Translations/CustomerAdministration/Validation/enterEmail')}"
value="#{data.contactEmail}">
<f:validator validatorId="EmailValidator" />
</p:inputText>
</f:facet>
</p:column>
<p:column style="width: 6%"
headerText="#{ivy.cms.co('/Translations/CustomerAdministration/actionsColumnTitle')}">
<p:rowEditor />
<p:commandLink styleClass="ui-icon ui-icon-trash"
actionListener="#{logic.deleteContact(contact)}"
icon="ui-icon-trash" update=":#{p:component('contactForm')}"
immediate="true" />
<f:facet name="footer">
<h:commandButton
value="#{ivy.cms.co('/Translations/Administration/Contacts/ButtonAddContact')}"
actionListener="#{logic.addContact}" />
</f:facet>
</p:column>
</p:dataTable>
</h:form>
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