dataTable question
Hi,
I am new to JSF and facing few problems in solving this.
My question is I have a dataTable with columns ProdCode,ProposedPrice and ProposedGrossMargin.In which ProposedPrice and ProposedGrossMargin are editable columns.
If I change value of ProposedPrice of a particular row then it should dynamically update ProposedGrossmargin column of that row and at the same time it should also be saved in the database.
Please could any body help me in solving this problem with a piece of code.
thanks and regards
kristein
[560 byte] By [
kristeina] at [2007-11-26 23:52:56]

# 2
Something like this?public class Product {
public getProposedGrossmargin() {
return proposedPrice * 10; // Implement your "dynamic update" here.
}
}
Or do it in the action method
public void action() {
product.setProposedGrossmargin(product.getProposedPrice() * 10); // Do your thing.
}
Saving is simple. Just do it the inverted way as you have loaded the data. "UPDATE table SET column=value", if you're using JDBC/SQL.
# 4
1) It depends on design. I guess you need HtmlDataTable#getRowData() and valueChangeListener.
JSF<h:dataTable value="#{myBean.products}" var="product" binding="#{myBean.productTable}">
<h:column>
<h:inputText value="#{product.proposedPrice}" valueChangeListener="#{myBean.updatePrice}" onblur="submit();" />
</h:column>
...
</h:dataTable>
MyBeanprivate HtmlDataTable productTable; // + getter + setter
public void updatePrice(ValueChangeEvent event) {
if (!event.getNewValue().equals(event.getOldValue()) {
// The value has changed.
Product product = (Product) productTable.getRowData(); // The row object.
Object proposedPrice = event.getNewValue(); // The new ProposedPrice
// Do your thing.
}
}
2) Just submit the form on blur. Take in mind that this is expensive if you have many rows (in terms of 1000), because JSF doesn't know before which row is updated and will just issue a ValueChangeEvent for every row. If this is the case, then consider AJAX for JSF to update per row only.