I have the following radio button-selectable datatable:
<h:form>
<p:dataTable value="#{gerarDocumentoBacking.reclamantes}"
selection="#{gerarDocumentoBacking.reclamante}" var="re" rowKey="#{re.id}">
<p:column headerText="Id">
<h:outputText value="#{re.id}"/>
</p:column>
<p:column headerText="Relamantes">
<h:outputText value="#{re.nome}"/>
</p:column>
<p:column selectionMode="single"/>
</p:dataTable>
<p:commandButton value="Gerar" action="#{gerarDocumentoBacking.gerar}"/>
</h:form>
It displays all the rows and the radio button as expected. However, it's not setting the reclamante
variable, as specified in the selection=
attribute.
The setReclamante
method is available and public:
@Named
@ViewScoped
public class GerarDocumentoBacking implements Serializable {
private static final long serialVersionUID = 1L;
private List<Reclamante> reclamantes;
private Reclamante reclamante;
@EJB
private ReclamanteService reclamanteService;
@PostConstruct
public void init() {
reclamantes = reclamanteService.listar();
}
public String gerar() {
System.out.println(reclamante.getNome());
return null;
}
public Reclamante getReclamante() {
return reclamante;
}
public void setReclamante(Reclamante reclamante) {
this.reclamante = reclamante;
}
...
Using some IDE debugging, I could see the setReclamante
method being called with a null value, so my gerar
method is throwing a NullPointerException at line System.out.println(reclamante.getNome());
. My datatable has the rowKey attribute and I know it's valid because it's being displayed in the datatable.
I need the command button outside the datatable because I intend to use other datatables inside this h:form
.