converter with producer method/field for p:selectOneMenu

Posted: August 27, 2012 in web

managed bean / producer

private List<Card> cards;

public List<Card> getCards() {
return cards;


@FacesConverter(forClass = Card.class)
public class CardConverter implements Converter {

List<Cards> cards;

public CardConverter() {

public CardConverter(List<Card> cards) { = cards;

public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (cards == null) {
return null;
} else {
for (Card card : cards) {
if (card.getTitle().equals(value)) {
return card;

return null;

public String getAsString(FacesContext context, UIComponent component, Object object) {
if (object == null) {
return null;
} else {
return ((Card) object).getTitle();



<p:selectOneMenu value=”#{bean.activeCard}”
<f:selectItem itemLabel=”Select Card”
itemValue=”null” />
<f:selectItems value=”#{}” var=”card”


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s