load css and js file in JSF - jsf-2.2

I am trying to load the css and js files as well as the image in the img directory from mainStyle.css but without secuss. I can not load the js file and the obama.jpg from the css stylesheet.
I am facing a problem to explain why am I getting Hell World! Say apple! green? I have set them before green but now they have the red value, despite that I am getting them rendered in green!!.
index.xhtml
<!DOCTYPE html>
<html xmlns="htpp://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>External resources</title>
<h:outputStylesheet library="css" name="mainStlye.css" />
<h:outputScript library="js" name="mainJS.js" />
</h:head>
<h:body>
<h1>Using external resources</h1>
<div class="message">Hello World!</div>
<div class="message">Say apple!</div>
</h:body>
</html>
mainStyle.css
body{
background: url("#{resource['img/obama.jpg']}");
}
.message{
color:red;
}
mainJS.js
alert('Javascript works fine');

Just use the relative path of the image in the css.
Furthermore, you wrote background instead of background-image.
Have a look here:
Can I use EL for external CSS files with JSF?
In your case, would be:
body{
background-image: url(../img/obama.jpg);
}

Related

Why everything goes above my navbar when I use #extend to display the navbar from another page

So I want to include my navbar to every page. I use #extends in laravel and When I define any html elements, It just goes above the navbar. It does not make sense at all. I write the html elements under the navbar but why does it go on top?????
here is my code:
<!DOCTYPE html>
<html lang="en">
#extends('layout.header')
<style>
</style>
</head>
<body>
#extends('layout.navbar')
asdasdsa
</body>
</html>

SonarQube quality gate status fetching issue

I am trying to get the status of SonarQube quality gate status using below query
curl.exe -u "78c2b8628934a6cdc8ae80f5acadaaaafdfsa96" : "https://sonarurl/api/qualitygates/project_status?projectKey=MarUiSonarQube3"
then system prompted for password, after that I got below error:
Did I miss something?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>IIS Windows</title>
<style type="text/css">
<!--
body {
color:#000000;
background-color:#0072C6;
margin:0;
}
#container {
margin-left:auto;
margin-right:auto;
text-align:center;
}
a img {
border:none;
}
-->
</style>
</head>
<body>
<div id="container">
<img src="iisstart.png" alt="IIS" width="960" height="600" />
</div>
</body>
</html>
The url you specified is the following:
curl.exe -u "78c2b8628934a6cdc8ae80f5acadaaaafdfsa96" : "https://sonarurl/api/qualitygates/project_status?projectKey=MarUiSonarQube3"
The way you've specified the token value looks slightly off. Try changing it to the following (moving the colon to right after the token):
curl.exe -u "78c2b8628934a6cdc8ae80f5acadaaaafdfsa96:" "https://sonarurl/api/qualitygates/project_status?projectKey=MarUiSonarQube3"

<img> after <h1> does not validate as HTML 4.01 Strict

My markup is
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>klaymen - About</title>
</head>
<body>
<h1>Klaymen</h1>
<img src="resources/klaymen-about.jpg" width="200" alt="Klaymen's about picture">
</body>
When I test the document with this validator https://validator.w3.org/#validate_by_input I get the following error:
document type does not allow element "IMG" here; missing one of "P", "H1", "H2", "H3", "H4", "H5", "H6", "DIV", "ADDRESS" start-tag
Clearly I have an H1, and img is a flow content element which supposed to be allowed in this location, so what is the problem?
You can use a div container.
<div>
<img src=""/>
<span display: block>Text below the image</span>
</div>
This happens because the body of a document in this spec cannot contain an inline element like <img>, thus, by putting it inside a block element like <div>, all's fixed.

Extend A View With Thymeleaf

is it possible extend a shared view with thymeleaf?
I saw that is possible use framents but is not what I want.
Instead I want something similar to .NET MVC, with something like #RenderBody() and another view that extend the shared view by including the shared view.
You can use the Thymeleaf Layout Dialect to extend a view.
Layout page
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
...
<body layout:fragment="body">
...
</body>
</html>
Content page
In your content page, you refer to the layout (decorator) page using the layout:decorator attribute.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="layout.html">
...
<body layout:fragment="body">
<p>Actual page content</p>
</body>
</html>
It is possible to have multiple fragments in one page.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
...
<body>
<div layout:fragment="content"></div>
<footer layout:fragment="footer"></footer>
</body>
</html>

Adding data on Print functionality in MVC3

I have a web page designed in MVC3. I want to add some data (a disclaimer text) at the bottom of the page on the print button click and then print the page. How to do this?
Thanks!
Description
You can do this using css.
Create a div at the end of your page and give them a className disclaimer
Create a stylesheet file for the normal view of your page and set the display attribute to none
Create another css file called print.css and set the display attribute to visible
Sample
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<link href="myCSSfile.css" rel="stylesheet" type="text/css" media="screen">
<link href="print.css" rel="stylesheet" type="text/css" media="print">
<head>
<body>
<!--- your content --->
<div class="disclaimer">Your disclaimer text</div>
</body>
</html>
Your myCSSfile.css
.disclaimer { display: none; }
Your print.css
.disclaimer { display: block; }
More Information
CSS Design: Going to Print
You want to use CSS and print media style sheets to make the element visible for printing.
A basic tutorial about this can be seen here: CSS Media Types Create Print-Friendly Pages

Resources