null converter en un SelectOneMenu!

UI Components for JSF
Post Reply
jotamarios
Posts: 13
Joined: 20 Jul 2013, 18:57

15 Apr 2014, 00:07

Hola a todos,

Tengo un selectOneMenu de primefaces y me está dando error:

Error de conversión al definir el valor 'Base.Categoria@53ac92aa' para 'null Converter'.
Error de conversión al definir el valor 'Base.Categoria@53ac92aa' para 'null Converter'

Este es mi SelectOneMenu:

[Translation]

Hi All,

I have a selectOneMenu of primefaces and I have this error:


Conversion Error setting value 'Base.Categoria@53ac92aa' for 'null Converter'

This is my SelectOneMenu [/translation]

Code: Select all

<p:column headerText="Padre">
                        <p:cellEditor>
                            <f:facet name="output">
                                <h:outputText value="#{categoria.padre.nombre}" />
                            </f:facet>
                            <f:facet name="input">
                                <p:selectOneMenu id="Sel_padres" value="#{categoria.padre}">
                                    <f:selectItem  itemLabel="Seleccione..." itemValue="0" noSelectionOption="true"  />
                                    <f:selectItems value="#{categoriaBean.categorias}" var="categoriaPadre" itemLabel="#{categoriaPadre.nombre}" itemValue="#{categoriaPadre}"></f:selectItems>
                                </p:selectOneMenu>
                                
                            </f:facet>
                        </p:cellEditor>
                    </p:column>


Es claramente una celda de un dataTable de primefaces... el value del SelectOneMenu es un objeto, y el itemvalue de los items también lo es de la misma clase.... una categoría puede tener un padre y éste padre es tipo categoría.... el error pareciera ser de casting... pero es raro porque ambos valores son del mismo tipo... alguien me podría decir porque?

[Translation]
Clearly this is a cell in a dataTable of primefaces... the value of the SelectOneMenu is an object, and the itemvalue of the items are the same class too... a category could have a parent and this parent is a category type... the error looks like a casting error but is rare because both values are the same type... somebody could tell me why? Thanks a lot!
[/Translation]
Last edited by jotamarios on 15 Apr 2014, 17:15, edited 1 time in total.

User avatar
snooperman
Posts: 155
Joined: 06 Nov 2012, 18:43

15 Apr 2014, 07:59

First of all, please use english when posting a question... My language has latin roots, so I could understand your problem, but maybe some people won't bother.
Second of all, your problem is that you don't quite know what a converter does. You need a converter because input controls in html form accepts only Strings.
So, Converters in JSF enables you to convert from String to Object and back from Object to String. If you don't want to use converters, you`ll have to use the SelectItem class.

Code: Select all


public class CategoriaBean{

     public List<SelectItem> getCategorias(){
        if (categorias== null){
            categorias = new ArrayList<SelectItem>();
            CategoriaService cs = ServiceFactory.getCategoriaService();
            List<Category> categoryList = cs.getAllCategories();
            for (Category cat : categoryList){
                categorias.add(new SelectItem(
                           cat
                            , cat.getName()); // value, label, the value to choose and label to appear to the user
            }
        }
        return categorias;
    }
}
var details = {
. . PF.version: "5.0.x",
. . JSF.version: "2.x",
. . Tomcat.version: "8.x"
}

jotamarios
Posts: 13
Joined: 20 Jul 2013, 18:57

15 Apr 2014, 17:09

Hi,

Thanks a lot, and my excuses about it, I forgot to translate my question because I was making the same question in another forum (spanish forum)....

I saw that I could use another type of object to make the convertion automaticly, but, ¿How will be the set of my original object if I have ItemValue = object (my own)... ? thats automatic? thanks a lot

User avatar
snooperman
Posts: 155
Joined: 06 Nov 2012, 18:43

16 Apr 2014, 15:23

If you are working on the same list of objects, ItemValue = object`s reference, and your original object will be set.
var details = {
. . PF.version: "5.0.x",
. . JSF.version: "2.x",
. . Tomcat.version: "8.x"
}

jotamarios
Posts: 13
Joined: 20 Jul 2013, 18:57

16 Apr 2014, 16:30

Hi, I used a converter, and it works fine, thanks a lot!

MESV
Posts: 4
Joined: 11 Sep 2014, 09:04

11 Sep 2014, 09:06

What is CategoriaService? I didn't understand it.

MESV
Posts: 4
Joined: 11 Sep 2014, 09:04

11 Sep 2014, 09:08

What is CategoriaService? I didn't understand it.

MESV
Posts: 4
Joined: 11 Sep 2014, 09:04

11 Sep 2014, 09:37

Hi! What is CategoriaService? I didn't understand it!

MESV
Posts: 4
Joined: 11 Sep 2014, 09:04

11 Sep 2014, 09:38

Hi! What is CategoriaService? I didn't understand it!

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 48 guests