有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java动态数据表显示空行

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

冰面2.0.0 JSF2.0 JSTL1。2. 已设置ViewScope,因此绑定不起作用

欢迎光临。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;
}


}
} 

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

在过去的一周里,我一直为此感到沮丧

请回复这个

寻找解决方案


共 (0) 个答案