Hi I'm learning JSF/Primefaces. whenever user click on a link it should forward to the edit page with the information, but it's empty.
I tried to debug, following flow happens:
- user click the link of the element that wants to edit
- QuoteStatusList.init() is called
- QuoteStatusForm.init() is called
- QuoteStatusForm.edit is called
- QuotestatusForm.quoteStatus bean is filled with the information
- return "edit"
- foward to quoteStatusForm.xhtml
- and QuoteStatusForm.init() is called again, all datas filled are lost
I found this but I'm now only using jsf annotation to manage view beans
QuoteStatusList.java
@ManagedBean
@RequestScope
public class QuoteStatusList extends BasePage implements Serializable {
@PostConstruct
public void init(){
log.debug("initing...");
}
...
}
QuoteStatusForm.java
@ManagedBean
@ViewScope
public class QuoteStatusForm extends BasePage implements Serializable {
@PostConstruct
public void init(){
log.debug("initing...");
}
public String edit() {
log.debug("editing..");
if (idQuoteStatus != null && idQuoteStatus != 0) {
quoteStatus = quoteStatusManager.get(idQuoteStatus);
} else {
quoteStatus = new QuoteStatus();
}
return "edit";
}
}
BasePage.java
@ManagedBean
@RequestScoped
public class BasePage {
//nothing is injected
//no other @postConstruct function
}
QuoteStatusList.xhtml
<h:commandLink action="#{quoteStatusForm.edit}" value="#{quoteStatus.idQuoteStatus}">
<f:param name="idQuoteStatus" value="#{quoteStatus.idQuoteStatus}"/>
</h:commandLink>
faces-config.xml
<navigation-rule>
<from-view-id>/quoteStatusList.xhtml</from-view-id>
<navigation-case>
<from-outcome>edit</from-outcome>
<to-view-id>/quoteStatusForm.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/quoteStatusForm.xhtml</from-view-id>
<navigation-case>
<from-outcome>edit</from-outcome>
<to-view-id>/quoteStatusForm.xhtml</to-view-id>
</navigation-case>
</navigation-rule>