Include static HTML (invalid XHTML) file to JSF Facelets - jsf-2

I have the following problem, We have web content manager (WCM) running at remote host,
which is responsible for generating header and footer HTML files.
i.e. header.html, footer.html.
The HTML files are not properly formatted syntax wise,
WCM generated files have
Space character ( ) 🡢 it is not allowed in XHTML.
Non Closing break line (<br>) tags 🡢 it is invalid in XHTML.
So the WCM generated HTML pages might not be valid XHTML pages.
We are implementing some of our applications in JSF,
where we need to include the WCM generated header and footer files.
Can we include the non-formatted HTML files into our XHTML files?
commonTemplate.xhtml
<html>
<head>
..........;
</head>
<body>
<ui:include src="remote_host/header.html" />
<ui:insert name="commonBodyContent" />
<ui:include src="remote_host/footer.html" />
</body>
</html>

I guess it is related to this question: Include non-Facelet content in a Facelet template
I do not recommend to mix XHTML with HTML, but most probably the browsers will not have any issues with the mentioned characters, hence you might try to directly render the file contenty, e.g. by
<h:outputText value="#{yourBean.headerCode}" escape="false" />
Whereas YourBean.getHeaderCode() would readout the header file's content and return it as String. YourBean should be ApplicationScoped.
Faster and better would be to get the WCM generating valid XHTML.

Related

LessJs file not being processed in ASP.NET

I'm experiencing a peculiar issue and I'm having trouble diagnosing it.
I am using LessJs in an ASP.NET MVC web application and the less file is not being processed and I am seeing my variables in the "F12" debug tools -- and the style is not applied as expected as a bi-product.
The markup looks like this.
#Scripts.Render("~/bundles/modernizr")
<link href="~/Content/bootstrap.css" rel="stylesheet" />
<link href="~/Content/site.less" rel="stylesheet" />
<script src="~/Scripts/less-1.5.1.min.js" type="text/javascript"></script>
I am seeing the files correctly delivered to the browser (from Network tab)
There are NO errors in the console.
but when I inspect my element, I see this:
The styles from bootstrap.css are applied as expected.
Am I missing a step? I've used less with ASP.NET before, this one's got me stumped.
Thanks!
Solved. This issue was that the link tag that references the less files had an incorrect rel attribute. For less it should be stylesheet/less as opposed to just stylesheet, which is used for CSS.
<link href="~/Content/site.less" rel="stylesheet/less" type="text/css" />

what is the difference between grails link ,createlink and resource tags

Is there any difference between grails link ,create link and resource tags and I want to know when to use each tag as per my knowledge the createlink tag has depricated
it's simple:
g.createLink generates only the url, like /aaa/bbb/222, based on controller/action/params for example
g.link generated the <a>-HTML-tag, using the g.createLink to generate the url to be put into the #href attribute
g.resource outputs a path to a resource file, available under web-app folder
<link rel="stylesheet" href="${resource(dir:'css',file:'style.css')}" />
produces
<link rel="stylesheet" href="/css/style.css" />
CREATE LINK is soemthing power full when u come to knowing the absolute or relative path in using likes inside a gsp page.
Let assume i have the following path /yourapp/controller1/view1
Instead of using
<a href="{grailscontext.thensomebaseurlstuff}/"+controller/view /> ,
which fails according to some context using the below will make it easy.
my link
<g:createLink url="[action:'list',controller:'book']" />
And ,glink is the above implementation using taglib form.. does the same effect as above but being in taglib makes reduce some computation or create some am not sure.
g.link("text of the link here", action:"foo", controller:"bar")
ResourceTags is no wonder its something help full and important in attaching either an image,css and js folder/file resource into a grails application.
// generates "/shop/css/main.css"
<g:resource dir="css" file="main.css" />
// generates "http://portal.mygreatsite.com/css/main.css"
<g:resource dir="css" file="main.css" absolute="true" />
// generates "http://admin.mygreatsite.com/css/main.css"
<g:resource dir="css" file="main.css" base="http://admin.mygreatsite.com"/>
Alloha!

Difference between <body> and <g:layoutBody>

may I know what's the difference between <body> and <g:layoutBody>, and how do I use these tags?
body tag is a HTML tag. (nothing to do with grails)
g:layoutBody should be used in templates to allow the concrete views to inject their data into the template.
Official documentation on g:layoutBody is quite helpful.
In particular, this is their example of a decorator layout a.k.a. main.gsp. In this example <g:layoutBody /> will be replaced with the body of the document to be decorated (e.g. index.gsp) and, of course, <g:layoutHead /> will be replaced with the head of the document to be decorated.
<html>
<head>
<script src="global.js" />
<g:layoutHead />
</head>
<body><g:layoutBody /></body>
</html>

JSF2 Reading Special Characters in GET Parameters

Here is my problem, can someone please help me....!
Present, i am migrating an application from struts to JSF2.
We have a user validation link, which sent to their email for verification,
after their successful registration.
For example:
http://testserv:5050/bjb/page/validateAccount.faces?Email=qwerty#testsession#1.com&Code=1272
The email address contains special characters, in old links which were sent to users.
In new application we are encoding them using URLEncoder.encode.
i think, this is nothing to do with UTF-8, But however
i set request, response, and JSF ExternalContext#setResponseCharacterEncoding to UTF-8.
tomcat is also configured for UTF-8.
validateAccount.xhtml
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
</h:head>
<h:body>
<h:form acceptcharset="UTF-8" name="verifyUserAccountForm" id="verifyUserAccountForm" prependId="false">
<f:metadata>
<f:event type="preRenderView" listener="#{verifyUserBean.execute}"></f:event>
</f:metadata>
</h:form>
</h:body>
</html>
In java code,
FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(paramName);
Could not read the URL GET Request Parameters properly.
How should i solve this for existing links.
I have something in my mind like, i can write a javascript function in my xhtml page,
Which could be excuted on load, so using javascript function i can encode parameters.
But how to execute that javascript function before <f:event type="preRenderView"> call.
is there any better solution ?.
The query string parameter in the outgoing URL should be encoded as follows wherein the desired charset is explicitly mentioned:
String emailParam = URLEncoder.encode(email, "UTF-8");
String url = "http://testserv:5050/bjb/page/validateAccount.faces?Email=" + emailParam + "&Code=1272";
The Tomcat server should be confidured to decode the incoming URL using the very same charset:
<Context ... URIEncoding="UTF-8">
That's all you need to do with regard to encoding/decoding GET URLs. The HTML meta tag is irrelevant to this. The HTTP response encoding is irrelevant to this. The HTML form accept charset does more worse than good.
Please note that you edit the <Context> element in the right Tomcat configuration file. If you're for example managing Tomcat in Eclipse, you'd by default need to edit the one in Eclipse's Servers project, not in Tomcat's installation folder.
See also
Unicode - How to get the characters right?

ui:composition template="<template from jar>"

I would like to place the Facelets template file for JSF in a JAR file.
I tried to reference it by EL as
<ui:composition template="#{resource['templates:template_pe_layout.xhtml']}">
which works perfect for CSS or images, but not for the composition template.
How could I achieve the goal?
The #{resource} expression is initially designed for use inside CSS files only like so
.someclass {
background-image: url(#{resource['somelibrary:img/some.png']});
}
It's not intented for usage in <h:outputStylesheet>, <h:outputScript> or <h:graphicImage> which should rather be used as follows:
<h:outputStylesheet library="somelibrary" name="css/some.css" />
<h:outputScript library="somelibrary" name="js/some.js" />
<h:graphicImage library="somelibrary" name="img/some.png" />
As to the templates, just specify the full /META-INF/resources relative path in there.
<ui:composition template="/templates/template_pe_layout.xhtml">
See also:
Packaging Facelets files (templates, includes, composites) in a JAR
Changing JSF prefix to suffix mapping forces me to reapply the mapping on CSS background images

Resources