Thymeleaf spring MVC - java

Inside My appli.proprety i have some text for example
app.test=<p><span class="lettrine">Hello</span>World</p>
In my view i try to get it inside a div with thymeleaf like this :
<div th:text="#{app.test}"></div>
it doesn't working!!
but it work when i write it inside the div :
<div><p><span class="lettrine">A</span>Hello</p></div>
So what exactly the problem and how i can fixed it?!
Ps: I have many text inside my data base with html, not working too.

Use th:utextinstead of th:text.
Like this
<div th:utext="#{app.test}"></div>

Related

How to add static image in inline background-image css tag in Spring boot Thymleaf template?

I am developing a web application for learning purpose using java spring and Thyme leaf template engine.
In one of my Thymeleaf page, I want to add an image as a background-image using inline CSS. My image is in the static folder,
I have tried to use various method found on the internet but none of them worked.
I've searched and unfortunately failed to find out the solution to this problem.
I've tried to th:style tag and searched in google to find out how this tag works but unfortunately couldn't able to understand this tag properly.
I've added the code and the screenshot of the error.
blockquote class="imgur-embed-pub" lang="en" data-id="a/TOr6Nyn"><a >
href="//imgur.com/TOr6Nyn"></a></blockquote><script async
src="//s.imgur.com/min/embed.js" charset="utf-8"></script>
th:style="'background-image: url('+
#{~/frontend/images/blog/default/thum1.jpg}+')'"
You should add the style attribute to your div as:
style="background-image: url(<c:url value="/resources/images/bg_1.jpg"/>)"
I have also tried static image but it does not work.
But if u want to show image on page use base64 of that image.
Use this code on your thyme leaf page:
<img th:src="#{data:image/png;base64,YOUR BASE 64}

Call several method from jsp + Spring

i'm new to jsp + spring and i have this problem:
i have two #RequestMapping that respond to "onWork" and "onPending". Both return a list of activities and i would like to call them in the same page, for example:
<div id="onWork">
here i want to display onWork
</div>
<div id="onPending">
here i want to display onPending
</div>
I really like to modularize them and create two page: one that display onWork and another that display onPenging, so i could reuse that "fragment" every time i want, without duplicate the code.
How can i do that using jsp, jsp:invoke, jsp:fragment etc ?
Thanks
You should probably use <c:import> from the JSTL to import a common fragment, or <jsp:include>, which allows you to pass variables into the fragment, which you'll probably need to do from the fragment's parent, in each of the divs you're shown above (see <jsp:param>).

How to map server response retrieved in jsp to an iFrame

I'm using struts2 framework(java/js/html/css combo) for my webapp. I am reading a text file from server and I want to write the response to an iFrame present in the same jsp.
Flow:
(1) On click of a link, I pass the relative URL of the text file to jsp.
(2) When the jsp page loads, the java code in the jsp reads the file from server.
(3) Now this response has to be written to an iFrame present in the same jsp file
Can anyone plz help me in writing such response to an iFrame?
Thanks in advance :)
[code not tested, only a demostration of the concept]
here's some very rough idea as to how to fix your code, they definitly not the best but they should be enough to help you understand the concept.
However I'd still recommend going over the whole concept and maybe come up with a more efficent way to do what you need.
if you insist on using iframe, you need to make use of 2 seperate jsp as W3C says in "Implementing HTML Frames":
Any frame that attempts to assign as its SRC a URL used by any of its ancestors is treated as if it has no SRC URL at all (basically a blank frame).
so you'll need 2 jsp, the first one is basically what you have but the the src of the iframe changed to:
<iframe scrolling="yes" width="80%" height="200" src="second.jsp?content=<%=all%>" name="imgbox" id="imgbox">
and the second one will be something like :
<html><body><%= request.getAttribute("content") %></body></html>
From the code you've shown you forced a "content update" on the iframe by using javascript. The proper/usual way to update an iframe is to provide different input parameter to the second jsp and let it update it for you.
Finally, I'd recommend using JSTL as much as possible instead of scriptlets. It is much cleaner.
What you need to do is set the src attribute of the IFRAME to the jsp url when your link is clicked. Another way to do it is doing something like this:
<iframe src="" name="iframe_a"></iframe>
<p>W3Schools.com</p>
with the correct parameters of course

how to send parameters to jsp

So I'm using JFree chart and I'm trying to generate an image and display it in my jsp code. I would like to know how to accomplish this. I have tried multiple different ways but it doesn't work.
I saved the file and then when I try to access it. It is stored on the webserver and therefore I don't have the url to it?
Any help would be much appreciated.
I also tried to do something like this,
<IMG SRC="chart.jsp"
WIDTH="300" HEIGHT="300" BORDER="0" USEMAP="#chart">
which is basically jsp which generates an image. It works but how can pass parameters to it?
You shouldn't use a JSP, but a servlet to generate an image. JSPs are view components, whose role is to generate HTML markup from a model prepared by a controller.
But anyway, you pass parameters to a JSP the same way as you do for any other URL:
<img src="chart.jsp?param1=value1&param2=value2" .../>
Instead of thinking of the img source as static file think of the url being a stream that will be returned from a servlet using a prticular URL
eg
<img src="/jfreeServer?param1=123"/>

Loading page content via AJAX in JSF2

I've been looking into jsf technologies lately such as primefaces, primefaces-extensions, omnifaces .
what I am not able to find is way to fetch content via ajax for example load a form, table content and put them into div or something, I've looked at rendered attribute, but that won't work for high scale application.
Any help would be appreciated.
A handy trick for this is using a dynamic ui:include tag like:
<div id="dynamicContent">
<ui:include src="#{contentBean.content1}"/>
</div>
Where content1 is a string with path and .xhtml filename (usually something like /WEB-INF/content/page1.xhtml), and the parent div can be used to update.

Categories