Menu

#392 Allow comboitems to carry a value payload

2.2.1
closed
nobody
5
2007-09-20
2007-03-12
No

A Combobox in many ways is "keyboard-friendly" replacement for Listbox. Our application is used by power-users who do a lot of data entry, so they always prefer combobox. However for the developer, it is annoying because a Comboitem only holds a text label, whereas a Listitem holds a label AND an underlying data value, which is much more convenient.

So Comboitem should have a getValue() method. For this to be useful, it would also be necessary to know the "selected" item of a Combobox. Obviously if the user has typed in their own text, then no item is selected. But if they have used the keyboard to select an item from the list, then we should be able to detect that value. See the below utility method for an example.

/**
* Devolver o comboitem atualmente selecionado, para o dado combobox.
* Ou seja, aquele item cuja description bate exatamente com o valor atual do combobox
*
* @return null se nao for achado nada que bate
*/
public static Comboitem getSelectedItem(Combobox combobox)
{
String value = StringUtils.trimToEmpty(combobox.getValue());

for(Comboitem item : (List<Comboitem>)combobox.getItems())
{
if(value.equals(item.getLabel())) { return item; }
}

//se chegarmos ate aqui, nao se encontrou nada entao devolve nul
return null;
}

Discussion

  • Cameron Smith

    Cameron Smith - 2007-09-20

    Logged In: YES
    user_id=873137
    Originator: YES

    Although the change was never announced, I notice that in ZK 2.4.1, Comboitem does now have a value payload, and it works fine! Nice one.

     
  • Cameron Smith

    Cameron Smith - 2007-09-20
    • status: open --> closed
     
  • Marcos de Sousa

    Marcos de Sousa - 2007-10-05

    Logged In: YES
    user_id=1691379
    Originator: NO

    It had been requested by me and was announced at release notes and features on ZK 2.4.1.

    The entry was: "Like listbox combobox must support getValue"

    And now, has an entry not yet closed "Like listbox, combobox CHECKBOX must support an getValue" accept an Object

    Regards,

    Marcos de Sousa

     

Log in to post a comment.

MongoDB Logo MongoDB