0

How to update text in TextGrid

I'm a new developer to tv widgets and I have not understand how to update the UI in widgets out of the updateView function. Specifically I want to change the data in my textGrid after I got a response from the XMLHttpRequest.

by
16 Replies
  • QUOTE (lemi_arg @ Jan 27 2010, 05:30 AM) <{POST_SNAPBACK}>
    I'm a new developer to tv widgets and I have not understand how to update the UI in widgets out of the updateView function. Specifically I want to change the data in my textGrid after I got a response from the XMLHttpRequest.

    Hi, you can update text with setText method like this:
    CODE
    this.controls.myTextGrid.setText('Lorem ipsum');
    0
  • Ok, I create a mainview and inside it a textgrid:

    var MainView = new KONtx.Class({
    ClassName: 'MainView',
    Extends: KONtx.system.FullscreenView,
    createView: function() {
    this.parent();

    this.controls.textGrid = new KONtx.element.TextGrid({
    guid: this.config.id + '.TextGrid',
    label: "Hello World I am Back",
    styles: {
    fontSize: KONtx.utility.scale(30),
    width: 600,
    height: 100,
    vAlign: "bottom",
    hAlign: "center",
    color: "#FFFFFF",
    scrolling: "left",
    scrollingSpeed: 40
    },
    }).appendTo(this);
    login();

    },

    Then I do an xmlhttprequest and in the response function I tried to use your statement
    function response(response){
    print("got response");
    this.controls.textGrid.setText('got response');
    return ;
    }

    In the debug windows I get (hello word is my widget)
    got response
    WD 00:00:47:982: [T:2178] got response
    WE 00:00:47:982: [T:2178] !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    WE 00:00:47:982: [T:2178] ERROR!ERROR!ERROR!ERROR!ERROR!
    WE 00:00:47:982: [T:2178] !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    WE 00:00:47:982: [T:2178] Hello World [com.helloworld]
    WE 00:00:47:983: [T:2178] TypeError: this.controls has no properties (widget.js: Line 96)
    0
  • Hi,
    Do not use login() and xmlhttprequest in CreateView. It is for creating your markup. Call login() in UpdateView instead.

    Cheers
    0
  • ...and btw
    "this" is context of response function is not the same as "this" for current view. You can try:
    CODE
    var theView = this;
    doRequest('url', function(data) {
    // On complete
    theView.controls.textGrid.setText(data);
    })


    And do this in updateView :)
    0
  • Usually this is what KONtx.messages API is used for.

    In your View you have something like this (note code is rough cut/paste not tested code).

    It's a really nice API to use if you're updating with async data updates.

    CODE
         initView: function() {
    this.registerMessageCenterListenerCallack(this._messageHandler);
    }

    _messageHandler: function(event) {
    if(event.type != KONtx.messages.eventType) return;

    // Note the key here "myData" maps to the one you're looking for above.
    if(event.payload.key == 'myData') {
    this.controls.myTextGrid.updateText(event.payload.value);
    }
    },


    Then in your XMLHTTPRequest handler

    CODE
    function response(response){
    // Note the key here "myData" maps to the one you're looking for above.
    KONtx.messages.store("myData', response);
    }
    0
  • Be wary of using the KONtx.message for storing information.

    We reworked our entire set of widgets to use this functionality and it does not work on some of the TV devices. (We found this out after numerous hours of work...)

    It works perfectly in the WDK, but crashed our testing device almost instantly.
    0
  • QUOTE (WidgetRealm @ Feb 1 2010, 08:07 AM) <{POST_SNAPBACK}>
    Be wary of using the KONtx.message for storing information.

    We reworked our entire set of widgets to use this functionality and it does not work on some of the TV devices. (We found this out after numerous hours of work...)

    It works perfectly in the WDK, but crashed our testing device almost instantly.

    You've got to be kidding me right? Why would this be in the developer documentation? We use this extensively.

    What TV devices specifically did you see the issues on?
    0
  • We have recently run into issues with it on all 2009 LG Televisions. We cannot confirm on the Samsungs or Sonys. Anyone?

    We also had a bug listing an issue which resulted in items being placed about 4 pixels lower on Vizio TV and WDK Sidebar.
    0
  • QUOTE (WidgetRealm @ Feb 1 2010, 10:08 AM) <{POST_SNAPBACK}>
    We have recently run into issues with it on all 2009 LG Televisions. We cannot confirm on the Samsungs or Sonys. Anyone?

    We also had a bug listing an issue which resulted in items being placed about 4 pixels lower on Vizio TV and WDK Sidebar.

    I've run our widget successfully on several Samsung models.
    0
  • Virtually all Yahoo! widgets use KONtx.messages on all platforms, including LG 2009. If Finance, News, and Video are working on the platform, then that means KONtx.messages _has_ to be working too.

    -Jeremy
    0
  • QUOTE (Jeremy Johnstone @ Feb 1 2010, 10:27 PM) <{POST_SNAPBACK}>
    Virtually all Yahoo! widgets use KONtx.messages on all platforms, including LG 2009. If Finance, News, and Video are working on the platform, then that means KONtx.messages _has_ to be working too.

    -Jeremy


    We welcome your thoughts on the widget we have had in the QA for weeks. It is successfully crashing our LG device when we use the message() functionality, but causes no problems without it.
    0
  • The bug is on line 44 of core.js in your widget and has nothing to do with KONtx.messages. It's actually an issue which was well communicated in numerous forms previously (sometime over past six months, been a while), including here on the forums.
    0
  • I am assuming you are referring to the platform.currentProfile.id which should be (profile.getCurrentProfile()).id

    Why would this not throw an error in the WDK if it is a device crashing call?

    Also interesting, but searching the forums for "platform.currentProfile.id" returns the entire forum and not specific results.
    0
  • This is _way_ off topic from the update text inquiry in this thread, but:

    http://developer.yahoo.net/forum/index.php?showtopic=1596

    QUOTE
    There is an issue with using platform.*


    That's from the sticky notes in the top of the forum. There are other spots too, but anything that is sticky should be reviewed constantly as it contains important information. All you needed to do to resolve the question was to remove platform. from the front of what you had on line 44. I was going to send you to that in an email this morning, but you beat me to the punch.
    0
  • QUOTE (Jeremy Johnstone @ Feb 3 2010, 09:53 AM) <{POST_SNAPBACK}>
    This is _way_ off topic from the update text inquiry in this thread, but:

    http://developer.yahoo.net/forum/index.php?showtopic=1596

    Not to continue the off topic+"ness" -> We did see that, but expected it only to apply to saving Data in the platform not the entire "platform" object. Thanks for the heads up.
    0
  • QUOTE (WidgetRealm @ Feb 3 2010, 07:13 PM) <{POST_SNAPBACK}>
    Not to continue the off topic+"ness" -> We did see that, but expected it only to apply to saving Data in the platform not the entire "platform" object. Thanks for the heads up.


    Thanks, I will add a note about that.

    -Jeremy
    0

Recent Posts

in General - Yahoo! TV Widgets