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]
# 1
Please any thoughts on this..any help is highly appreciated
kristeina at 2007-7-11 15:33:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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.

BalusCa at 2007-7-11 15:33:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Thanks very much for your reply BalusC.But I have few more questions for you1)How to do it for a particular row of that column.2)Is there any posibility of doing using onblur method on that column to change ProposedGrossMargin column value.
kristeina at 2007-7-11 15:33:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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.

BalusCa at 2007-7-11 15:33:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Thanks for valuable information BalusC.I don't have any knowledge of Ajax. It will be great if you can you provide me with any tips on how to do this using ajax.Please help me!Thanks and regardsKristein
kristeina at 2007-7-11 15:33:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
I've AJAX experience, but not in conjunction with JSF.Check out the JBoss site for any info about A4J: http://labs.jboss.com/portal/jbossajax4jsf
BalusCa at 2007-7-11 15:33:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
please had anybody did this before using ajax.Thanks and regardsKristein
kristeina at 2007-7-11 15:33:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...