PickList: how do I create converter when working with POJO

UI Components for JSF
Post Reply
KingdomHeart
Posts: 280
Joined: 25 Jun 2010, 01:18

01 Sep 2010, 23:30

The documentation said that I need to write my own converter when working with POJO. What do I need to convert the POJO to? to String? Can someone give me an example?

Mojarra 2.1.10, Glassfish 3.1, Tomcat 7, Primeface 3.3.1
IE 6-8, FireFox 10-13
MAC OSX Lion, Windows XP, 7

callahan
Posts: 768
Joined: 27 May 2010, 22:52

02 Sep 2010, 00:19

As a general rule, the user's guide is not about JSF in general, it's about PrimeFaces in particular. It's terse and to the point. Most examples in the user's guide are from the showcase. If you feel that some piece of code is missing from the user's guide, it probably isn't. The code that you feel is missing is most likely about JSF in general and not about PrimeFaces in particular.

You'll find the code that you're looking for in the showcase which can be downloaded here http://repository.prime.com.tr/org/prim ... -SNAPSHOT/.

The files you need to look at are PlayerConverter.java and faces-config.xml. The class PlayerConverter is registered as a converter in faces-config.xml.

KingdomHeart
Posts: 280
Joined: 25 Jun 2010, 01:18

02 Sep 2010, 19:45

I thought I figure it out, but apparently not. So I display the list correctly on the left, when I start picking out item and move to the right, and click submit, I got exception error "java.lang.NullPointerException"

Code: Select all

java.lang.NullPointerException
	at org.xdrawing.converter.ProjectConverter.getAsObject(ProjectConverter.java:36)
This is my converter

Code: Select all

    @EJB
    DocumentSBean sBean;
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if(value.trim().equals("")){
            return null;
        }
        return sBean.getProjectById(value);  //This line of code is where it break, can u access the EJB from here?
    }

    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if(value == null){
            return null;
        }
        return ((Project) value).getId().toString();  //Return the Primary Key so that it can be used to uniquely query out the object.
    }
The line "return sBean.getProjectById(value); " break it. I debug using Netbean and it turn out the EJB "sBean" value is null. Is there a way to fix this?

Mojarra 2.1.10, Glassfish 3.1, Tomcat 7, Primeface 3.3.1
IE 6-8, FireFox 10-13
MAC OSX Lion, Windows XP, 7

callahan
Posts: 768
Joined: 27 May 2010, 22:52

02 Sep 2010, 22:36

A converter isn't an appropriate target for injecting an EJB. Managed beans are, but not converters. You're current issue isn't related to PrimeFaces.

KingdomHeart
Posts: 280
Joined: 25 Jun 2010, 01:18

02 Sep 2010, 23:58

Sorry, I did not mean to bring off your realm like this. However, I figure it out, you either use InitialContext then JNDI lookup or you change the converter to Managed Bean.

Mojarra 2.1.10, Glassfish 3.1, Tomcat 7, Primeface 3.3.1
IE 6-8, FireFox 10-13
MAC OSX Lion, Windows XP, 7

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

03 Sep 2010, 01:09

Standard JSF does not provide injecting EJBs or other things to converters/validators. For example you can use Seam-Faces module to do this afaik, JNDI is also an option for lookup. Also for Spring users, you can get it via a static lookup.

LCT
Posts: 9
Joined: 05 Sep 2017, 11:48

15 Feb 2018, 14:18

Hi,
I use a POJO with picklist. but the selectGroupes in

Code: Select all

listModel = new DualListModel<Groupe>(allGroupes, selectGroupes);
is always empty. can some body help me?

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

15 Feb 2018, 20:51

Please create a new question with a 'mcve' instead of resurecting a 7.5 year old question

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 36 guests