我有一个richfaces项目,看似简单的事情不想工作:( 看看代码:
<rich:panel header="Admin home" id="panel">
<h:form>
<rich:dataTable id="userlisttable" value="#{adminBean.userList}"
var="user" style="width:100%">
<rich:column id="banDate" headerClass="dataTableHeader"
label="Ban date" sortable="true" sortBy="#{user.banDate}"
sortIconAscending="dataTableAscIcon"
sortIconDescending="dataTableDescIcon">
<f:facet name="header">
<h:outputText value="Ban Date" />
</f:facet>
<h:outputText value="#{user.banDate}" />
</rich:column>
<rich:column id="actions" headerClass="dataTableHeader"
label="Actions" sortable="false">
<f:facet name="header">
<h:outputText value="Actions" />
</f:facet>
<h:panelGrid columns="4">
<h:outputText value="Ban user for" />
<a4j:commandLink action="#{adminBean.banUser}" value="One week"
style="font-size:16px" reRender="banDate" immediate="true">
<f:setPropertyActionListener target="#{adminBean.user}"
value="#{user}" />
</a4j:commandLink>
</h:panelGrid>
</rich:column>
</rich:dataTable>
</h:form>
</rich:panel>
它表现得很奇怪:执行action(actionBean.banUser),然后执行userList的getter,但是在页面上没有任何反应。如果我手动刷新(F5),则会显示新的修改数据。
有什么想法吗? 谢谢,Ben
答案 0 :(得分:1)
尝试使用rich:dataTable
a4j:outputPanel
<a4j:outputPanel id="myOutputPanel">
<rich:dataTable id="userlisttable" value="#{adminBean.userList}"
var="user" style="width:100%">
...
<a4j:commandLink action="#{adminBean.banUser}" value="One week"
style="font-size:16px" reRender="myOutputPanel" immediate="true">
<f:setPropertyActionListener target="#{adminBean.user}" value="#{user}" />
</a4j:commandLink>
...
</a4j:outputPanel>
答案 1 :(得分:1)
我已经渲染了dataTable它的工作原理..我正在使用Richfaces 4.0。如果您使用的是其他任何版本,请告诉我......
以下是有效的代码
<rich:dataTable id="userlisttable" value="#{adminBean.userList}"
var="user" style="width:100%">
<rich:column id="banDate" headerClass="dataTableHeader"
label="Ban date" sortable="true" sortBy="#{user.userId}"
sortIconAscending="dataTableAscIcon"
sortIconDescending="dataTableDescIcon">
<f:facet name="header">
<h:outputText value="Ban Date" />
</f:facet>
<h:outputText value="#{user.userId}" />
</rich:column>
<rich:column id="actions" headerClass="dataTableHeader"
label="Actions" sortable="false">
<f:facet name="header">
<h:outputText value="Actions" />
</f:facet>
<h:panelGrid columns="4">
<h:outputText value="Ban user for" />
<a4j:commandLink action="#{adminBean.banUser}" value="One week"
style="font-size:16px" render="banDate" >
<f:setPropertyActionListener target="#{adminBean.user}"
value="#{user}" immediate="true" />
</a4j:commandLink>
</h:panelGrid>
</rich:column>
</rich:dataTable>
</h:form>
</rich:panel>
AdminBean:
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@ManagedBean(name="adminBean")
@ViewScoped
public class AdminBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = -5338764155023244249L;
private List<UserBean> userList;
private UserBean user;
/**
* @return the user
*/
public UserBean getUser() {
return user;
}
/**
* @param user the user to set
*/
public void setUser(UserBean user) {
this.user = user;
}
/**
* @return the userList
*/
public List<UserBean> getUserList() {
return userList;
}
/**
* @param userList the userList to set
*/
public void setUserList(List<UserBean> userList) {
this.userList = userList;
}
public AdminBean() {
UserBean user1= new UserBean();
user1.setUserId("1");
user1.setUserName("userName1");
UserBean user2= new UserBean();
user2.setUserId("2");
user2.setUserName("userName2");
userList = new ArrayList<UserBean>();
userList.add(user1);
userList.add(user2);
}
public void banUser(){
if(user !=null){
user.setUserId("Rendered id R1");
}
}
}
的UserBean:
import java.io.Serializable;
public class UserBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 3820279264217591645L;
private String userName;
private String userId;
/**
* @return the userName
*/
public String getUserName() {
return userName;
}
/**
* @param userName the userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}
/**
* @return the userId
*/
public String getUserId() {
return userId;
}
/**
* @param userId the userId to set
*/
public void setUserId(String userId) {
this.userId = userId;
}
}