Render problem of jsf 2.0
yyq2009 Dec 16, 2009 3:17 AMI just want to rerender a tag(h:outputText) when I click one cell of a datatable using jsf 2.0, but my test showed me some error like that the tag id i set to be rerendered is not in the context of the cell tag.
my code is following:
index.xhtml
<?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" > <h:head> <title>Facelet Title</title> <h:outputScript target="header" name="jquery.js" library="js"/> <script type="text/javascript"> function showStatus(event) { $("#status").text(event.status); } </script> </h:head> <h:body> <h:form id="form1" prependId="false"> <h:dataTable id="table" value="#{TestBean.allUsers}" var="u"> <h:column> <f:facet name="header"> <h:outputLabel value="Name"/> </f:facet> <h:outputLabel value="#{u.name}"> <f:ajax event="click" listener="#{TestBean.show(u)}" onevent="showStatus" render="out1"/> </h:outputLabel> </h:column> </h:dataTable> </h:form> <h:outputText id="out1" value="#{TestBean.user.name}"/> <div id="status"></div> </h:body> </html>
my test bean is:
TestBean.java
@ManagedBean(name="TestBean") @RequestScoped public class TestBean { private User user; private List<User> list; /** Creates a new instance of TestBean */ public TestBean() { } public List<User> getAllUsers(){ list = new ArrayList<User>(); for (int i = 0; i < 10; i++) { list.add(new User("Name"+(i+1),18+i,"DV"+(i+1))); } return list; } public void show(User user){ System.out.println("User nam is "+user.getName()); this.user = user; } public User getUser() { return user; } public void setUser(User user) { this.user = user; }
<f:ajax event="click" listener="#{TestBean.show(u)}" onevent="showStatus" render="out1"/>
The error appeared in this line.
if I change render value to "@all" it works, but I just want to render the only one tag, why must I set the render value "@all"?
Any suggestions?
Thanks in advance.