【问题标题】:Richfaces editable dataTable not setting updated values in BeanRichfaces可编辑数据表未在Bean中设置更新值
【发布时间】:2012-06-09 11:28:06
【问题描述】:

我在谷歌搜索后尝试了很多建议,但到目前为止没有一个对我有用。我试图在每一行中显示一个带有可编辑 inputText 值的简单数据表。表是通过通常的对象列表从数据库中填充的。这是我的 xhtml 页面和托管 bean

Richfaces 4.2.1、JSF 2 mojarra 与 JBoss 7.1、JDK 1.6 捆绑在一起

<rich:dataTable value="#{wlScoreBean.scoreList}" binding="#{wlScoreBean.scoreTable}" var="item" id="table" style="width:100%">
        <rich:column>
            <f:facet name="header">PARAM NAME</f:facet>
            <h:outputText value="#{item.paramName}" />
        </rich:column>
        <rich:column>
            <f:facet name="header">1 Score</f:facet>
             <h:inputText value="#{item.name1}" />
        </rich:column>
        <rich:column>
            <f:facet name="header">2 Score</f:facet>
             <h:inputText value="#{item.name2}" />
        </rich:column>
      </rich:dataTable>

        <br/>
        <h:panelGrid columns="3" id="buttonRow">
            <a4j:commandButton value="Save" render="table" execute="@this" action="#{wlScoreBean.update()}">                    
            </a4j:commandButton>
        </h:panelGrid>



import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.html.HtmlDataTable;
import javax.faces.event.ValueChangeEvent;

import org.richfaces.component.UIDataTable;


@ManagedBean(name = "wlScoreBean")
@ViewScoped
public class WS implements Serializable
{

    private static final long serialVersionUID = 1L;
    
    private HtmlDataTable scoreTable;
    private List<WorkloadScore> scoreList;
    
    public void watchScore(ValueChangeEvent e)
    {
        System.out.println("old value="+e.getOldValue() + ", New Value="+e.getNewValue());
    }

    public List<WorkloadScore> getScoreList() {
        return scoreList;
    }

    public void setScoreList(List<WorkloadScore> scoreList) {
        this.scoreList = scoreList;
    }

    @EJB
    private WorkloadScoreManagerService wlScoreManager;

    public HtmlDataTable getScoreTable() {
        return scoreTable;
    }

    public void setScoreTable(HtmlDataTable scoreTable) {
        this.scoreTable = scoreTable;
    }

    public WorkloadScoreBean()
    {
        
    }

    @PostConstruct
    private void getAllScores()
    {
        this.scoreList = wlScoreManager.getAllScores();
    }
    
    public void update()
    {
        
        for (WorkloadScore wls : getScoreList())
        {
            System.out.println(wls.getParamName()+"="+wls.getPortabilityScore()+","+wls.getVirtualizationScore());
        }
        
        //wlScoreManager.update(workloadScore);
    }
}

这是我尝试过的所有内容。所有这些都会导致在 update() 方法中仅将 OLD VALUES 打印到控制台。

  1. 从 rich:dataTable 更改为普通的旧 JSF h:dataTable,结果相同

  2. 将 dataTable 绑定到托管 Bean 属性,在 update() 方法中检查,旧值也在此处打印。我刚刚在 UIDataTable 对象上做了一个 getVlaue() 并将其转换为 List。

    列表应该已使用表单中的更改值进行了更新,但我没有看到它发生。我确实确保将 MBean 放在 ViewScope 中。

【问题讨论】:

    标签: jsf richfaces


    【解决方案1】:

    你在数据表之外有一个 h:form 吗?您是否尝试将 inputtext 替换为 inplaceinput 字段?

    【讨论】:

    • 是的,我在桌子外面有一个 h:form。我确实注意到,当我将 valueChangelistener 添加到 inputText 字段时,事件会触发并在 bean 上设置新值。奇怪....
    【解决方案2】:

    在这里查看答案https://community.jboss.org/thread/200684?tstart=0

    我更改了 execute=@form 并且成功了!不需要 ValueChangeEvent 或搞乱 dataTable 绑定。 List 值已就地更新,更新方法打印正确的值

    【讨论】:

      猜你喜欢
      • 2013-10-07
      • 1970-01-01
      • 2013-10-27
      • 1970-01-01
      • 1970-01-01
      • 2020-09-14
      • 1970-01-01
      • 2013-10-10
      • 2012-11-15
      相关资源
      最近更新 更多