0

How to access ZK components by JavaScript

asked 2013-12-06 15:55:57 +0800

yasinsahin gravatar image yasinsahin
6

updated 2013-12-06 21:53:01 +0800

Hi all,

I want to set value of a zk datebox from javascript. Actually I can set the value but when I want to access its value, it is throwing a null pointer exception. More generally, some abilities of the zk components can be manupulated but others not. For example I can fire a button onclick event but I can not set an attribute of that button by javascript.

For example these two work : zk.Widget.$('$startDateProxy').setValue(start); zk.Widget.$('$addEventBtn').fire('onClick');

But these two not: zk.Widget.$('$startDateProxy').setAttribute("startDate",start) -> cutting the operation alert(startDateProxy.getValue().toString()) -> null pointer

Thanks

PS: I am trying to use FULLCALENDAR (arshaw.com/fullcalendar)

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-12-09 02:53:04 +0800

ashishd gravatar image ashishd flag of Taiwan
1972 6

Assuming startDateProxy is a ZK Datebox component, First, there is no startDate attribute for Datebox. Second, zk.Widget.$('$startDateProxy').setAttribute("startDate",start) fails because there is no setAttribute JS API for ZK Widgets. You have to call attribute's corresponding setter method.

For null pointer exception it is expected. If you are updating Widget values by custom code it is your job to also sync it with server side. Check this sample code

<zk xmlns:w="client">
<label id="tb" width="250px" value="hello" >
    <custom-attributes org.zkoss.zk.ui.updateByClient="true"/>
</label>
<button label="chage at client-side">
    <attribute w:name="onClick"><![CDATA[
        var tb = zk.Widget.$(jq('$tb')),
            val = 'world';
        tb.setValue(val);
                tb.smartUpdate('value', val);
    ]]></attribute>
</button>
<button label="get at server-side" onClick="alert(tb.value)"/>
 </zk>

Hope this helps.

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

Follow
1 follower

RSS

Stats

Asked: 2013-12-06 15:55:57 +0800

Seen: 53 times

Last updated: Dec 09 '13

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