Skip to Content

SAP UI5 XML View access html contrrol

I need to change an JS view to an XML View. Problem is in the JS was an Html Control with a canvas. I need to access the Canvas but i dont get it to work in the xmlView. Code is as follows:

http://www.w3.org/1999/xhtml">

<App>

<pages>

<Page id="CanvasPage" >

</Page>

</pages>

And in the controller i ad the control but cant access the Canvas.

onInit: function() {

var map = this.getView().byId("CanvasPage");

var canvas = new sap.ui.core.HTML({

content: "<canvas id='Map' width='860' height='624' "

+ "style='border:1px solid #000000;'>"

+ "</canvas>" });
map.addContent(canvas);
var hmap = document.getElementById('Map');
I need to access the canvas. I can see it on the page. but
document.getElementById('Map');
doesnt work. I get null as return. Anyone an Advice?
Regards.

Dirk

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Mar 12, 2017 at 06:41 PM

    i think it is timing issue.

    can u do it onafterrendering?

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Mar 13, 2017 at 02:14 AM

    A code to render canvas should be at View.

    Check below code

    <App>
    <pages>
    <Page id="CanvasPage" >
     <core:HTML content='<canvas id="Map" width="860" height="624" style="border:1px solid #000000;">'>
     </core:HTML>
    </Page>
    </pages>
    
    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Check your code.

      1. You should a namespace for core like this

      <mvc:View	xmlns:l="sap.ui.layout"	xmlns:core="sap.ui.core"
      

      2. And replace a special characters.

      1) < to "& l t;"

      2) > to "& g t;"

      3) ' to "& q u o t;"

      code.png (25.9 kB)
  • Mar 15, 2017 at 08:46 AM

    Thanks,

    i still miss that i have to replace the special charachters.
    Now it works and i can declare the canvas in the view.

    regards

    Dirk

    Add comment
    10|10000 characters needed characters exceeded