Hybrid View

  1. #1
    Sencha User
    Join Date
    Jul 2011
    Posts
    3
    Vote Rating
    0
    Schoumy is on a distinguished road

      0  

    Default Unanswered: Cannot use data:image/png;base64 in XTemplate

    Unanswered: Cannot use data:image/png;base64 in XTemplate


    Hi !

    I try to use XTemplate and insert a Base64 image in HTML.

    So i wrote :
    <img src="{image.base64}"/>

    With base64 = data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==

    But the image won't be displayed

  2. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Answers
    109
    Vote Rating
    89
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    You probably added it as a String, use a SafeUri instead. See the source for the example at http://www.sencha.com/examples-dev/#...Place:combobox

    Code:
      interface ComboBoxTemplates extends XTemplates {
     
        @XTemplate("<img width=\"16\" height=\"11\" src=\"{imageUri}\"> {name}")
        SafeHtml country(SafeUri imageUri, String name);
     
        @XTemplate("<div qtip=\"{slogan}\" qtitle=\"State Slogan\">{name}</div>")
        SafeHtml state(String slogan, String name);
     
      }

  3. #3
    Sencha User
    Join Date
    Jul 2011
    Posts
    3
    Vote Rating
    0
    Schoumy is on a distinguished road

      0  

    Default


    Thx for answer me

    I try it and I receive a new error :

    SafeUri can only be used as the entire value of a URL attribute. Did you mean to use java.lang.String or SafeHtml instead?

  4. #4
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Answers
    109
    Vote Rating
    89
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    Please show the actual code you are writing, wrapped in a simple, standalone entrypoint so others can try it - it is difficult to debug a project just from an error message.

  5. #5
    Sencha User
    Join Date
    Jul 2011
    Posts
    3
    Vote Rating
    0
    Schoumy is on a distinguished road

      0  

    Default


    I have fixed my problem

    You had right, i replace the String argument by a SafeUri argument.

    view.setCell(new SimpleSafeHtmlCell<Image>(new AbstractSafeHtmlRenderer<Image>() {

    @Override
    public SafeHtml render(Image object) {
    return r.renderItem(UriUtils.fromTrustedString(object.getBase64()),object.getName(), style);
    }
    }));

    And

    @FormatterFactories(@FormatterFactory(factory = ShortenFactory.class, name = "shorten"))
    interface Renderer extends XTemplates {
    @XTemplate("<img width=\"100\" height=\"100\" src=\"{base64}\"> {name}")
    public SafeHtml renderItem(SafeUri base64, String name, Style style);
    }


    It works, thanks a lot !

Thread Participants: 1