I just started learning jsf and I encountered a basic problem. I displayed a list of objects in dataTable and created form for each row to call a function with right parameter:
<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>
And now I wanted to redirect user to edit page whit a form which has inputs set to proper values. So in function edit I set values to the variables:
public String edit() {
this.name = "test1";
this.description = "test2";
return "/edit.xhtml?faces-redirect=true";
}
And in edit view I wanted to display them:
<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>
but inputs are empty. Why?
And Test class:
@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() {
}