Richfaces可编辑数据表未在Bean中设置更新值 [英] Richfaces editable dataTable not setting updated values in Bean
问题描述
在谷歌搜索后,我尝试了很多建议,但到目前为止没有一个对我有用.我试图在每行中显示一个带有可编辑inputText值的简单数据表.表是通过通常的对象列表从数据库填充的.这是我的xhtml页面和托管bean
I have tried a bunch of suggestions after googling but none has so far worked for me. I am trying to display a simple datatable with editable inputText values in each row. table is being populated from database via a usual List of objects. Here is my xhtml page and managed bean
Richfaces 4.2.1,与JBoss 7.1,JDK 1.6捆绑在一起的JSF 2 mojarra
Richfaces 4.2.1, JSF 2 mojarra bundled with 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()方法打印到控制台.
Here's all the things I tried. All of them result in only the OLD VALUES being printed to console in the update() method.
-
从rich:dataTable更改为普通的旧JSF h:dataTable,结果相同
Changed from rich:dataTable to plain old JSF h:dataTable, same result
将dataTable绑定到Managed Bean属性,在update()方法中检查,这里也打印旧值.我只是在UIDataTable对象上做了一个getVlaue()并将其强制转换为List.
Bound the dataTable to a Managed Bean property, checked in update() method, old values are being printed here too. I just did a getVlaue() on the UIDataTable object and cast it to List.
应该使用列表中的更改值来更新列表,但是我看不到它的发生.我确实确保将MBean放在ViewScope中.
The List is supposed to have been updated with changed values from the form, but I do not see it happening. I did make sure to put the MBean in ViewScope.
推荐答案
在此处查看答案 https ://community.jboss.org/thread/200684?tstart = 0
我更改了execute = @ form并成功了!不需要ValueChangeEvent或搞乱dataTable绑定. List值已就地更新,并且update方法将打印正确的值
I changed execute=@form and it worked! no need for ValueChangeEvent or messing with dataTable binding. The List values are updated in place and the update method prints the correct value
这篇关于Richfaces可编辑数据表未在Bean中设置更新值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!