I am making an application using jsf and I have a problem when sending data from one of the rows of the datatable to a bean and then redirect to another page. Just to state, I'm using bootsfaces. Here are the codes:
JSF page:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/templates/layout.xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:b="http://bootsfaces.net/ui"
xmlns:f="http://java.sun.com/jsf/core">
<ui:define name="title">Home</ui:define>
<ui:define name="content">
<b:dataTable value="#{LeiloesMB.lista()}" var="l">
<b:column>
<f:facet name="header">
<h:outputText value="Leilao"/>
</f:facet>
<h:outputText value="#{l.leilao.id}"/>
</b:column>
<b:column>
<f:facet name="header">
<h:outputText value="Encerramento"/>
</f:facet>
<h:outputText value="#{l.leilao.encerramento}"/>
</b:column>
<b:column>
<f:facet name="header">
<h:outputText value="Item"/>
</f:facet>
<h:outputText value="#{l.item.nome}"/>
</b:column>
<b:column>
<f:facet name="header">
<h:outputText value="Descrição"/>
</f:facet>
<h:outputText value="#{l.item.descricao}"/>
</b:column>
<b:column>
<f:facet name="header">
<h:outputText value="Maior Lance"/>
</f:facet>
<h:outputText value="#{l.valor}"/>
</b:column>
<b:column>
<f:facet name="header">
<h:outputLabel value="ID"/>
</f:facet>
<h:outputLabel value="#{l.usuario.id}"/>
</b:column>
<b:column>
<f:facet name="header">
<h:outputLabel value="Nome"/>
</f:facet>
<h:outputLabel value="#{l.usuario.nome}"/>
</b:column>
<b:column rendered="#{not empty Usuario.user.nome}">
<f:facet name="header">
<h:outputLabel value="Realizar Lance"/>
</f:facet>
<h:form>
<h:commandButton value="Faça seu lance" action="#{LanceMB.lance(Usuario.user, l)}"/>
</h:form>
</b:column>
</b:dataTable>
</ui:define>
</ui:composition>
LanceMB code:
@SessionScoped
@ManagedBean(name="LanceMB")
public class NovoLance {
private Usuario user = new Usuario();
private LancesLeilao ll = new LancesLeilao();
private double novo_valor;
public String lance(Usuario usuario, LancesLeilao lal){
this.user = usuario;
this.ll = lal;
return "novolance";
}
//getters.. setters
}
Usuario code:
@ManagedBean(name="Usuario")
@SessionScoped
public class UserSession {
private String email, senha;
private Usuario user = new Usuario();
//getters and setters..
}
Any question leave a comment.
A <h:commandButton />
is used to push the values of individual fields in a form to the managed bean defined. I see that you have enclosed just the button within the form but not the values themselves.
Wrap all the values within the form including the button and give it a try. It should work if everything else has been defined correctly.
Hope this helps :)