0

Render a component in Java as Controller

asked 2012-10-27 03:10:04 +0800

progamerdotcom gravatar image progamerdotcom
117 5

updated 2012-10-27 03:11:43 +0800

Good Day,

I have a zul file as below

<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window title="new page title" border="normal">
New Content Here!
	<menubar id="menubar" apply="com.test.MenubarCtrl" ></menubar>
	
</window>
</zk>

and MenubarCtrl.java as below :

public class MenubarCtrl extends GenericForwardComposer {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Menubar menubar;
	private Menuitem item;
	
	@Override
	public void doAfterCompose(Component comp) throws Exception {
		// TODO Auto-generated method stub
		super.doAfterCompose(comp);
		item = new Menuitem();
		
		menubar = new Menubar();
		item.setParent(menubar);
		
	}

	public Menubar getMenubar() {
		return menubar;
	}

	public void setMenubar(Menubar menubar) {
		this.menubar = menubar;
	}
}

but I can't see menubar component when I run my project,

how to render menubar component in Java as controller.

thanks for advice;

delete flag offensive retag edit

8 Replies

Sort by ยป oldest newest

answered 2012-10-28 09:03:04 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Please use apply attribute in Window Component Something like this..
[code<window title="new page title" border="normal"apply="com.test.MenubarCtrl" >


And if you are using apply attribute you have to wire the Component from its id ,In Your case your MenuBar id is  <b >id="menubar"</b>
So in Java File you have to Wire this Component like this..

@Wire("menubar")
Menubar menuBar;

Andnow with this MenuBar do anhythind you want

link publish delete flag offensive edit

answered 2012-10-29 17:16:06 +0800

Steva77 gravatar image Steva77 flag of Italy
1014 3
http://www.research.softe...

Just quoting... ;)

Please use apply attribute in Window Component Something like this..

<window title="new page title" border="normal"apply="com.test.MenubarCtrl" >

And if you are using apply attribute you have to wire the Component from its id.
In Your case your MenuBar id is id="menubar"
So in Java File you have to Wire this Component like this..
@Wire("menubar")
Menubar menuBar;

And now with this MenuBar do anything you want!

link publish delete flag offensive edit

answered 2012-10-29 21:23:01 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

The GenericForwardComposer has the AutoWireing in it.

.. extends GenericForwardComposer {

private Menubar menubar; // autowired

is enough for getting access to the components by component ID.

link publish delete flag offensive edit

answered 2012-10-30 10:21:25 +0800

Steva77 gravatar image Steva77 flag of Italy
1014 3
http://www.research.softe...

Yes, correct!

link publish delete flag offensive edit

answered 2012-10-30 12:10:39 +0800

sjoshi gravatar image sjoshi flag of India
3493 1 8
http://zkframeworkhint.bl...

Thanks @Steva77, and @terrytornado

link publish delete flag offensive edit

answered 2012-11-01 07:23:28 +0800

progamerdotcom gravatar image progamerdotcom
117 5

ok thank All,
now I can generate menubar with menupopup and menuitem, but I have a problem with menuitem generated.

<menubar id="menubar" apply="com.trio.test.MenubarCtrl" autodrop="true" />
	
	<borderlayout height="100%">
			<north height="99%" splittable="true" collapsible="true"
				flex="true" border="normal">

				<iframe id="iframe" src="">

				</iframe>
			</north>
	</borderlayout>

*.java

for (Mstmenu mt : listMenu){
				
				if (mt.getVparent().equalsIgnoreCase("MASTERMENU")){
					
					item = new Menuitem();
					item.setLabel(mt.getVtitle());
					item.setParent(menupopupPMT);
					item.setImage(mt.getVimage());
					//item.setHref(mt.getVlocation());
					iframe = new Iframe();
					iframe.setSrc(mt.getVlocation());
					menupopupPMT.setParent(menuPMT);
					menuPMT.setParent(menubar);
				}
}

How to add event to item ( menuitem object ), with mt.getVlocation. (mt.getVlocation = path_to_zul_file.zul), the event will target to iframe ( Iframe object ).

Thanks.

link publish delete flag offensive edit

answered 2012-11-02 12:04:44 +0800

progamerdotcom gravatar image progamerdotcom
117 5

I modified that above code :

if (mt.getVparent().equalsIgnoreCase("MASTERMENU")){
					
					item = new Menuitem();
					item.setLabel(mt.getVtitle());
					item.setParent(menupopupPMT);
					item.setImage(mt.getVimage());
					item.addEventListener(Events.ON_CLICK, new EventListener() {
						
						@Override
						public void onEvent(Event arg0) throws Exception {
							iframe = new Iframe();
							iframe.setSrc("mypage.zul");
						}
					});
					menupopupPMT.setParent(menuPMT);
					menuPMT.setParent(menubar);
				}

but iframe doesnt render the "mypage.zul" ,, why ?

thanks

link publish delete flag offensive edit

answered 2012-11-03 00:43:02 +0800

progamerdotcom gravatar image progamerdotcom
117 5

I got it ,, with setParent for iframe additional.

if (mt.getVparent().equalsIgnoreCase("MASTERMENU")){
					
					item = new Menuitem();
					item.setLabel(mt.getVtitle());
					item.setParent(menupopupPMT);
					item.setImage(mt.getVimage());
					item.addEventListener(Events.ON_CLICK, new EventListener() {
						
						@Override
						public void onEvent(Event arg0) throws Exception {
							
							iframe.setSrc(mt.getVlocation());
							<b >iframe.setParent(win);</b>
							
						}
					});
					menupopupPMT.setParent(menuPMT);
					menuPMT.setParent(menubar);
				}

Thank all.

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: 2012-10-27 03:10:04 +0800

Seen: 182 times

Last updated: Nov 03 '12

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