select first item in listbox using MVC not working.

asked 2019-02-22 07:24:23 +0800

bztom35 gravatar image bztom35
1 1

updated 2019-02-23 06:14:46 +0800

<bandbox id="rsStateTypeID" autodrop="true" sclass="labelstyleDetail" style="font-weight:plain; font-size:11pt; color: #00008B; " hflex="1" mold="rounded">
<bandpopup height="100%" sclass="labelstyle" width="280px">
<listbox id="rsStateListBox" width="250px" hflex="true" mold="paging" pagesize="5" model="@{rsStateModel}" selecteditem="@{RS.getStatename}" onselect="rsStateTypeID.value = self.selectedItem.label;rsStateTypeID.close();" checkmark="true">
<listhead> <listheader label="State Selection"/>
</listhead> <listitem self="@{each='RS'}" value="@{RS.getFcst_sensor_id} ">
<listcell label="@{RS.getStatename}"/>
</listitem> </listbox> </bandpopup> </bandbox>

public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp);

     /****************  Load State and Set Default State **************/
     StateData getStateTypeData = new StateData();
     this.rsStateModel = new ListModelList(getStateTypeData.getStateDataList());
    comp.setAttribute("rsStateModel", rsStateModel);


delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted

answered 2019-02-22 11:03:57 +0800

MDuchemin gravatar image MDuchemin
1346 1 4
ZK Team

Hi bztom35,

Unless there is a very specific reason to do otherwise, the best place for initialization code in composer is during doAfterCompose. I'd recommend using this block to also instantiate the model instead of beforeComposeChildren which happen at an in-between state of composition. I might be missing a few steps, since Bandbox itself doesn't use a model, but I'm assuming that you are hosting a listbox (or similar) inside the bandpopup?

From the sample you sent, the most important line would be model.addToSelection(model.get(0)) which is a reasonable way to initialize selection. However, this may stop working if you update the model after setting selection and remove the selected item from the model. Would need to see more of your code to know if this is what is happening

Here's a runnable example of a very basic case of using "select the first item during init" for reference http://zkfiddle.org/sample/rbvoal/1-select-first-item-in-model

Have a look :)

link publish delete flag offensive edit

answered 2019-02-26 00:35:01 +0800

bztom35 gravatar image bztom35
1 1

updated 2019-02-26 00:39:03 +0800

Thanks for your suggestions.

I was able to get it working by using a customized itemRenderer in the zul file.

:zul file

<bandpopup height="100%" sclass="labelstyle" width="280px" >="" <listbox="" id="rsStateListBox" width="250px" hflex="true" mold="paging" pagesize="5" <br=""> itemRenderer="${StateRenderer}" onSelect="rsStateTypeID.value = self.selectedItem.label;rsStateTypeID.close();" checkmark="true" > <listhead> <listheader label="State Selection"/> </listhead> </listbox> </bandpopup> </bandbox>

:Java class

public class StateRenderer implements ListitemRenderer { @Override public void render(Listitem item, Object data, int arg2) throws Exception { StateList st = (StateList) data; item.setLabel(st.getStatename()); item.setValue(st.getState_abbr());

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

1 follower



Asked: 2019-02-22 07:24:23 +0800

Seen: 12 times

Last updated: Feb 26

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