I am creating a Icefaces Datatable.First column have radio button. On clicking of radio button of first row i am able to edit the row. On clicking of radio button of another rows another operation should be performed(but not edit). I have one command button at the bottom of the datatable which saves the data. Find below the code for the same
------------------xhtml----------------------
<h1>IceFaces 3 </h1>
<h:form>
<ice:selectOneRadio id="myRadioId"
value="#{order.checked}" layout="spread"
valueChangeListener="#{orderBean.editSelectedRow}"
partialSubmit="true">
<f:selectItem itemValue="" />
</ice:selectOneRadio>
<ace:dataTable value="#{orderBean.orderList}" var="o" style="width: 300px !important">
<ace:column headerText="Select">
<ice:radio for="myRadioId" />
</ace:column>
<ace:column headerText="Order No">
<h:inputText value="#{o.orderNo}" size="10" rendered="#{o.editable}" />
<h:outputText value="#{o.orderNo}" rendered="#{not o.editable}" />
</ace:column>
<ace:column headerText="Product Name">
<h:inputText value="#{o.productName}" size="20" rendered="#{o.editable}" />
<h:outputText value="#{o.productName}" rendered="#{not o.editable}" />
</ace:column>
<ace:column headerText="Price">
<h:inputText value="#{o.price}" size="10" rendered="#{o.editable}" />
<h:outputText value="#{o.price}" rendered="#{not o.editable}" />
</ace:column>
<ace:column headerText="Quantity">
<h:inputText value="#{o.qty}" size="5" rendered="#{o.editable}" />
<h:outputText value="#{o.qty}" rendered="#{not o.editable}" />
</ace:column>
</ace:dataTable>
<br/><br/>
<ice:commandButton value="Save Changes" action="#{orderBean.saveAction}" />
</h:form>
</h:body>
------------------------------managed bean------------------------------ //bean
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlDataTable;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import org.icefaces.ace.component.datatable.DataTable;
@ManagedBean(name="orderBean")
@SessionScoped
public class OrderBean implements Serializable{
private static final long serialVersionUID = 1L;
private static final ArrayList<Order> orderList =
new ArrayList<Order>(Arrays.asList( new Order("A0001", "Intel CPU", new BigDecimal("700.00"), 1),
new Order("A0002", "Harddisk 10TB", new BigDecimal("500.00"), 2),
new Order("A0003", "Dell Laptop", new BigDecimal("11600.00"), 8),
new Order("A0004", "Samsung LCD", new BigDecimal("5200.00"), 3),
new Order("A0005", "A4Tech Mouse", new BigDecimal("100.00"), 10)
));
public ArrayList<Order> getOrderList() {
return orderList;
}
public String saveAction() {
//get all existing value but set "editable" to false
for (Order order : orderList){
order.setEditable(false);
}
//return to current page
return null;
}
// listener method
public void editSelectedRow(ValueChangeEvent evt) {
// We get the table object
DataTable table = getParentDatatable((UIComponent) evt.getSource());
if(table==null) return;
// We get the object on the selected line.
Object o = table.getRowData();
Order order = (Order)o;
// Eventually, if you need the index of the line, simply do:
int index = table.getRowIndex();
if(index == 0){
order.setEditable(true);
}
// ...
}
// Method to get the DataTable.
private DataTable getParentDatatable(UIComponent compo) {
if (compo == null) {
return null;
}
if (compo instanceof DataTable) {
return (DataTable) compo;
}
return getParentDatatable(compo.getParent());
}
//managed bean
@ManagedBean(name="order")
public static class Order{
String orderNo;
String productName;
BigDecimal price;
int qty;
boolean editable;
boolean checked;
public Order(){ }
public Order(String orderNo, String productName, BigDecimal price, int qty) {
this.orderNo = orderNo;
this.productName = productName;
this.price = price;
this.qty = qty;
}
//getter and setter methods
public String getOrderNo() {
return orderNo;
}
public void setOrderNo(String orderNo) {
this.orderNo = orderNo;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public int getQty() {
return qty;
}
public void setQty(int qty) {
this.qty = qty;
}
public boolean isEditable() {
return editable;
}
public void setEditable(boolean editable) {
this.editable = editable;
}
public boolean isChecked() {
return checked;
}
public void setChecked(boolean checked) {
this.checked = checked;
}
}
}
-------------------------------generated html--------------------------------
<table>
<thead>
<tr>
<th class="ui-widget-header"><div
class="ui-header-column clickable" id="j_idt6:j_idt9:j_idt10">
<span><span class="ui-header-text"
id="j_idt6:j_idt9:j_idt10_text">Select</span></span>
</div></th>
<th class="ui-widget-header"><div
class="ui-header-column clickable" id="j_idt6:j_idt9:j_idt12">
<span><span class="ui-header-text"
id="j_idt6:j_idt9:j_idt12_text">Order No</span></span>
</div></th>
<th class="ui-widget-header"><div
class="ui-header-column clickable" id="j_idt6:j_idt9:j_idt15">
<span><span class="ui-header-text"
id="j_idt6:j_idt9:j_idt15_text">Product Name</span></span>
</div></th>
<th class="ui-widget-header"><div
class="ui-header-column clickable" id="j_idt6:j_idt9:j_idt18">
<span><span class="ui-header-text"
id="j_idt6:j_idt9:j_idt18_text">Price</span></span>
</div></th>
<th class="ui-widget-header"><div
class="ui-header-column clickable" id="j_idt6:j_idt9:j_idt21">
<span><span class="ui-header-text"
id="j_idt6:j_idt9:j_idt21_text">Quantity</span></span>
</div></th>
</tr>
</thead>
<tbody class="ui-datatable-data ui-widget-content">
<tr class=" ui-datatable-even " id="j_idt6:j_idt9_row_0" tabindex="0">
<td>
<span>
<input id="j_idt6:myRadioId:_0"
name="j_idt6:myRadioId" onblur="setFocus('');"
onclick=";setFocus('');iceSubmitPartial(form, this, event);"
onfocus="setFocus(this.id);"
onkeypress="Ice.util.radioCheckboxEnter(form,this,event);"
type="radio" value="" />
<label class="iceSelOneRb" for="j_idt6:myRadioId:_0"></label>
</span>
</td>
<td><span id="j_idt6:j_idt9:0:_t14">A0001</span></td>
<td><span id="j_idt6:j_idt9:0:_t17">Intel CPU</span></td>
<td><span id="j_idt6:j_idt9:0:_t20">700.00</span></td>
<td><span id="j_idt6:j_idt9:0:_t23">1</span></td>
</tr>
<tr class=" ui-datatable-odd " id="j_idt6:j_idt9_row_1" tabindex="0">
<td>
<span>
<input id="j_idt6:myRadioId:_0"
name="j_idt6:myRadioId" onblur="setFocus('');"
onclick=";setFocus('');iceSubmitPartial(form, this, event);"
onfocus="setFocus(this.id);"
onkeypress="Ice.util.radioCheckboxEnter(form,this,event);"
type="radio" value="" />
<label class="iceSelOneRb" for="j_idt6:myRadioId:_0"></label>
</span>
</td>
<td><span id="j_idt6:j_idt9:1:_t14">A0002</span></td>
<td><span id="j_idt6:j_idt9:1:_t17">Harddisk 10TB</span></td>
<td><span id="j_idt6:j_idt9:1:_t20">500.00</span></td>
<td><span id="j_idt6:j_idt9:1:_t23">2</span></td>
</tr>
<tr class=" ui-datatable-even " id="j_idt6:j_idt9_row_2" tabindex="0">
<td>
<span>
<input id="j_idt6:myRadioId:_0"
name="j_idt6:myRadioId" onblur="setFocus('');"
onclick=";setFocus('');iceSubmitPartial(form, this, event);"
onfocus="setFocus(this.id);"
onkeypress="Ice.util.radioCheckboxEnter(form,this,event);"
type="radio" value="" />
<label class="iceSelOneRb" for="j_idt6:myRadioId:_0"></label>
</span>
</td>
<td><span id="j_idt6:j_idt9:2:_t14">A0003</span></td>
<td><span id="j_idt6:j_idt9:2:_t17">Dell Laptop</span></td>
<td><span id="j_idt6:j_idt9:2:_t20">11600.00</span></td>
<td><span id="j_idt6:j_idt9:2:_t23">8</span></td>
</tr>
<tr class=" ui-datatable-odd " id="j_idt6:j_idt9_row_3" tabindex="0">
<td>
<span>
<input id="j_idt6:myRadioId:_0"
name="j_idt6:myRadioId" onblur="setFocus('');"
onclick=";setFocus('');iceSubmitPartial(form, this, event);"
onfocus="setFocus(this.id);"
onkeypress="Ice.util.radioCheckboxEnter(form,this,event);"
type="radio" value="" />
<label class="iceSelOneRb" for="j_idt6:myRadioId:_0"></label>
</span>
</td>
<td><span id="j_idt6:j_idt9:3:_t14">A0004</span></td>
<td><span id="j_idt6:j_idt9:3:_t17">Samsung LCD</span></td>
<td><span id="j_idt6:j_idt9:3:_t20">5200.00</span></td>
<td><span id="j_idt6:j_idt9:3:_t23">3</span></td>
</tr>
<tr class=" ui-datatable-even " id="j_idt6:j_idt9_row_4" tabindex="0">
<td>
<span>
<input id="j_idt6:myRadioId:_0"
name="j_idt6:myRadioId" onblur="setFocus('');"
onclick=";setFocus('');iceSubmitPartial(form, this, event);"
onfocus="setFocus(this.id);"
onkeypress="Ice.util.radioCheckboxEnter(form,this,event);"
type="radio" value="" />
<label class="iceSelOneRb" for="j_idt6:myRadioId:_0"></label>
</span>
</td>
<td><span id="j_idt6:j_idt9:4:_t14">A0005</span></td>
<td><span id="j_idt6:j_idt9:4:_t17">A4Tech Mouse</span></td>
<td><span id="j_idt6:j_idt9:4:_t20">100.00</span></td>
<td><span id="j_idt6:j_idt9:4:_t23">10</span></td>
</tr>
</tbody>
</table>
probleme here is that i am unable to call editSelectedRow(ValueChangeEvent evt) method of OrderBean.java
I think what you are missing is the
onchangeproperty , do something like the following :Hope that Helps.