0

I want to use Javascript sent some data to zk's view Model

asked 2015-04-23 10:44:56 +0800

CPLUSx2 gravatar image CPLUSx2
1

same as title

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2015-04-23 21:50:10 +0800

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

updated 2015-04-23 23:31:35 +0800

Zul:

<window ... apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') 
@init('de.oxitec.zkboost.websocket.webrtc.OXWebsocketWebRtcVM')">

<div id="divRemoteVideo" visible="false" style="overflow:auto;"
     onMyEvent="@command('createVideo', 
                          parent=event.data.parent, 
                          username=event.data.username, 
                          src=event.data.src)">
   <!--  some stuff here -->
</div>

Javascript:

//  Fire an event to the ViewModel.

function myFunction(){
    var widget;

    // Get ZK widget
    widget = zk('$divRemoteVideo').$();

    // widget fires SELF-DEFINED event
    widget.fire('onMyEvent', {
      // sample params to send to ViewModel
      parent : 'divRemoteVideo',
      username : 'TerryTornado',
      src : URL.createObjectURL(stream)
     }, {toServer : true })
}

ViewModel:

@Command("createVideo")
public void createVideo(@BindingParam("parent") String _parent, 
                        @BindingParam("username") String _username, 
                        @BindingParam("src") String _src) {

// your code here
System.out.println(_parent + " | " + _username + " | " + _src );
}

Attention: Such things are not safety. Every guy can open your js file and call such a function.

best Stephan

PS: I take votes :-)

link publish delete flag offensive edit

Comments

Got to learn a new thing today :) Thanks Stephan +1

RD190 ( 2015-04-24 08:21:16 +0800 )edit

Cool, upvoted it.

echarish ( 2015-04-24 08:24:11 +0800 )edit

Thank you, just a head up, I was getting an empty data map because i tried to use the onClick event.

WilliamB ( 2015-06-15 15:00:52 +0800 )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: 2015-04-23 10:44:56 +0800

Seen: 25 times

Last updated: Apr 23 '15

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