Good morning, everyone.
I do not know what to do to solve this problem in @FacesConverter(forClass=Fabricante.class)
that I implemented ...
The getAsString
method is called with null values.
All parameters ( FacesContext context, UIComponent component, Object value
) arrive with null.
The test I'm performing is in the call to edit records from the search list as the print attachment.
When I click Edit the facesConverter is called however the values are null, depending on the prints.
Does this only work on TOMCAT?
I'm trying to run this implementation in WILDFLY 8 and it's not working.
I do not know what to do ... could anyone guide me?
Thank you very much.
Thank you.
XHTML:
<ui:define name="titulo">Novo fabricante TESTE</ui:define>
<ui:define name="corpo">
<f:metadata>
<o:viewParam name="fabricante" value="#{cadastroFabricanteBean.fabricante}" converters="fabricanteConverter" />
</f:metadata>
<h:outputText value="#{cadastroFabricanteBean.fabricante}"/>
<br />
<h:outputText value="fabricante"/>
<h:form id="frmCadastro">
<p:messages id="messages" autoUpdate="true" closable="true" />
<p:toolbar style="margin-top: 20px">
<p:toolbarGroup>
<p:commandButton value="Salvar" id="botaoSalvar" action="#{cadastroFabricanteBean.salvar}" update="frmCadastro"/>
<p:commandButton value="Outro Salvar" id="botaoSalvar1" action="#{cadastroFabricanteBean.salvar}" update="frmCadastro"/>
</p:toolbarGroup>
<p:toolbarGroup align="right">
<p:button value="Pesquisa" outcome="/fabricante/PesquisaFabricantes.xhtml"/>
</p:toolbarGroup>
</p:toolbar>
<p:panelGrid columns="2" id="painel" style="width: 100%; margin-top: 20px"
columnClasses="rotulo, campo">
<p:outputLabel value="Código" for="codigo"/>
<p:inputText id="codigo" size="20" maxlength="20" value="#{cadastroFabricanteBean.fabricante.codigo}" readonly="true"/>
<p:outputLabel value="Nome" for="nome"/>
<p:inputText id="nome" size="60" maxlength="80" value="#{cadastroFabricanteBean.fabricante.nome}"/>
</p:panelGrid>
<h:dataTable value="#{cadastroFabricanteBean.fabricantes}" var="fabricante" border="1" cellpadding="5">
<h:column>
<h:outputText value="#{fabricante.codigo}"/>
</h:column>
<h:column>
<h:outputText value="#{fabricante.nome}"/>
</h:column>
</h:dataTable>
</h:form>
</ui:define>
<ui:define name="titulo">Pesquisa de Fabricantes</ui:define>
<ui:define name="corpo">
<h1>Pesquisa de Fabricantes</h1>
<h:form id="frmPesquisa">
<p:messages id="messages" autoUpdate="true" closable="true" />
<p:toolbar style="margin-top: 20px">
<p:toolbarGroup>
<p:commandButton value="Novo" id="botaoNovo" action="/fabricante/CadastroFabricante.xhtml"/>
</p:toolbarGroup>
</p:toolbar>
<p:dataTable id="fabricantesTable" value="#{pesquisaFabricanteBean.fabricantes}" var="fabricante"
style="margin-top: 20px" emptyMessage="Nenhum fabricante encontrado." rows="20"
paginator="true" paginatorAlwaysVisible="false" paginatorPosition="bottom">
<p:column headerText="Código" style="text-align: center; width: 100px">
<h:outputText value="#{fabricante.codigo}" />
</p:column>
<p:column headerText="Nome">
<h:outputText value="#{fabricante.nome}" />
</p:column>
<p:column style="width: 100px; text-align: center">
<p:button outcome="CadastroFabricante" icon="ui-icon-pencil" title="Editar">
<f:param name="fabricante" value="#{fabricante.codigo}"/>
</p:button>
<p:commandButton icon="ui-icon-trash" title="Excluir" oncomplete="PF('confirmacaoExclusao').show()"
process="@this" update=":frmPesquisa:confirmacaoExclusaoDialog">
<f:setPropertyActionListener target="#{pesquisaFabricanteBean.fabricanteSelecionado}" value="#{fabricante}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:confirmDialog id="confirmacaoExclusaoDialog" widgetVar="confirmacaoExclusao"
message="Tem certeza que deseja excluir o fabricante #{pesquisaFabricanteBean.fabricanteSelecionado.nome}?"
header="Exclusão de fabricante" severity="alert">
<p:button value="Não" onclick="confirmacaoExclusao.hide(); return false;" />
<p:commandButton value="Sim" update=":frmPesquisa:fabricantesTable"
onclick="confirmacaoExclusao.hide()" action="#{pesquisaFabricanteBean.excluir}" />
</p:confirmDialog>
</h:form>
</ui:define>
package com.jobstream.jboss.controller;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import com.jobstream.jboss.modelo.Fabricante;
@FacesConverter(forClass=Fabricante.class)
public class FabricanteConverter implements Converter {
public FabricanteConverter() {
}
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
System.out.println("FabricanteConverter :: getAsObject :: " + value);
Fabricante retorno = null;
return retorno;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
Fabricante f = (Fabricante) value;
if (f.getCodigo() == null) {
System.out.println("?????");
}
if (value != null) {
Long codigo = ((Fabricante) value).getCodigo();
System.out.println("FabricanteConverter :: getAsString :: " + codigo);
String retorno = (codigo == null ? null : codigo.toString());
return retorno;
}
return "";
}
}