日期:2014-05-16 浏览次数:20407 次
JSF异常java.lang.IllegalArgumentException:
public String updateProduct() { 
FacesContext facesContext = FacesContext.getCurrentInstance(); 
UIViewRoot root = facesContext.getViewRoot(); 
UIData table = (UIData) root.findComponent("editForm").findComponent( 
"editTable"); 
Product product = (Product) table.getRowData(); 
ProductUtil.updateProduct(product.getId(), product.getName(), product 
.getAddress()); 
ProductUtil.selectAll();// 重载datatable 
return "updataKO"; 
} 
当执行到Product product = (Product) table.getRowData();这段代码的时候就报这个异常,请大家帮帮忙
------解决方法--------------------
参数不对的错误, table.getRowData(); 这个函数是你自己写的吗?还是??跳进去看看吧... 
------解决方法--------------------
看看那个地方参数不对 
------解决方法--------------------
UIData table = (UIData) root.findComponent("editForm").findComponent("editTable"); 
改成UIData table = (UIData) root.findComponent("editForm:editTable")试试,但我估计这样写也是不成的, 
你可以按照下面的方法解决: 
<t:commandLink actionListener="#{yourBean.actinlisterer}" immediate="true" action="yourBean.updateProduct"> 
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->public String updateProduct() {return "updataKO";} public void actinlisterer(ActionEvent ev){ UIData table = findParentHtmlDataTable(ev.getComponent());Product product = (Product) table.getRowData();ProductUtil.updateProduct(product.getId(), product.getName(), product.getAddress());ProductUtil.selectAll();// 重载datatable}private HtmlDataTable findParentHtmlDataTable(UIComponent component) {  if (component == null)  {  return null;  }  if (component instanceof HtmlDataTable)  {  return (HtmlDataTable) component;  }  return findParentHtmlDataTable(component.getParent()); }
------解决方法--------------------
学习~~~~~~~~~~~
------解决方法--------------------
------解决方法--------------------
你在错的那句之前调用一下isRowAvailable(),我想你的返回应该是false,也就是没数据可用
------解决方法--------------------
public String updateProduct() { 
 return "updataKO"; 
 } 
 public void actinlisterer(ActionEvent ev){ 
 UIData table = findParentHtmlDataTable(ev.getComponent()); 
 Product product = (Product) table.getRowData(); 
 ProductUtil.updateProduct(product.getId(), product.getName(), product 
 .getAddress()); 
 ProductUtil.selectAll();// 重载datatable 
 } 
 private HtmlDataTable findParentHtmlDataTable(UIComponent component) 
 { 
 if (component == null) 
 { 
 return null; 
 } 
 if (component instanceof HtmlDataTable) 
 { 
 return (HtmlDataTable) component; 
 } 
 return findParentHtmlDataTable(component.getParent()); 
 }
------解决方法--------------------
应该是参数的异常吧,学习了,up
------解决方法--------------------
有时间把你的相关代码都贴出来,包括整个bean及jsf页面