File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes How to conditionaly populate a column in the datatable based on another column Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "How to conditionaly populate a column in the datatable based on another column" Watch "How to conditionaly populate a column in the datatable based on another column" New topic
Author

How to conditionaly populate a column in the datatable based on another column

Anitha Pillai
Greenhorn

Joined: Jun 29, 2012
Posts: 2
I have a datatable with input fields and 8 rows.
If any of the stylenumbers in a row is entered, then the qty column should be entered and it should be greater than 0.
Only for the rows where style number is entered. Can i use some kind of validation/rendering to make this happen?
Appreciate your help!

<p:dataTable value="#{invBean.orderList}" var="order" rows="8" rowStyleClass="#{data.id mod 2 == 0 ? null : 'odd'}">
styleClass="formStyle"
cellspacing="0"
cellpadding="0"
border="0"
rowClasses="odd,even"
columnClasses="Style Number,Color,Quantity"
class = "orderData">

<p:column headerstyleClass="first">
<f:facet name="header">
<hutputText value="Style Number" align="left" class="title1"/>
</f:facet>
<h:inputText id = "styleNo" value="#{order.styleNumber}" align="left" class="title1" >
<f:validator binding="#{styleValidator}" />
</h:inputText>

</p:column>
<p:column>
<f:facet name="header">
<hutputText value="Color" align="left" class="title1"/>
</f:facet>
<h:inputText value="#{order.color}" class="title1"/>
</p:column>
<p:column headerstyleClass="last">
<f:facet name="header">
<hutputText value="Quantity" align="left" class="title1"/>
</f:facet>
<h:inputText value="#{order.qty}" class="title1" />

</p:column>
</p:dataTable>
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15964
    
  19

Welcome to the JavaRanch, Anitha!

You can make your sample code and XML much easier to read: http://www.coderanch.com/how-to/java/UseCodeTags

The critical thing to keep in mind is that JSF is based on Model/View/Controller. So to update the display, you must update the model. That is, you must update the appropriate properties in the backing bean. In the case of a dataTable, the table's DataModel object is a sub-model, and the individual rows of that table are components of that sub-model, so that's where the updates must be made.

Under stock JSF, the updates could only be done by submitting the entire form containing the table and getting an updated page back. You are using PrimeFaces, I see, so if you prefer, you could take advantage of the PrimeFaces AJAX support features to update parts of the current page instead of submitting and updating the entire page. The technical name for that process is "partial page update" or "partial page refresh".


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to conditionaly populate a column in the datatable based on another column
 
Similar Threads
Sorting is not working in my JSF PrimeFaces Datatable and blank (empty) rows are displayed filtering
Problem trying to send file to browser in JSF
Unable to populate values obtained from ajax call using PrimeFaces
<p:datatable scrollable="true"> not working
DataModel not being refreshed when NextPageLink or PageLinks clicked