Checking Null Values of Radiogroup and combobox
Hi Swapnil,
Better if you specify a little more about your problem or give a little example about how you implement it. Anyway... I control my zul page with a class which extends GenericForwardComposer. To avoid nullPointerExceptions you can to put a default element as selected, maybe to check previously with component.getItemCount(), or to be sure you have the value attribute before to do a component.getValue()...
For example, to load my combos I use something like:
for(MyOwnModel myModel : myList)
{
myComboItem = new Comboitem();
myComboItem.setLabel ( myModel.getNameToShow() );
myComboItem.setValue ( myModel.getNameValue() );
myCombo.appendChild ( myComboItem );
}
comboTipoNum.setSelectedIndex(0);Hope it helps.
Regards
Hi DaniG,
Appologies for late reply, I have a form in ZUL file with Combobox and radio group for filling the form. Now i want to keep these combobox and radiogroup component data as a optional for this form.But when i dont select any value for combobox and radiogroup and click on save, then it goes to composer in which i am selecting the value from these combobox for checking null values as (comboboox.getselecteditem.getlalabel();). it gives me null exceptions.
Please suggest any solutions for this..
Thanks in advance
Regard
Swapnil
Hi Swapnil,
Yes, I know what you mean. ZK is different (to javascript for example). When you have a Combobox with no selection or default value it returns null, not blank ( "" ). I do:
myComboItem = new Comboitem();
myComboItem.setLabel ( " " );
myComboItem.setValue ( "" );
myCombo.appendChild ( myComboItem );
for(MyOwnModel myModel : myList)
{
myComboItem = new Comboitem();
myComboItem.setLabel ( myModel.getNameToShow() );
myComboItem.setValue ( myModel.getNameValue() );
myCombo.appendChild ( myComboItem );
}
comboTipoNum.setSelectedIndex(0);for the "blank" element of my Combobox, and select it as default to prevent the null value. And if you have Comboitems I would suggest you use better the value attribute when you can:
myComboItem.setLabel ( myModel.getNameToShow() ); myComboItem.setValue ( myModel.getNameValue() );
When it is the same as label then:
myComboItem.setLabel ( myModel.getNameToShow() ); myComboItem.setValue ( myModel.getNameToShow() );
and to get it with myCombo.getSelectedItem().getValue();
Hope it helps you.
Regards
ZK - Open Source Ajax Java Framework
Hello Everyone,
Need help on checking null values of radiogroup and combobox items?
Thanks
Swapnil