• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

getAsObject never called

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ranchers, please help me to solve this problem:

I created a converter to work with class TipoEmpresa (please see all the code below). The getAsString is working ok, but when I submit the form, I was expecting jsf to call the getAsObject and convert the object again but it is not happening and I get a string instead of TipoEmpresa. Has someone face this problem before ? (EmpresaBean.converter returns the Converter). I also tried other ways to declare the converter and none of them worked)

----JSP----
<h:selectManyListbox styleClass="selectManyMenu"
id="tipo" converter="#{EmpresaBean.converter}" value="#{EmpresaBean.empresa.tipo}" >
<%--<f:converter converterId="TipoEmpresaConverter" />--%>
<f:selectItems value="#{HelperBean.selectItemGroup}"/>
</h:selectManyListbox>

---TipoEmpresa--(variable tipo)./*Accessor methods removed*/
public class TipoEmpresa implements Serializable
{

@Id
@GeneratedValue(strategy = GenerationType.TABLE,generator="SEQ_TIPO_EMPRESA")
private Long id;

private String nome;
private String status;

--Converter--
public class TipoEmpresaConverter implements Converter, Serializable
{
static Logger logger = Logger.getLogger(TipoEmpresaConverter.class);

/** Creates a new instance of TipoEmpresaConvertor */
public TipoEmpresaConverter()
{
logger.debug("Contrutor TipoEmpresaConverter");
}

public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException
{
logger.debug("getAsObject - Object recieved was: " + value + " Type: " + value.getClass().getName());

if(value == null || "".equals(value)){
value = "0";
}

TipoEmpresa tipoEmpresa = new TipoEmpresa(Long.valueOf(value));

return tipoEmpresa;
}

public String getAsString(FacesContext context,
UIComponent component, Object value) throws ConverterException
{

logger.debug("getAsString - Object recieved was: " + value + " Type: " + value.getClass().getName());

if(value == null){
return "";
}
return ((TipoEmpresa)value).getId()+"";
}
}
 
Alan Teodoro
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot to mention that EmpresaBean.empresa.tipo is List<TipoEmpresa> and that is the way I provide the SelectItems:

private SelectItem[] comboTipoEmpresas = new SelectItem[2];

TipoEmpresa empresa1 = new TipoEmpresa(Long.valueOf(1));
TipoEmpresa empresa2 = new TipoEmpresa(Long.valueOf(2));
getComboTipoEmpresas()[0]= new SelectItem(empresa1,"Produtora");
getComboTipoEmpresas()[1]= new SelectItem(empresa2,"Distribuidora");
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have the same problem. However my converter is declared in faces-config.xml, and I refer to it with converter="myConverterID" (no surrounding '#{}'). getAsString() is called, but not getAsObject. I'm using MyFaces embedded with JBoss 4.0.4.GA. Did you solve this?
 
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Same problem here, no body had the solutiuon?
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You 'll have to override checkbox element within faces-config via render-kit

because internally it won't call the getasobject method

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems too late to answer but I resolved this by enabling validate on the component(selectManyListbox)

because convert is done after validate and also setting

on the button which is default value.

 
keep an eye out for scorpions and black widows. But the tiny ads are safe.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic