0

Help with Focus on ToolbarButton

asked 2010-05-18 09:04:08 +0800

santiago gravatar image santiago
42

updated 2010-05-18 09:45:16 +0800

Hello, greetings to all, I have a ZK application with 5.0.2 version, i have a problem with the ToolbarButton , the the buttons from the bar do not get the focus when i press the TAB button, when i add a textbox in the toolbar, the textbox can get the focus but the toolbar buttons still can't

PD: In the ZK version 3.6.4 i didn't have that problem

Please Help

prueba.zul

<window id="win" title="Prueba" width="500px" use="page.Prueba">
<button label="Foco" onClick="win.foco()"/>

<toolbar id="tb" align="end" style="background:#defeff repeat-x 0 0;padding-top:7px">
<textbox />
<toolbarbutton id="btnGrabar" label="Grabar" image="/img/Save.png"
onClick="win.onClose()" />
<button id="btnIgnorar" label="Ignorar" image="/img/Undo.png"
onClick="win.onClose()" />
<toolbarbutton id="btnSalir" label="Salir" image="/img/Power.png"
onClick="win.onClose()" />
</toolbar>
</window>

Prueba.java

package page;

import org.zkoss.zul.Window;
import org.zkoss.zul.Toolbarbutton;

public class Prueba extends Window {

private Toolbarbutton btnGrabar;

public void onCreate() {
initcomponentes();
}

private void initcomponentes() {
btnGrabar = (Toolbarbutton) getFellow("btnGrabar");
}

public void foco() {
btnGrabar.setFocus(true);
}

}

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2010-05-18 20:19:17 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Hi santiago
You can set tabindex

<window id="win" title="Prueba" width="500px">
	<button label="Foco" tabindex="1" />
	<toolbar id="tb" align="end"
		style="background:#defeff repeat-x 0 0;padding-top:7px">
		<textbox tabindex="2" />
		<toolbarbutton id="btnGrabar" label="Grabar"
			image="/img/Save.png" tabindex="3" />
		<button id="btnIgnorar" label="Ignorar" image="/img/Undo.png"
			tabindex="4" />
		<toolbarbutton id="btnSalir" label="Salir"
			image="/img/Power.png" tabindex="5" />
	</toolbar>
</window>

link publish delete flag offensive edit

answered 2010-05-19 10:02:02 +0800

santiago gravatar image santiago
42

hi, thanks for your answer

i have this button on my .zul

<button id="btnFoco" label="Foco" onClick="win.foco()"/>

<toolbarbutton id="btnGrabar" label="Grabar" image="/img/Save.png"
onClick="win.onClose()" />
<button id="btnIgnorar" label="Ignorar" image="/img/Undo.png"
onClick="win.onClose()" />
<toolbarbutton id="btnSalir" label="Salir" image="/img/Power.png"
onClick="win.onClose()" />


is there any way to send the focus to the toolbarbutton by clicking on the "btnFoco" button which calls the "foco" method.
I tried to do it with this code:

public void foco() {
btnGrabar.setFocus(true);
}

but it doesn't work... please help mee

link publish delete flag offensive edit

answered 2010-05-19 10:42:10 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

updated 2010-05-19 10:45:31 +0800

It cause by below code

 if (!jq.nodeName(n, 'button', 'input', 'textarea', 'a', 'select', 'iframe'))
    return false; 

in ZK 3, toolbutton is a "a" tag
but we modify to a "div" in ZK 5

we will fix it after we decide it whether is a bug or spec

You can use client side to control it
it is more fast then control from server

I create a sample
<zk xmlns:w="http://www.zkoss.org/2005/zk/client">
	<script type="text/javascript"><![CDATA[
		function foco(){
			jq("$btnGrabar").focus();
		}
	]]></script>
	<button label="Foco" w:onClick="foco();"/>
	<toolbarbutton id="btnGrabar" label="Grabar"/>
</zk>


more information

link publish delete flag offensive edit

answered 2010-05-19 12:48:54 +0800

santiago gravatar image santiago
42

thanks for the support

the only way is to generate a function which set the focus for each toolbarbutton.

function foco1(){
jq("$btnGrabar").focus();
}

function foco2(){
jq("$btnSalir").focus();
}

is there any way to invoque jquery from java instead of the client side (.zul)

link publish delete flag offensive edit

answered 2010-05-19 19:43:09 +0800

jimmyshiau gravatar image jimmyshiau
4921 5
http://www.zkoss.org/ ZK Team

Yes you can use Clients

<zk >
	<zscript><![CDATA[
		public void foco(){
			Clients.evalJavaScript("jq('$btnGrabar').focus();");
		}
	]]></zscript>
	<button label="Foco" onClick="foco();"/>
	<toolbarbutton id="btnGrabar" label="Grabar"/>
</zk>

link publish delete flag offensive edit

answered 2010-05-20 09:57:07 +0800

santiago gravatar image santiago
42

thanks for your support
it was very helpful

link publish delete flag offensive edit

answered 2019-03-30 17:26:55 +0800

LuigiFabbri gravatar image LuigiFabbri
46 5

updated 2019-03-30 20:20:04 +0800

I solved this problem this way:

1) put in lang-addon.xml this rows

<component>
<component-name>mytoolbarbutton</component-name>
<extends>toolbarbutton</extends>
<componentclass>MyToolbarButton</component-class>  
</component>

2) Extend toolbarbutton

import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zk.ui.event.Event;  
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.Toolbarbutton;

public class MyToolbarButton extends Toolbarbutton implements IdSpace{
/**
 * 
 */
private static final long serialVersionUID = 1L;

public MyToolbarButton()
{
    this.addEventListener(Events.ON_CREATE, new EventListener<Event>() {
        public void onEvent(Event event){
            Clients.evalJavaScript("jQuery(\"#" +     MyToolbarButton.this.getUuid()+"\").attr(\"href\",\"\");");
            Clients.evalJavaScript("jQuery(\"#" + MYToolbarButton.this.getUuid()+"\").attr(\"onclick\",\"return false;\");");
        }
    });
}

}

3) Use <mytoolbarbutton>

Regards

Luigi

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: 2010-05-18 09:04:08 +0800

Seen: 744 times

Last updated: Mar 30

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