0
votes

I use Hibernate, Spring and JSF (Primefaces) in my project. I want to create a picklist with simple POJO (Entity). Here is what I created:

<p:pickList id="pickList" converter="#{groupConverter}" value="#{adminUsersMB.groups}" var="group"   
                        itemLabel="#{group.name}" itemValue="#{group}" >

                        <f:facet name="sourceCaption">Available groups</f:facet>  
                        <f:facet name="targetCaption">Users groups</f:facet> 

 </p:pickList>

My Converter is:

@RequestScoped
@FacesConverter(forClass=Group.class, value="groupConverter")
public class GroupConverter implements Converter {

    @ManagedProperty(name="groupService", value="#{groupService}")
    @Getter @Setter
    GroupService groupService;

    @Override
    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
        try {
            return groupService.getGroupByName(Integer.parseInt(arg2));
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
        return ((Group) arg2).getId().toString();
    }

}

of course I added my custom converter to the faces config:

<converter>
        <converter-id>groupConverter</converter-id>
        <converter-class>pl.proedims.users.component.GroupConverter</converter-class>
</converter>

But when I commit the form, I got exception:

> SEVERE: javax.el.PropertyNotFoundException: /admin/user.xhtml @73,66
> itemLabel="#{group.name}": Property 'name' not found on type java.lang.String
1
remove the converter from faces config (cause you already used the FacesConverter annotation) and tryDaniel
What is the definition of adminUsersMB.groups? Is seems to think that group is a string.SteveS

1 Answers

1
votes

Problem solved. All i needed was to type:

@Component("groupConverter")
public class GroupConverter implements Converter {

    @Autowired
    GroupService groupService;
    (...)