Boa dia,
Eu tenho um h:selectOneMenu que exibe uma lista de informação armazenada em banco.
Contudo, quando eu escolho um item da lista, o id não esta sendo retornada para a variavel responsavel de armazenar esse valor.
Alguem sabe se eu estou fazendo errado ou porque ele esta se perdendo?
tela:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<ui:fragment xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:form>
<p:dialog id="dialoggeradoc" widgetVar="geradoc" showEffect="clip"
hideEffect="clip" modal="true" resizable="false">
<f:facet name="header">
<h:outputText value="Gerar Documento" style="font-size: 14px" />
</f:facet>
<table>
<tr>
<td>
<h:outputLabel for="nomearquivo" value="Nome do Arquivo:" />
</td>
<td>
<p:inputText id="nomearquivo" required="true"
label="nomearquivo" styleClass="form1" value="#{geraDocsController.nomeTemplate}"/>
</td>
</tr>
<tr>
<td>
<h:outputLabel for="selecttempate" value="Template:" />
</td>
<td>
[b]<h:selectOneMenu effect="fade" id="selecttempate" label="template" style="size: 10px"
value="#{geraDocsController.templateComplete}">
<f:selectItem itemLabel="Selecione um Template" itemValue="" />
<f:selectItems value="#{geraDocsController.templatesItem}" />
</h:selectOneMenu>[/b]
</td>
</tr>
<tr>
<td>
<h:outputLabel for="informacao" value="Informações:" />
</td>
<td>
[b] <h:selectOneMenu effect="fade" id="informacao" label="template" style="size: 10px"
value="#{geraDocsController.nomeinformacao}">
<f:selectItem itemLabel="Selecione uma Informação" itemValue="" />
<f:selectItems value="#{geraDocsController.informacoesItem}" />
</h:selectOneMenu>[/b]
<p:spacer width="10" height="10" />
<p:commandButton image="ui-icon-plusthick" value="Adicionar" style="font-size: 12px" update="idinformacoesDG" actionListener="#{geraDocsController.addInformacao}" immediate="true"/>
<!-- <p:commandButton
image="ui-icon ui-icon-close" title="Delete"
style="width: 30px;height:30px;" /> -->
</td>
</tr>
<tr>
<td colspan="2">
<p:dataGrid id="idinformacoesDG" var="informacoesDG" value="#{geraDocsController.listaInformacoes}"
columns="2" rows="10" paginator="true" effect="true" paginatorPosition="bottom"
paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink}">
<p:column>
<p:panel id="gpnl" style="text-align:center; font-size:10px;width: 450px">
<f:facet name="header">
<h:outputText value="#{informacoesDG.nome}" />
</f:facet>
<p:draggable for="gpnl" grid="20,40" />
<h:panelGrid columns="1" style="width:100%">
<h:outputText value="#{informacoesDG.descricao}" />
</h:panelGrid>
</p:panel>
</p:column>
<p:column headerText="Opções" style="text-align: center;">
<p:commandButton oncomplete="confirmationRemove.show()" image="ui-icon ui-icon-close" title="Remover Informação"
style="width: 30px;height:30px;" immediate="true">
<f:setPropertyActionListener value="#{informacoesDG}" target="#{geraDocsController.selectedInformacoes}" />
</p:commandButton>
</p:column>
</p:dataGrid>
</td>
</tr>
<tr>
<td colspan="2"><br /> <br /> <p:panel
header="Informações Faltantes">
<h:outputLabel for="tagfaltante" value="#....#" />
<p:inputText id="tagfaltante" required="true"
style="width: 400px;" />
</p:panel></td>
</tr>
<tr>
<td colspan="2">
<p:spacer width="40%" height="10" />
<p:commandButton value="Gerar" actionListener="#{GeraDocs.salvar}"
style="font-size: 12px" oncomplete="onEditComplete(xhr,status,args)" image="ui-icon ui-icon-check" ajax="false" immediate="true"/>
<p:spacer width="10" height="10" />
<p:commandButton value="Cancelar" onclick="geradoc.hide()" type="button" image="ui-icon ui-icon-close"
style="font-size: 12px"/>
</td>
</tr>
</table>
</p:dialog>
</h:form>
</ui:fragment>
controlador
package br.com.dsc.controller;
import java.util.ArrayList;
import java.util.List;
import javax.faces.model.SelectItem;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import br.com.dsc.entity.Informacoes;
import br.com.dsc.entity.Templates;
import br.com.dsc.entity.Usuarios;
import br.com.dsc.service.IInformacaoService;
import br.com.dsc.service.ITemplatesService;
import br.com.dsc.service.IUsuarioService;
@Controller
@Qualifier("geraDocsController")
public class GeraDocsController {
private final Log logger = LogFactory.getLog(getClass());
@Autowired
private IUsuarioService iUsuarioService;
@Autowired
private ITemplatesService iTemplatesService;
@Autowired
private IInformacaoService iInformacaoService;
// Variaveis de controle
private String nomeTemplate;
private Integer templateComplete;
private Integer nomeinformacao;
private List<Informacoes> listaInformacoes;
private Informacoes selectedInformacoes;
public GeraDocsController() {
selectedInformacoes = new Informacoes();
}
/* ==================Funcionalidades ================================== */
public void pesquisar() {
logger.info("Controller atualizar.");
}
public void zerarController() {
}
public Templates templatesbyid(){
final Templates templatesbyid = new Templates() ;
final Usuarios usuarios = this.iUsuarioService.pesquisarPorId(1);
templatesbyid.setUsuarios(usuarios);
return templatesbyid;
}
public Informacoes informacoesbyid(){
final Informacoes informacoesbyid = new Informacoes() ;
final Usuarios usuarios = this.iUsuarioService.pesquisarPorId(1);
informacoesbyid.setUsuarios(usuarios);
return informacoesbyid;
}
public List<SelectItem> getTemplatesItem() {
SelectItem item = null;
final List<SelectItem> items = new ArrayList<SelectItem>();
final List<Templates> templates = this.iTemplatesService.pesquisar(templatesbyid());
for (Templates template : templates) {
item = new SelectItem();
item.setLabel(template.getNome());
item.setValue(template.getId());
items.add(item);
}
return items;
}
public List<SelectItem> getInformacoesItem() {
SelectItem item = null;
final List<SelectItem> items = new ArrayList<SelectItem>();
final List<Informacoes> informacoes = this.iInformacaoService.pesquisar(informacoesbyid());
for (Informacoes informacao : informacoes) {
item = new SelectItem();
item.setLabel(informacao.getNome());
item.setValue(informacao.getId());
items.add(item);
}
return items;
}
public void removeInformacao(){
listaInformacoes.remove(selectedInformacoes);
}
public void addInformacao(){
System.out.println("templateComplete: "+ templateComplete); // o console exibe null para essa variavel
System.out.println("nomeinformacao: "+ nomeinformacao); // o console exibe null para essa variavel
//final Informacoes informacoes = this.iInformacaoService.pesquisarPorId(nomeinformacao);
//listaInformacoes.add(informacoes);
}
/* =====================Gets e Sets==Omitidos=================================== */
}