• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getAsObject never called

 
Alan Teodoro
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
  • 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");
 
Henrique Sousa
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • 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?
 
Milton Ochoa
Ranch Hand
Posts: 336
Firefox Browser Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same problem here, no body had the solutiuon?
 
Munix Sharma
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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

 
Kayvan Tehrani
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic