i've got this jsf simple form in which i try if the method for set the id of the selected invoice works:
<h:form>
<fieldset>
<label for="email">E-Mail</label>
<h:inputText id="email" value="#{invoiceManageController.selectedInvoiceId}"></h:inputText>
<h:commandButton styleClass="button-primary" action="#{invoiceManageController.putInvoice()}" value="Login"></h:commandButton>
<h:outputText value="#{ invoiceSessionBean.invoiceId}" />
</fieldset>
</h:form>
then i got a controller class that works on a bean:
@Model
public class InvoiceManageController {
@Inject
private InvoiceDao invoiceDao;
@Inject
private InvoiceSessionBean invoiceSession;
private List<Invoice> lastInvoicesData;
private Long selectedInvoiceId;
public InvoiceManageController(){
selectedInvoiceId = new Long(3);
}
public void putInvoice(){
invoiceSession.setInvoiceId(selectedInvoiceId);
}
public void setSelectedInvoiceId(Long selectedInvoiceId) {
this.selectedInvoiceId = selectedInvoiceId;
}
public Long getSelectedInvoiceId() {
return selectedInvoiceId;
}
}
and finally i got a simple bean that save the id of the invoice selected during a session:
import javax.faces.bean.SessionScoped;
import javax.inject.Named;
@SessionScoped
@Named
public class InvoiceSessionBean implements Serializable{
private static final long serialVersionUID = 1L;
private Long invoiceId;
public Long getInvoiceId() {
return invoiceId;
}
public void setInvoiceId(Long invoiceId) {
this.invoiceId = invoiceId;
}
}
when i click on the button the method isn't called and the outputText is not update, why? instead if i call for example other methods that not use InvoiceSessionBean work,why?
My test:
If i replace the annotation on the InvoiceSessionBean with:
@ManagedBean
@SessionScoped
and try to access directly to the bean changing the form to:
it works why?
<h:form>
<fieldset>
<label for="email">E-Mail</label>
<h:inputText id="email" value="#{ invoiceSessionBean.invoiceId }"></h:inputText>
<h:commandButton styleClass="button-primary" action="#{invoiceSessionBean.setInvoiceId(invoiceSessionBean.invoiceId)}" />
<h:outputLabel value="#{ invoiceSessionBean.invoiceId }" />
</fieldset>
</h:form>
Solved: My problem was that i was minxing CDI beans with JSF beans thus i change the import and works
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;