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.
Related
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}
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>
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
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¶m2=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"/>
I have the following code in a JSP page:
<c:forEach var="widget" items="${widgets}">
<p><h2>Widget</h2></p>
<p>IDType: ${widget.id}</p>
<p>Name: ${widget.name}</p>
</c:forEach>
At the moment it is only text that will be displayed, but in the future there will be charts and images as well.
I would like to use asynchronous loading, so the page doesn't have to wait on the largest images/charts.
On the internet I found tutorials for Java code, but not for JSP pages. What is the best way to implement asynchronous loading in JSP pages?
Thanks!
Simply generate these images and charts separately using different servlet:
<c:forEach var="widget" items="${widgets}">
<p><h2>Widget</h2></p>
<p>IDType: ${widget.id}</p>
<p>Name: ${widget.name}</p>
<img src="chart-servlet.png?id=${widget.id}"/>
<img src="image-servlet.png?id=${widget.id}"/>
</c:forEach>
On the server side map some servlets to chart-servlet.png and image-servlet.png. You can then use id parameter to generate appropriate chart or image. From the browser perspective it first renders DOM without images to then ask server for external resources (images).