PickList: how do I create converter when working with POJO
-
- Posts: 280
- Joined: 25 Jun 2010, 01:18
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
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.
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.
-
- Posts: 280
- Joined: 25 Jun 2010, 01:18
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"
This is my converter
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?
Code: Select all
java.lang.NullPointerException
at org.xdrawing.converter.ProjectConverter.getAsObject(ProjectConverter.java:36)
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.
}
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
-
- Posts: 280
- Joined: 25 Jun 2010, 01:18
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
-
- Prime
- Posts: 18616
- Joined: 05 Jan 2009, 00:21
- Location: Cybertron
- Contact:
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.
Hi,
I use a POJO with picklist. but the selectGroupes in is always empty. can some body help me?
I use a POJO with picklist. but the selectGroupes in
Code: Select all
listModel = new DualListModel<Groupe>(allGroupes, selectGroupes);
-
- Information
-
Who is online
Users browsing this forum: No registered users and 36 guests