【发布时间】:2015-05-18 04:37:05
【问题描述】:
刚开始学习jsf,遇到一个基本问题。我在 dataTable 中显示了一个对象列表,并为每一行创建了表单以调用具有正确参数的函数:
<h:dataTable value="#{test.getMyItems()}" var="o"
styleClass="order-table"
headerClass="order-table-header"
rowClasses="order-table-odd-row,order-table-even-row">
<h:column>
<f:facet name="header">Content</f:facet>
#{o.content}
</h:column>
<h:column>
<h:form>
<h:commandLink action="#{test.edit}" value="edit">
<f:param name="id" value="#{o.id}" />
</h:commandLink>
</h:form>
</h:column>
</h:dataTable>
现在我想将用户重定向到编辑页面,该页面的输入设置为正确的值。所以在函数编辑中,我为变量设置了值:
public String edit() {
this.name = "test1";
this.description = "test2";
return "/edit.xhtml?faces-redirect=true";
}
我想在编辑视图中显示它们:
<h:form>
<h:outputLabel value="name:" />
<h:inputText value="#{test.name}" />
<h:outputLabel value="description" />
<h:inputText value="#{test.description}" />
<h:commandButton value="Add" action="#{edit.update()}"/>
</h:form>
但输入为空。为什么?
和测试类:
@ManagedBean (name = "test")
@ViewScoped
public class Test {
private String name;
private String description;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public String edit() {
this.name = "test1";
this.description = "test2";
return "/edit.xhtml?faces-redirect=true";
}
public List<Item> getMyItems() {
List<Item> items = new ArrayList<Item>();
Item i = new Item("1", "g", "f");
items.add(i);
return items;
}
public void update() {
}
【问题讨论】:
-
如果你展示了你的测试课会有所帮助。您的名称和描述字段是否正确命名了 getter 和 setter?
-
@hooda 我添加了测试类实现。
标签: jsf controller master-detail