• Post Reply Bookmark Topic Watch Topic
  • New Topic

SelectItem Pardox  RSS feed

 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I pray that it is my own ignorance that has led me to post this topic and not truth.

What I want:
I'm currently writing a bean to use with selectoneMenus. When an item is selected it stores it into a holding bay where it can be accessed by various accessor methods. I need to be able to grab the description, label, and value of the currently selected item.

Listener:


JSF code:


What I get:
The Label and Value are the same and Description is null!

What the API says about the SelectItem constructor I'm using:
Parameters:
value - Value to be delivered to the model if this item is selected by the user
label - Label to be rendered for this item in the response
description - Description of this item, for use in tools

Why this presents me with a paradox:
Reread the API

If I try to put an item in value, I get a null pointer exception.

Anythoughts?
If I figure out anything I'll make sure to post it
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I see the listboxBean.listboxItems method? I'd like to see how you are building your selectItems. That may lead to the answer.
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
addSelectItem(new SelectItem("fooValue", "barLabel", "bazDescription"));

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

public void listboxListener(ValueChangeEvent vce) {
SelectItem item = new SelectItem(vce.getNewValue());

vce.getNewValue() does not return a SelectItem. It returns the value. You can't get the SelectItem from vce.
 
Mauro Castaldo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:

public void listboxListener(ValueChangeEvent vce) {
SelectItem item = listboxHash.get(vce.getNewValue());
setSelectedItem(item);
System.out.println("value: " + (String)item.getValue());
System.out.println("label: " + item.getLabel());
System.out.println("description: " + item.getDescription());
}

public void addSelectItem(SelectItem selectItem) {
if (selectItem != null) {
listboxItems.add(selectItem);
listboxHash.put(selectItem.getValue(), selectItem);
setSelectedItem(selectItem);
}
}


Mauro Castaldo
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you and sorry... That's what I'm doing now
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't get the SelectItem from vce.
Would I be able to by any other means? I want the listbox to be able to learn.
 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and if I do it this way I can't have two items with the same value! It swaps me around and acts funky.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!