2012-01-11 61 views
0

我有一個RichFaces的項目,以及一個看似簡單的事情,開不想要工作:( 退房代碼:重新呈現不適合A4J工作:commandLink標籤

<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> 

它的行爲非常奇怪: (actionBean.banUser)被執行,那麼userList的getter也被執行,但是頁面上沒有任何反應,如果我手動刷新它(F5),新的修改後的數據就會出現。 ,本

+0

你禁止用戶後更新adminBean.userList? – soulcheck 2012-01-11 13:22:49

+0

是的。我在getter中有一個數據庫查詢,正如我所提到的,getter被調用。我也試圖把這個查詢放在這個動作中,所以如果更新(禁止)成功,那麼它就會被解僱,並且仍然沒有任何東西:( – 2012-01-11 13:28:54

+0

嘗試重新渲染整個表而不是一列 – soulcheck 2012-01-11 13:31:26

回答

1

嘗試周圍您rich:dataTablea4j: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> 
+0

nope,那沒有任何作用:( – 2012-01-11 13:31:49

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; 
    } 



} 
+0

hm,在這種情況下,你能發給我你使用的bean嗎?我知道它不應該與它有任何關係,但仍然,它值得一試:) – 2012-01-11 21:52:44

+0

只是萬一你使用richfaces 3.X通過這個鏈接將幫助你解決問題http://mkblog.exadel.com/2011/03/learn-how-to- adddelete錶行與 - RichFaces的式-5-分鐘/ – 2012-01-12 17:46:11