0

Retrieving selected items from a listBox

asked 2008-11-24 04:02:21 +0800

judacoor gravatar image judacoor
280 1 3 8

Hello everybody

I'm trying to obtain the selected items from a listBox, in order to apply a function that deletes records from a database.

So far, I've got this on the zul file:

<window id="sugeSearch" width="100%" use="npBO.suge.SugeSearch">
<div align="left" width="100%">
<listbox id="sugeList" checkmark="true" width="100%"
multiple="true" mold="paging" onCreate="sugeSearch.fillGrid()">
<listhead>
<listheader label=" " width="50px"/>
<listheader label="Type" sort="auto" />
<listheader label="Subjetc" sort="auto" />
<listheader label="Comment" sort="auto" />
</listhead>
</listbox>
<separator/>
<button label="Delete selected" onClick="sugeSearch.deleteChecked()" />
</div>
</window>


And on the java file I've got:

fillGrid(){
ListBox g......

lit = new Listitem();
lit.appendChild(lic2);
lit.appendChild(lic3);

lit.setAttribute("idSuge", result.getIdSugerencia());
g.appendChild(lit);
}

For filling the grid with the stuff from the DB.


And the method that I want to use to delete:

public void deleteChecked(){
Listbox g = (Listbox)getDesktop().getPage("SugeSearch").getFellow("sugeSearch").getFellow("sugeList");
Set set = g.getSelectedItems();

for (int i = 0; i < set.size(); i++) {

}

List list = g.getChildren();
for (int i = 3; i < list.size(); i++) {
Listitem li = (Listitem) list.get(i);
int idSuge = Integer.parseInt(li.getAttribute("idSuge").toString());

}
}

But it says that it can't cast from Header (listHeader I suppose) to Listitem. So I have absolutely no idea of how to retrieve the selected/checked rows from the listBox in order to get the idSuge attribute from each one of them, so I can then erase those items from the DB.

Could someone please help me??

Or is there any better way to do this?

Thank you guys so much!

judacoor

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2008-11-24 08:41:54 +0800

ziccardi gravatar image ziccardi
321 7

>Or is there any better way to do this?

In my opinion, it would be much better if you would work another way.

1st: change

<window id="sugeSearch" width="100%" use="npBO.suge.SugeSearch"> 

to

<window id="sugeSearch" width="100%" apply="npBO.suge.SugeSearch"> 

2nd: change your zul file to something similar to:

<window id="sugeSearch" width="100%" apply="npBO.suge.SugeSearch">
   <div align="left" width="100%">
      <listbox id="sugeList" checkmark="true" width="100%"  multiple="true" mold="paging">
        <listhead>
        <listheader label=" " width="50px"/>
        <listheader label="Type" sort="auto" />
        <listheader label="Subjetc" sort="auto" />
        <listheader label="Comment" sort="auto" />
        </listhead>
      </listbox>
      <separator/>
      <button label="Delete selected" id="btnDelete" />
   </div>
</window> 

3rd: use a model and a renderer to fill your listbox

4th: change your SugeSearch class to something similar to the following:


public class SugeSearch extends GenericForwardComposer
{
   // This variable is automatic attached to the sugeList listbox
   // (see MVC made easy small talk)
   private Listbox sugeList;
  
   public void doAfterCompose(Component comp)
   {
      super.doAfterCompose(comp);
      // Create your model 
      // Apply your model to the listbox:
      sugeList.setModel(yourModel);
      // Create and apply your renderer
      sugeList.setItemRenderer(yourRenderer);
   }


   // This method is automatic attached to the onClick event of the
   // btnDelete button (see MVC made easy small talk)
   public onClick$btnDelete(Event evt)
   {
      Set set = g.getSelectedItems();
      // do what you want with selected items...
   }

}

link publish delete flag offensive edit

answered 2008-11-25 04:11:32 +0800

judacoor gravatar image judacoor
280 1 3 8

Thank you so much for taking the time to help me ziccardi!

I've read the small talk on MVC and so far I've got:

<window title="Composer Test" border="normal" use="test.Composer" >
<grid>
<rows>
<row>First Name: <textbox id="firstName"/></row>
<row>Last Name: <textbox id="lastName"/></row>
<row>Full Name: <label id="fullName"/></row>
</rows>
</grid>
<separator/>
<button id="myButton" label="I've not been clicked yet"></button>

</window>
</zk>

And:

public class Composer extends Window implements AfterCompose {

private Textbox firstName;
private Textbox lastName;
private Label fullName;
private Button myButton;
private int carry =1;


//onChange event from firstName component
public void onChange$firstName(Event event) {
fullName.setValue(firstName.getValue()+" "+lastName.getValue());
}

//onChange event from lastName component
public void onChange$lastName(Event event) {
fullName.setValue(firstName.getValue()+" "+lastName.getValue());
}

public void onClick$myButton(Event event){
myButton.setLabel("You've Clicked me "+this.carry+" time(s)");

this.carry++;
this.setTitle(fullName.getValue());
this.getPage().setTitle(fullName.getValue()+" times "+this.carry);
}


public void afterCompose() {
Components.wireVariables(this, this);
Components.addForwards(this, this);
}

}

And it's working awesome!!

I could not use the apply attribute on the window, for the java class needs to extend the class Window for several purposes but the wireVariables and autoForward is working seamlessly, su I've decided to have it "use" the composer class and there you go.

I think it's working really good! I'll try to have it work with the listBox and if I encounter any trouble I'll post it on this thread.......hoping that maybe you can give me a little hand.

Thank you so much ziccardi!

link publish delete flag offensive edit

answered 2009-01-30 13:59:17 +0800

ridams gravatar image ridams
6

<marquee>hi</marquee>

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2008-11-24 04:02:21 +0800

Seen: 1,440 times

Last updated: Jan 30 '09

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