2

我正在尝试创建没有绑定的动态数据表。因为绑定不适用于视图范围的 bean。但问题是动态数据表只呈现一次。如果我尝试更改值,它将显示空行.....

ICEfaces 2.0.0 JSF 2.0 JSTL1.2 ViewScoped 所以绑定不起作用

欢迎.xhtml

<h:form id="form">
<h:outputText value="Welcome to ICEfaces 2"/>
<ice:commandButton value="Start" action="#{table.start}"/>
<ice:commandButton value="Update" action="#{table.update}"/>
<ice:dataTable id="table" value="#{table.list}" var="currentRow" >
<ice:column rendered="false" id="row">
<ice:rowSelector multiple="false" selectionListener="#{table.selectionRowTable}" />
</ice:column>
</ice:dataTable>
</h:form> 

JavaBean 代码

@ManagedBean (name="table")
@ViewScoped
public final class TestTable implements Serializable {

public sample list[]=new sample[5];

public sample[] getList() {
return list;
}

public void setList(sample[] list) {
this.list = list;
}

HtmlDataTable table=null;


public void createTable()
{
table=(HtmlDataTable)findComponent(FacesContext.getCurrentInstance().getViewRoot(), "table");

HtmlCommandButton commandSortHeader = new HtmlCommandButton();
commandSortHeader.setId("header");

HtmlOutputText headerComponent = new HtmlOutputText();
headerComponent.setId("headerComponentId");
headerComponent.setValue("Header");

ExpressionFactory factory = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
MethodExpression methodsexpression = factory.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{table.Test}", null, new Class[]{ActionEvent.class});
MethodExpressionActionListener actionListener = new MethodExpressionActionListener(methodsexpression);
commandSortHeader.addActionListener(actionListener);
commandSortHeader.getChildren().add(headerComponent);

UIColumn column=new UIColumn();
column.setId("column");
HtmlOutputText t=new HtmlOutputText();
t.setValueExpression("value",FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression(FacesContext.getCurrentInstance().getELContext(), "#{currentRow.name}",String.class));
t.setId("Text");
column.getChildren().add(t);
column.setHeader(commandSortHeader);
table.getChildren().add(column);
}

public void start()
{
for(int i=0;i<5;i++)
list[i]=new sample("OLD"+i);
createTable();
}

public void update()
{
for(int i=0;i<5;i++)
list[i]=new sample("NEW"+i);
}


public void Test(ActionEvent e)
{
System.out.println("Header Clicked");
}

public void selectionRowTable(RowSelectorEvent e)
{
System.out.println("Row Clicked");
}

public UIComponent findComponent(UIComponent parent, String id) {
if (id.equals(parent.getId())) {
return parent;
}
Iterator<UIComponent> kids = parent.getFacetsAndChildren();
while (kids.hasNext()) {
UIComponent kid = kids.next();
UIComponent found = findComponent(kid, id);
if (found != null) {
return found;
}
}
return null;
}


public class sample{

public String name;

public sample(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}


}
} 

如果我更新列表值,它永远不会被打印并显示空行......

由于这个原因,我在过去 1 周感到沮丧.......

请回复这个....

寻找解决方案

4

0 回答 0