Escape character in erb file - puppet

I am trying to include an erb file in puppet. But the file consists of lines like these:
<%# taglib prefix="ww" uri="webwork" %>
<%# taglib prefix="ui" uri="webwork" %>
<%# taglib prefix="aui" uri="webwork" %>
<%# taglib prefix="page" uri="sitemesh-page" %>
When I run puppet, this is showing a syntax error that says
'# ' is not allowed as an instance variable name.
How can I escape this character #?

Your question is basically answered here already: How do I escape the ERB tag in ERB.
You can't escape the # character per se; you need to "escape" the ERB tags, by using the sequence <%% to indicate that you want the literal string <%.
So, change your ERB code to:
<%%# taglib prefix="ww" uri="webwork" %>
<%%# taglib prefix="ui" uri="webwork" %>
<%%# taglib prefix="aui" uri="webwork" %>
<%%# taglib prefix="page" uri="sitemesh-page" %>

Related

Facelets equivalent of <jsp-file> servlet mapping

Note - This question might have been answered earlier but I am not able to find any note on this. hence asking!
Background - I am working on a legacy JSF application which uses JSP as view technology. Now since we have decided to move to JSF 2.2/2.3, we are also changing the JSP pages to facelets.
Issue - In the web.xml, we have following mapping -
<servlet>
<servlet-name>dummyframe</servlet-name>
<jsp-file>/WEB-INF/dummyframe.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>dummyframe</servlet-name>
<url-pattern>dummyframe</url-pattern>
<servlet-mapping>
We have converted jsp file to facelet file but not sure how to handle this jsp-file mapping.
We are planning to write java classes which will redirect to facelet page. In this case, the mapping will be -
<servlet>
<servlet-name>dummyframe</servlet-name>
<servlet-class>xxx.xxxx.dummyframe</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dummyframe</servlet-name>
<url-pattern>dummyframe</url-pattern>
<servlet-mapping>
The questions I have -
1) Is this a good alternative?
2) Is there any other alternative available without writing java classes?
1) Is this a good alternative?
Yes, but I think it would be better to implement redirection in a filter instead of a servlet class.
2) Is there any other alternative available without writing java
classes?
Leave dummy servlet mapping in web,xml as is and put into /WEB-INF/dummyframe.jsp this:
<html>
<head>
<meta http-equiv="Refresh" content="0; URL=mynewdummyfile.jsf">
</head>
</html>
or this:
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<body>
<c:redirect url="mynewdummyfile.jsf"/>
</body>
</html>
or this:
<%# page import = "java.io.*,java.util.*,javax.servlet.http.HttpServletResponse" %>
<html>
<body>
<%
response.sendRedirect("mynewdummyfile.jsf");
%>
</body>
</html>
or this:
<%# page import = "java.io.*,java.util.*,javax.servlet.http.HttpServletResponse" %>
<html>
<body>
<%
response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
response.setHeader("Location", "mynewdummyfile.jsf");
%>
</body>
</html>
or this:
<%# page import = "javax.servlet.ServletContext" %>
<html>
<body>
<%
ServletContext sc = getServletContext();
sc.getRequestDispatcher("/WEB-INF/mynewdummyfile.jsf").forward(request, response);
%>
</body>
</html>

how to single h:panelgrid into apply colspan?

USe lib <%# taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
how to apply single panel grid in colspan?

Is there a way to ignore tags in a dustJS template

We have a lot of spring, jsp and jstl tags in our templates that we wish to include. Can we make dust ignore these tags?
<sec:authorize access="!hasRole('ROLE_USER')">
<a>Blah</a>
</sec:authorize>
<sec:authorize access="hasRole('ROLE_USER')">
<a>Foo</a>
</sec:authorize>
or
<%# taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
Use the parser expression grammar to ignore special delimiters, which would look something like this:
= ld [^%] ws* [#?^><+%:#/~%] ws* (!rd !eol .)+ ws* rd
References
dustjs / src / dust.pegjs
dust.pegjs is a bunch of regexes that output an array
peg.js Online Tester

JSF page splitting

During working with JSF 1.2 one page code is too large and JDeveloper gave too large code in service method exception. Now I want to split my JSF file in smaller files. During splitting I need some help and suggestion.
Beacuse the whole page binds with a single bean, is it also necessary to split the bean? If not, then how to overcome this? What is the best way to split JSF file and include in main page?
You don't need to split the bean. You could just split the page fragments over multiple files which you include by <jsp:include> (and not by #include as that happens during compiletime and you would end up with still the same exception!). Note that you should store those include files in /WEB-INF folder to prevent direct access by enduser.
So given this example of an "extremely large" page,
<%#taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%#taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
large chunk 1
</div>
<div>
large chunk 2
</div>
<div>
large chunk 3
</div>
</body>
</html>
You could split it as follows while keeping the beans:
<%#taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%#taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<jsp:include page="/WEB-INF/includes/include1.jsp" />
<jsp:include page="/WEB-INF/includes/include2.jsp" />
<jsp:include page="/WEB-INF/includes/include3.jsp" />
</body>
</html>
and /WEB-INF/includes/include1.jsp:
<%#taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%#taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<div>
large chunk 1
</div>
and /WEB-INF/includes/include2.jsp:
<%#taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%#taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<div>
large chunk 2
</div>
and /WEB-INF/includes/include3.jsp:
<%#taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%#taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<div>
large chunk 3
</div>

Embedding Tag Files in a JAR

Is it possible to do this? What I'm trying to accomplish here is the creation of an extensible Struts 2 plugin with customizable screens to avoid code duplication in similar projects.
Yes, it is possible, but it has nothing to do with Struts 2:
http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPTags6.html#wp90207 (under "Packaged Tag Files").
Here is an example: http://www.examulator.com/moodle/mod/resource/view.php?id=473
Quoting steps from this source(taken from prev. answer) in case URL changes. (Simplest solution I found on the internet)
When wrapped in a jar (Java archive) tag files require a tld.
menu.tld placed in the META-INF directory.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>menutagfile</shortname>
<uri>www.examulator.com/menutagfile</uri>
<tag-file>
<name>menu</name>
<path>/META-INF/tags/menu.tag</path>
</tag-file>
</taglib>
menu.tag placed in the META-INF\tags directory.
<%# tag body-content="tagdependent" %>
<%# attribute name="menutext" rtexprvalue="true"%>
<h1>This is my tag file</h1>
<jsp:doBody/>
The command to package these into JAR(Auto package in case of maven)
Jar cvf menutagfile.jar .\META-INF\*.*
Usage in the parent project
<%# taglib prefix="mytagfile" uri="www.examulator.com/menutagfile" %>
<html>
<head>
<title>Demonstration of Tag Files</title>
</head>
<body>
<h1> What is going down? </h1>
<mytagfile:menu/>
</body>
</html>
Note: In case you do not have a META-INF folder in your project, create one inside src/main/resources.

Resources