jsf - Unable to call method specified in ValueChangeListener attribute of <ice:selectOneRadio> -
i creating icefaces datatable.first column have radio button. on clicking of radio button of first row able edit row. on clicking of radio button of rows operation should performed(but not edit). have 1 command button @ bottom of datatable saves data. find below code 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 existing value set "editable" false (order order : orderlist){ order.seteditable(false); } //return current page return null; } // listener method public void editselectedrow(valuechangeevent evt) { // table object datatable table = getparentdatatable((uicomponent) evt.getsource()); if(table==null) return; // object on selected line. object o = table.getrowdata(); order order = (order)o; // eventually, if need index of line, do: int index = table.getrowindex(); if(index == 0){ order.seteditable(true); } // ... } // method 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 , 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 unable call editselectedrow(valuechangeevent evt) method of orderbean.java
i think missing onchange
property , following :
<ice:selectoneradio id="myradioid" value="#{order.checked}" layout="spread" valuechangelistener="#{orderbean.editselectedrow}" onchange="submit()"> <f:selectitem itemvalue="" /> </ice:selectoneradio>
hope helps.
Comments
Post a Comment