0

How to Change Listheader from Composer?

asked 2011-07-11 04:10:47 +0800

gellaps gravatar image gellaps
157 1

hi,
i have one Combobox,
when the Combobox value is changed, i want change the listheader too,

i have made this

	public void loadListIncident() {	
		listIncident.getItems().clear();
		listIncident.getHeads().clear();
		listIncident.getChildren().clear();
	
		Listhead lhd = new Listhead();
		if (cbTemplate.getValue().equalsIgnoreCase("default")){	
			Listheader lh = new Listheader();
			lh.setLabel("ID");
			lh.setParent(lhd);
			
			lh = new Listheader();
			lh.setLabel("DESCRIPTION");
			lh.setParent(lhd);
			
			lh = new Listheader();
			lh.setLabel("OWNER");
			lh.setParent(lhd);
			
			lh = new Listheader();
			lh.setLabel("STATUS");
			lh.setParent(lhd);
		
		}else if (!cbTemplate.getValue().equalsIgnoreCase("default")){	
			Listheader lh = new Listheader();
			lh.setLabel("ID");
			lh.setParent(lhd);
			
			lh = new Listheader();
			lh.setLabel("NAME");
			lh.setParent(lhd);
			
			lh = new Listheader();
			lh.setLabel("DESCRIPTION");
			lh.setParent(lhd);
			
			lh = new Listheader();
			lh.setLabel("DEPARTMENT");
			lh.setParent(lhd);
		}
		lhd.setParent(listIncident);
	}

invoked by this

	public void onChange$cbTemplate(Event event){
		loadListIncident();
	}


but i've got an error when i change the combobox value

Jul 11, 2011 4:05:17 PM org.zkoss.zk.ui.impl.UiEngineImpl handleError:1131
SEVERE: >>java.lang.UnsupportedOperationException
>>	at org.zkoss.zul.Listbox$Iter.remove(Listbox.java:2783)
>>	at java.util.AbstractCollection.clear(Unknown Source)
>>	at com.telkomsel.composer.reports.DynamicReportComposer.loadListIncident(DynamicReportComposer.java:311)
>>	at com.telkomsel.composer.reports.DynamicReportComposer.onChange$cbTemplate(DynamicReportComposer.java:124)
>>	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>>	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>>	at java.lang.reflect.Method.invoke(Unknown Source)
>>	at org.zkoss.zk.ui.event.GenericEventListener.onEvent(GenericEventListener.java:89)
>>	at org.zkoss.zk.ui.impl.EventProcessor.process0(EventProcessor.java:197)
>>	at org.zkoss.zk.ui.impl.EventProcessor.process(EventProcessor.java:141)
>>...

can someone help me?
i really don't where's the bug..

thanks for all of your kindly replies..

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2011-07-12 06:45:47 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

Hi Gellaps,
you do not need to create new header objects,
just change the label of origional headers.

a simple sample below, consists of 2 files,
test.zul and TestComposer.java,
the headers of the list will change while button clicked

WebContent / test.zul

<?script src="/js/someFoo.js" ?>
<zk>
	<window id="win" apply="test.TestComposer">
		<listbox id="testList">
            <listhead sizable="true">
                <listheader label="old label 1" sort="auto"/>
                <listheader label="old label 2" sort="auto"/>
                <listheader label="old label 3" sort="auto"/>
                <listheader label="old label 4" sort="auto"/>
                <listheader label="old label 5" sort="auto"/>
            </listhead>
            <listitem>
                <listcell label="data 1"/>
                <listcell label="data 2"/>
                <listcell label="data 3"/>
                <listcell label="data 4"/>
                <listcell label="data 5"/>
            </listitem>
        </listbox>
		<button id="testButton" label="test">
		</button>
	</window>
</zk>

src / test / TestComposer.java

package test;

import java.sql.Timestamp;
import java.util.Iterator;

import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Button;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listhead;
import org.zkoss.zul.Listheader;

public class TestComposer extends GenericForwardComposer {
	// newButton, variable name should equal to the id of the button in zul
	Button testButton;
	Listbox testList;
	// pattern: event + $ + variable name
	// onClick + $ + newButton here
	public void onClick$testButton() {
		Listhead lh = testList.getListhead();
		Listheader lhr = (Listheader)lh.getFirstChild();
		int i = 1;
		while(lhr != null) {
			lhr.setLabel(" new Label " + i++);
			lhr = (Listheader)lhr.getNextSibling();
		}
	}
}

link publish delete flag offensive edit

answered 2011-07-13 00:37:35 +0800

gellaps gravatar image gellaps
157 1

thank you benbai :)

but it didn't solve my problem yet, since i want to create a dynamic listbox,
and it means that the number of listhead will always change depending on demand..

moreover, i have solve my problem :)

this is they should be

	public void loadListIncident() {
	        /*just remove this
                listIncident.getItems().clear();
		listIncident.getHeads().clear();
                */
		listIncident.getChildren().clear();
	
		Listhead lhd = new Listhead();
		if (cbTemplate.getValue().equalsIgnoreCase("default")){	
			Listheader lh = new Listheader();
			lh.setLabel("ID");
			lh.setParent(lhd);
			
			lh = new Listheader();
			lh.setLabel("DESCRIPTION");
			lh.setParent(lhd);
			
			lh = new Listheader();
			lh.setLabel("OWNER");
			lh.setParent(lhd);
			
			lh = new Listheader();
			lh.setLabel("STATUS");
			lh.setParent(lhd);
		
		}else if (!cbTemplate.getValue().equalsIgnoreCase("default")){	
			Listheader lh = new Listheader();
			lh.setLabel("ID");
			lh.setParent(lhd);
			
			lh = new Listheader();
			lh.setLabel("NAME");
			lh.setParent(lhd);
			
			lh = new Listheader();
			lh.setLabel("DESCRIPTION");
			lh.setParent(lhd);
			
			lh = new Listheader();
			lh.setLabel("DEPARTMENT");
			lh.setParent(lhd);
		}
		lhd.setParent(listIncident);
	}

thank you :)

link publish delete flag offensive edit

answered 2011-07-19 08:09:06 +0800

pdavie gravatar image pdavie
97 3

updated 2011-07-19 08:10:20 +0800

gellaps, thanks for your post, it helped me solve the same issue. I've taken your approach a step further:

If you pass a regular string with say, commas, as the list header delimiters, you can also do this:

            void changeListHeader (String headings)
               {
               String[] hds = headings.split(",") ;     // Change this to whatever suits you, e.g. |
               
               listIncident.getChildren().clear() ;
               
               Listhead lhd = new Listhead() ;
               
               for (String label : hds)
                   {
                   Listheader lh = new Listheader () ;
                   lh.setLabel(label.trim()) ;
                   lh.setParent(lhd) ;
                   }
                              
               lhd.setParent(listIncident) ;
               }

To call this, you simply need to have wherever you want the list change to be triggered from, do this:

        changeListHeader ("First Heading, Second Heading, Some other Heading") ;

Hope that helps.

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: 2011-07-11 04:10:47 +0800

Seen: 352 times

Last updated: Jul 19 '11

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