I'm using Primesfaces' Incell editing in a p:dataTable.
When choosing a new id in the selectOneMenu, I'd like to update the 'name' field in the same row without having to wait until the user presses the ok check mark for the name field to be updated. Objects' name attribute is updated in bean.idEdited(object).
I was hoping I could just use f:ajax render="name" to update the other field like this:
<h:form>
<p:dataTable var="object" value="#{bean.objects}"
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{bean.objectId}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{bean.objectId}">
<f:selectItems value="#{bean.objectIds}" />
<f:ajax listener="#{bean.idEdited(object)}"
render="name" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<h:outputText id="name" value="#{object.name}" />
</p:column>
</p:dataTable>
</h:form>
When I try render="name" I get this:
SEVERE: Error Rendering View[/logicalAddress.xhtml]
java.lang.IllegalStateException: PWC3999: Cannot create a session after the response has been committed
at org.apache.catalina.connector.Request.doGetSession(Request.java:2867)
...
Using
Primesfaces 2.2.1
Netbeans 7.0.1
JSF Bundled with Netbeans
Ideas, other ways or salvation?
edit: p:ajax renders the same result.
This is happening because when you are calling ajax to render the page, that page is already rendered.
TIP: If you use primefaces you could also use primefaces components where this is possible. Also upgrade to Primefaces 3.0.M4 for a better implementation. You also have a primefaces selectOneMenu component, and you can use primefaces ajax (p:ajax event="onchange") with update attribute (update the entire form)
updating the entire form with p:ajax certainly updates the name field but the row will no longer be in edit mode after this. If the user wants to edit the other cell in the same row, he has to explicitly go into edit mode
Related
I have a Primefaces DataTable with sortable columns. Even though it implements single sort (with and without sortMode="single"), the sort indicators on other columns do not disappear when I sort by a new column. It's purely for aesthetics, but I would like to remove the indicator once another column is sorted. I'm new to jsf and inherited this project, so there may be something happening behind the scenes that I don't understand. Here is a snippet from the xhtml:
<p:dataTable id="searchResults"
value="#{searchController.searchResults}"
var="emr"
selection="#{searchController.selectedEmr}"
rowKey="#{emr.emrid}"
selectionMode="single" widgetVar="theTable"
scrollable="true"
resizableColumns="true"
stickyHeader="true"
rowIndexVar="rowIndex"
sortBy="#{emr.emrid}"
styleClass="stdSearchResult">
<f:facet name="header">
Search Results
</f:facet>
<p:column style="width:16px">
<p:rowToggler />
</p:column>
<p:column headerText="Emr ID" sortBy="#{emr.emrid}" styleClass="wrap">
<h:outputText value="#{emr.emrid}" title="emrId"/>
</p:column>
Table:
Seems like an obvious name now, but removing stickyHeader="true" accomplished the desired functionality. Thank you for the assistance.
The problem can be reproduced in PrimeFaces showcase:
http://www.primefaces.org/showcase/ui/data/dataexporter/basic.xhtml
<f:facet name="{Exporters}">
<h:commandLink>
<p:graphicImage name="/demo/images/excel.png" width="24"/>
<p:dataExporter type="xls" target="tbl" fileName="cars" />
</h:commandLink>
</f:facet>
I have no idea from where the export gets the sorting that it is using.
Is there any way to make p:dataExporter to keep the same order as in p:dataTable?
Edit: My client noticed that if you click a column to sort the datatable then export keeps the sorting. That's good but how to keep the initial sorting?
This is an update on a previous post I made regarding conditional rendering of page components. I can now conditionally render different components on the page based on selected user inputs using the f:ajax tag. The trouble is that when I click my commandbutton the inputs that are conditionally rendered using ajax aren't being read on submit. I am guessing it is because the whole page isn't rerendered when I add in the new components and the submit button can't see them, even though they are there. Here is the segment of my form page(it is wrapped in a h:form tag):
<h:outputLabel for="selectPersonType" value="Select Type: "/>
<h:selectOneMenu id="selectPersonType" value="#{addPersonBean.personType}" label="Person Type" required="true">
<f:selectItem itemValue=""/>
<f:selectItems value="#{listBean.personTypes}" />
<f:ajax render="results"/>
</h:selectOneMenu>
<h:message for="selectPersonType" style="color: red"/>
</h:panelGrid>
<h:panelGroup id="results">
<h:panelGroup rendered="#{addPersonBean.personType == 'STUDENT'}">
<h:outputLabel for="selectSchoolType" value="School Type: " />
<h:selectOneMenu id="selectSchoolType" value="#{addPersonBean.schoolType}">
<f:selectItems value="#{listBean.schoolTypes}" />
<f:ajax execute="selectSchoolType"/>
</h:selectOneMenu>
</h:panelGroup>
<h:panelGroup rendered="#{addPersonBean.personType == 'PATIENT'}">
<h:outputLabel for="smoker" value="Smoker? " />
<h:selectBooleanCheckbox id="smoker" value="#{addPersonBean.smoker}">
<f:ajax execute="smoker"/>
</h:selectBooleanCheckbox>
</h:panelGroup>
</h:panelGroup>
<h:commandButton value="Add Person" action="#{addPersonBean.action}"/>
The trouble here is that the components with ids 'selectSchoolType' and 'smoker's values don't get set when I click the commandButton because they are rendered conditionally using the selectPersonType select menu after the page has loaded. Is there a way to fire the components when their values change instead of when I click the submit button (therefore, their values should be processed before I even click submit). As you can see I have tried to use f:ajax with the execute attribute attached to the components in question but it didn't seem to work. (I believe the default events for these components are valueChange so haven't added them to the f:ajax tags, but I have tried 'change' and 'valueChange').
All your <f:ajax> things are inside a conditionally rendered component. This construct will fail when the condition behind rendered attribute evaluates to false during processing the form submit. This will happen when the #{addPersonBean} is in the request scope and doesn't preinitialize the condition behind the rendered attribute during (post)construction, or when it's performing business logic in getters/setters in a wrong way.
Placing the #{addPersonBean} in the view scope and ensuring that you aren't doing business logic in getters/setters should fix this problem.
See also:
commandButton/commandLink/ajax action/listener method not invoked or input value not updated - point 5 applies to you
How to choose the right bean scope?
am usign jsf 2.0 + primefaces 3.2. i have a problem with filterBy when the data is a date but it works with other types of data.
<p:column sortBy="#{item.dateNaissance}" filterBy="#{item.dateNaissance}">
<f:facet name="header">
<h:outputText value="#{bundle.ListEtudiantTitle_dateNaissance}"/>
</f:facet>
<h:outputText value="#{item.dateNaissance}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</p:column>
default filtering doesn't work for date field, though you can use advanced filtering option and provide a filter server side method which does the filtering from the data set for you.
Basically you will specify your metho on key up event and filter record as per your need, default assumes everything to be String.
I have a dataTable in which i have five columns. First , fourth and fifth columns consists of checkboxes. I want that if user select or deselect checkbox of a particular row then the all checkboxes of that row also effected. I am using viewScope. Is this possible with view scope ?
Thanks
Just specify the relative IDs of those checkboxes in the render/update.
<p:column>
<h:selectBooleanCheckbox id="column1" value="#{item.column1}">
<f:ajax render="column4 column5" />
</h:selectBooleanCheckbox>
</p:column>
...
<p:column>
<h:selectBooleanCheckbox id="column4" value="#{item.column4}" />
</p:column>
<p:column>
<h:selectBooleanCheckbox id="column5" value="#{item.column5}" />
</p:column>
I would invoke a bean method when the tick changes in the first column. There you can set the calues for the other selects. After setting, refresh.