renderFormatted() doesnt seem to work with elemenst within each statement
ijabz opened this issue · comments
ijabz commented
I created a full page with j2html, and used renderFormatted on the html() element. It renders nicely aprt from where I used a each statement (see the output within table part)
This is (bulk of code)
package com.jthink.songkong.server.page;
import com.jthink.songkong.cmdline.SongKong;
import com.jthink.songkong.reports.utils.HtmlSnippets;
import com.jthink.songkong.server.RoutePath;
import com.jthink.songkong.text.TextLabel;
import com.jthink.songkong.ui.progressdialog.FixSongsCounters;
import com.jthink.songkong.util.Html;
import static com.jthink.songkong.reports.utils.HtmlSnippets.*;
import static j2html.TagCreator.*;
import static j2html.attributes.Attr.FOR;
import static j2html.attributes.Attr.MAX;
import static j2html.attributes.Attr.VALUE;
/**
* Monitor Progress of Fix Songs
*/
public class FixSongsProgressPage extends AbstractPage
{
private static final String PB_PREFIX = "pb";
private static final String CHECK_PROGRESS_ID = "check_progress";
public String getHeaderText()
{
return "";
}
public String createPage(String errorPage)
{
FixSongsCounters fsc = new FixSongsCounters();
return HtmlSnippets.createPage(
body(
getBodyHeading(),
iff(SongKong.isStopTask(),h1("Fix Songs has been cancelled, report will be displayed when cancellation has completed ").withStyle("color:#FF0000;")),
table(each(fsc.getCounters().entrySet(), next ->
tr(
td(
label(next.getValue().getText())
.attr(FOR,PB_PREFIX+next.getKey().intValue())),
td(
iffElse(next.getValue().getBar().isIndeterminate(),
progress()
.withId(PB_PREFIX+next.getKey().intValue()),
progress()
.withId(PB_PREFIX+next.getKey().intValue())
.attr(VALUE, next.getValue().getCounter().intValue())
.attr(MAX, next.getValue().getBar().getMaximum())
)
)
)
)
),
form().withAction(RoutePath.STARTFIXSONGS + RoutePath.CHECK_PROGRESS).withId(CHECK_PROGRESS_ID),
iffElse(!SongKong.taskMonitor.getPause().isPaused(),
form(input().withType(Html.SUBMIT).withValue(TextLabel.PAUSEBUTTON.getMsg()).withAction(RoutePath.STARTFIXSONGS + RoutePath.PAUSE)),
form(input().withType(Html.SUBMIT).withValue(TextLabel.CONTINUEBUTTON.getMsg()).withAction(RoutePath.STARTFIXSONGS + RoutePath.CONTINUE))
),
form(input().withType(Html.SUBMIT).withValue(TextLabel.CANCELBUTTON.getMsg()))
.withAction(RoutePath.STARTFIXSONGS + RoutePath.CANCEL
),
script(rawHtml("function checkprogress() { document.getElementById('check_progress').submit(); }; setTimeout(checkprogress, 5000)")
)
));
}
}
This is html output
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/html" xml:lang="en" lang="en">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<link href="https://github.com/tipsy/j2html/style/googlefonts.css" target="_blank" rel="nofollow" rel="stylesheet" type="text/css">
<link href="../style/songkong.css" rel="stylesheet" type="text/css">
<link href="../style/jquery/ui/css/smoothness/jquery-ui-1.9.2.custom.css" rel="stylesheet" type="text/css">
<link href="../style/jstree/themes/style.css" rel="stylesheet" type="text/css">
<script src="../style/songkong.js" type="text/javascript">
</script>
<script src="../style/jquery/jquery-1.9.1.js" type="text/javascript">
</script>
<script src="../style/jquery/ui/js/jquery-ui-1.9.2.custom.js" type="text/javascript">
</script>
<script src="../style/jstree/jstree.js" type="text/javascript">
</script>
<link rel="shortcut icon" href="../style/songkong32.png" type="text/png">
<link rel="icon" href="../style/songkong32.png" type="text/png">
</head>
<body>
<div>
<noscript>
<h1 style="color:#FF0000;">
This reportFile will not be navigable without Javascript, please enabled Javascript
</h1>
</noscript>
<img src="style/songkongheader.png">
<h2 class="subheading ui-corner-all" title="Start Fixing Songs">
<a style="text-decoration: none">
Fix Songs
</a>
</h2>
</div>
<h1 style="color:#FF0000;">
Fix Songs has been cancelled, report will be displayed when cancellation has completed
</h1>
<table>
<tr><td><label for="pb0">Processing</label></td><td><progress id="pb0"></progress></td></tr><tr><td><label for="pb1">Songs loaded</label></td><td><progress id="pb1" value="3465" max="17080"></progress></td></tr><tr><td><label for="pb3">Songs ignored because already matched</label></td><td><progress id="pb3" value="0" max="17080"></progress></td></tr><tr><td><label for="pb8">Songs saved (if not preview)</label></td><td><progress id="pb8" value="0" max="17080"></progress></td></tr><tr><td><label for="pb11">Completed</label></td><td><progress id="pb11" value="196" max="17080"></progress></td></tr><tr><td><label for="pb12">Errors</label></td><td><progress id="pb12" value="0" max="17080"></progress></td></tr>
</table>
<form action="/fixsongs.check_progress" id="check_progress">
</form>
<form>
<input type="submit" value="Pause" action="/fixsongs.pause">
</form>
<form action="/fixsongs.cancel">
<input type="submit" value="Cancel">
</form>
<script>
function checkprogress() { document.getElementById('check_progress').submit(); }; setTimeout(checkprogress, 5000)
</script>
</body>
</html>
ijabz commented
Just to be clear this is a bug not user error.
ijabz commented
FYI also reported by another user - https://stackoverflow.com/questions/48358347/how-to-make-j2html-format-each-tags-correctly
I-Dont-Want-To-Create-An-Account commented
The problem appears to be in j2html.tags.ContainerTag.renderFormatted(). Objects created by each()
are of type 'UnescapedText', but only objects of type 'ContainerTag' are formatted