Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Anitha Pillai
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic