0

selectbox - null pointer exception

asked 2016-01-02 19:42:17 +0800

jawak gravatar image jawak
3 1

Hi, I have a SELECTBOX for loading Value/Text types of data. when i delete a selected item, the refresh code works fine. However, if i delete another item in the same dropdown immediately, the same refresh code throws "null pointer exception". any help would be appreciated.

In the below code, "model.getSelection();" throws that error. Model still holds values at this point.

ZUL <selectbox id="mfrListbox" model="${$composer.mfrModel}" >="" <template="" name="model"> ${each.text} </template> </selectbox>

@Listen("onClick=button#btnDelMfr") public void DelMfr() throws SQLException { Header sHeader = new Header(); sHeader.setManufacturer(getStringValue("mfrListbox", mfrModel)); HardwareDb hardwareDb = new HardwareDb(); hardwareDb.DelMfr(sHeader); RefreshManufacturer();
}

String getStringValue(String componentId, ListModelList<socketheader.valuetype> model) {

        Set<SocketHeader.ValueType> types = model.getSelection();
        SocketHeader.ValueType type = types.iterator().next();
        return type.getValue();

}

delete flag offensive retag edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2016-01-03 10:30:18 +0800

Darksu gravatar image Darksu
1991 1 4

Hello jawak,

From the code sample i think you are not refreshing the mfrModel once an item is deleted. Probably this causes the exception.

Best Regards,

Darksu

link publish delete flag offensive edit
0

answered 2016-01-04 20:14:40 +0800

jawak gravatar image jawak
3 1

Hi Darksu,

Actually, there is a function being called right after delete is executed. Yes, it does refresh the mrfModel.

private void RefreshManufacturer() throws SQLException {
    mfrListbox.setModel(new ListModelList<SocketHeader.ValueType>(getManufacturer()));
    mfrModel = new ListModelList<SocketHeader.ValueType>(getManufacturer());        
}

Here is my test case.

Lets say there are 10 values loaded initially into the SELECT BOX. First, I DELETED Item 9 from the dropdown and refreshed the drop down. Now, the drop down has 9 values which is correct. Next, I deleted Item 8 again and then calling the same code. This time, model.getSelection() returns size = 0. It is suppose to return Item 8. why it is failing?

link publish delete flag offensive edit
0

answered 2016-01-06 23:15:31 +0800

jawak gravatar image jawak
3 1

The sync up between model and listbox should be reversed in order to work. This resolved my issue.

private void RefreshManufacturer() throws SQLException { mfrModel = new ListModelList<socketheader.valuetype>(getManufacturer());
mfrListbox.setModel(mfrModel); }

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2016-01-02 19:42:17 +0800

Seen: 17 times

Last updated: Jan 06 '16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More