aspose file tools*
The moose likes JSF and the fly likes getAsObject never called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "getAsObject never called" Watch "getAsObject never called" New topic
Author

getAsObject never called

Alan Teodoro
Greenhorn

Joined: Jul 14, 2005
Posts: 4
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

Joined: Jul 14, 2005
Posts: 4
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

Joined: Apr 29, 2004
Posts: 92
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?


Henrique Sousa<br />SCJP 1.4<br /> <br />All men die, not all men really live - Braveheart, 1995
Milton Ochoa
Ranch Hand

Joined: Oct 23, 2007
Posts: 336

Same problem here, no body had the solutiuon?
Munix Sharma
Greenhorn

Joined: Nov 30, 2007
Posts: 4
You 'll have to override checkbox element within faces-config via render-kit

because internally it won't call the getasobject method


Munix<br />SCJP 5.0
Kayvan Tehrani
Greenhorn

Joined: Jan 05, 2010
Posts: 1
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.


SCJP 6.0
 
Don't get me started about those stupid light bulbs.
 
subject: getAsObject never called