1

I need to reference a Java varaible within an HTML tag in order to display the string variable contents as the HTML "title" tag value for a tool tip. I have been trying for a day and a half now and my google searches have not yielded any help yet either.

I am storing the Java variables in a table per the requirements of this app, and the below code is the closest I can get to correct but it shows the exact text 'block_type_desc' for the tool tip/on mouse over result that I need to show the value within the table column 'block_type_desc' when you move your mouse over the "block_code" value. I have tried : sb.append(""+block_type_desc'); sb.append(""); sb.append(""); sb.append(""); //this one no matter how I differentiate the syntax round t.getValue etc. it won't compile

Can someone please advise how to correct my syntax to call the variable string data corectly to display it? thank you so much in advance for your time and help!! I am copying the whole display function as I think that will help paint a complete picture of my needs and situation.

private StringBuffer displayUserMenuItems(Table t) {
        StringBuffer sb = new StringBuffer(20000);
        sb.append("<table>");
        sb.append("<tr>");
    sb.append("<td><strong>Code</strong></td>");
    sb.append("<td><strong>Menu Item Description</strong></td>");
    sb.append("<td><strong>Block Type</strong></td>");
    sb.append("</tr>");
    t.reset();
    String css;
    int i = 0;
    while (t.next()) {
        if (i % 2 == 0) {
            css = "even";
        } else {
            css = "odd";
        }
        sb.append("<tr class=\"" + css + "\">");
        sb.append("<td>");
        sb.append(t.getValue("menu_code"));
        sb.append("</td>");
        sb.append("<td>");
        sb.append(t.getValue("menu_desc"));
        sb.append("</td>");
        // this next line below displays "block_type_desc" for title
        **sb.append("<td title='block_type_desc'>");**
        sb.append(t.getValue("block_type"));
        sb.append("</td>");
        sb.append("</tr>");
        i ++;
    }
    sb.append("</table>");
    return sb;      
}
Jason
  • 51,583
  • 38
  • 133
  • 185
  • Put at least 4 spaces before any code that you post, or use backquotes. Your examples of what you have already tried are not showing up correctly because you didn't do this. – We Are All Monica Aug 27 '12 at 21:27
  • @Katya - unless you need the Thread safety of synchronization, you're better off using a `StringBuilder` instead of a `StringBuffer` ... See [this question](http://stackoverflow.com/q/355089/17300) here on SO – Stephen P Aug 28 '12 at 00:40

1 Answers1

2
sb.append("<td title=\"" + t.getValue("block_type_desc") + "\">");
We Are All Monica
  • 13,000
  • 8
  • 46
  • 72
  • 2
    Since the OP is already using an StringBuffer, I would put it like this instead: `sb.append("");` –  Aug 27 '12 at 21:29