简体   繁体   中英

How to create html tag in jsp page from java bean object

I'm trying to create jsp page that contains chart and tool tip on the chart. I got to this point: I have a chart as image in my jsp page. I have String that contians the html tag map with all the data about the tool tip.

I am looking for a way to take the String with all the data and put it in my jsp page as regular html tag.

I tried to use :

<h:graphicImage id="linkGraph"
                value="#{myBean.fileName}"
        usemap="#{myBean.mapPath}"
        width="#{myBean.width}"
        height="#{myBean.height}"
        rendered="true"
        style="border-color: #ffffff;/>
        #{myBean.mapHtml}

I'm getting it as text in my jsp page

Thanks in advanced.

Have you included the correct headers in your JSP, i,e:

<%@page language="java" %>
<%@taglib prefix="h" uri="[taglib url]" %>

EDIT:

To enable Expression Language:

<%@ page isELIgnored="false" %>

Then get your bean:

<jsp:useBean id="myBean" class="fully.qualified.bean.class.MyBean"/>

And then use it in your tag:

<h:graphicImage id="linkGraph"
            value="${myBean.fileName}"
    usemap="${myBean.mapPath}"
    width="${myBean.width}"
    height="${myBean.height}"
    rendered="true"
    style="border-color: #ffffff;/>
    ${myBean.mapHtml}

Note the ${byBean.property} expressions, with a $ not a #: your bean class needs matching getter methods, ie getFilename(), getMapPath() etc.

I found a way to do it. Create simple tag(div, span....) with id="tag" and with the help of java script function

        function replaceString(str) {
        document.getElementById("tag").innerHTML = str;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM