Is It Possible: Pass JSP Fragment To Tag, Parsing EL
I just couldn't find if this was possible so can someone point me in the right direction.
I've got a tag that is going to output some HTML. What I would like to do is to have that tag fetch a local JSP and have the tag print the contents of this tag out, processing any EL in that page using variables in the PageContext. Is this possible?
E.g. Something along these lines?
public int doStartTag() throws JspException {
try {
pageContext.setAttribute("config", ConfigServlet.getXmlConfig());
InputStream inputStream = this.getClass()
.getResourceAsStream("menu.jsp"); // How do I get the JSP???
String jspBody = convertStreamToString(inputStream);
pageContext.getOut().print(jspBody);
} catch (IOException e) {
LOGGER.error(e, e);
return SKIP_BODY;
}
How we handle a similar requirement is with a bean or tag that gets the data as XML and then we use the x tags to apply an xslt to it.
<%@taglib uri="/WEB-INF/sw.tld" prefix="sw"%>
<%@taglib uri="http://java.sun.com/jstl/xml" prefix="x"%>
<c:import var="xslDoc" url="/xslt/some.xsl"/>
<sw:events sqlID="EventsByDate" var="ListOfEvents" />
<x:transform doc="${ListOfEvents}" xslt="${xslDoc}">
<x:param name="someParameterInTheXSLT" value="someValue"/>
</x:transform>
Similar Messages
-
How to skip validation for tag file, or jsp fragment?
hi
I have some jsp fragment and tag file in a workshop 10 project
workshop blame me about the jsp fragment (no start/end tag)
and unable to publish to server
is there a way to skip validation on some files?
I do found an check box call "validate JSP fragments" and I have un-ticked it. It does nothing.
please helpYes, you can turn off validation either on project/folder/individual file.
Project:
Project > Properties - Validation AppXRay - un-check "Validate Workshop managed documents" (this is not recommended, you may loose entire AppXRay validation).Folder:
Project > Properties - Validation AppXRay - Exclude Folders tab, if all the JSP fragments are present in a particular folder (under WebAppRoot), you can pick that folder to be excluded from AppXRay validationFile:
Help > Help Contents - BEA Workshop User's Guide > Common IDE Tasks > "Using AppXRay" - Live Synchronization of artifacts with AppXRay - On this page scroll to the bottom you will find a table with list of comments that can be included in a JSP file to exclude file level validation.Ex:
<%--<nitrox:set-property property="validation" value="true"/> --%>
Controls all validation in the IDE. The default value of true enables validation. -
JSP Tag -- Including a JSP fragment in a Java Tag file
Hi all,
I have a query regarding JSP Tag file authoring by extending the TagSupport class. I would like to know if it is possible to include a JSP file fragment inside a Java file somehow.
Specifically, I have created a simple template tag, which adds a header and footer template to the resulting HTML page.
<bc:template>
Hello World!
</bc:template>produces for example
<html><body>
Hello World!
</body></html>Now I have two JSP fragment files (head.jspf and foot.jspf), and I want to do do something like
public class HtmlTemplateTag extends TagSupport implements TryCatchFinally {
public int doStartTag() {
// somehow include head.jspf
return EVAL_BODY_INCLUDE;
public void doFinally() {
// somehow include foot.jspf
}Which means, I want to execute had.jspf and foot.jspf from the Java class file. I am not sure if it is even possible. If anyone can help me with this, it would be greatly appreciated.
thanks
nileshYour intention is to put a header/footer on pages in your web application?
There is another way to do it - specify prelude/coda jsp fragments in web.xml
Something like the following:
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<include-prelude>/WEB-INF/jspf/head.jspf</include-prelude>
<include-coda>/WEB-INF/jspf/foot.jspf</include-coda>
</jsp-property-group>
<jsp-config> -
Problem redering h:outputText tag on a jsp fragment
Hello to all... I'm trying to understand and use this new technology and I have encountered a problem that I cannot find any documentation as how to solve it. First I have my welcome.jsp page that I am using to call my fragment:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<f:view>
<h1><h:outputText value="Java Server Faces" /></h1>
<f:subview id="banner">
<c:import url="/banner.jsp"/>
</f:subview>
</f:view>
</body>
</html>then I have my jsp fragment, banner.jsp:
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<f:loadBundle basename="com.gm.gsip.messages" var="msgs"/>
<table border="1">
<tr>
<td> <h:outputText value="#{msgs.hour}"/> � </td>
<td> <h:outputText value="#{msgs.hour1}"/> �</td>
<td> <h:outputText value="#{msgs.hour2}"/>� </td>
<td> <h:outputText value="#{msgs.hour3}"/> �</td>
<td> <h:outputText value="#{msgs.hour4}"/>� </td>
<td> <h:outputText value="#{msgs.hour5}"/> �</td>
<td> <h:outputText value="#{msgs.hour6}" /> �</td>
<td> <h:outputText value="#{msgs.hour7}" /> �</td>
<td> <h:outputText value="#{msgs.total}" />� </td>
</tr>
</table>My problem is that the <h:outputText> tag is rendering the values outside the table. This is what gets displayed:
Java Server Faces
Hour1234567TOTAL
If I copy/paste the table tags (including the <h:outputText> tags) on the main jip, it renders without any problem:
Java Server Faces
Hour 1 2 3 4 5 6 7 TOTAL
I'm guessing that I might be missing some other jsf tag inside the jsp fragment. Any help will be greatly appreciated.
-thanks
RolandoI can suggest you with the following solutions
1. try having <%out.flush();%> before and after c:import
2. try with jsp:include with flush=true
Can you reply back with which one works? I didnt try out both of them
Thanks -
Hi there...
I put a right JSTL code in a JSP fragment and it didn't work? What am I supposed to do to run a JSTL code in a JSP fragment. Is there any configuration in special?
ThanksThere is a fundamental difference between the include directive [url http://java.sun.com/products/jsp/syntax/1.2/syntaxref129.html#997991]<%@ include %> and [url http://java.sun.com/products/jsp/syntax/1.2/syntaxref1214.html#8828] <jsp:include >
The <%@ include %> tag includes the file at translation/compile time. It is like copying and pasting the contents of the "fragment" into the main JSP. It is then translated, compiled and run.
The <jsp:include> tag includes the result of running that page at execution time. ie it is as if you made a web request to that URL, and pasted the response you got back into the response of the including page.
What does this mean in your case?
1 - a .jspf file will not be evaluated by <jsp:include>. If you make a request for the jspf file directly, it will send you the source, because it doesn't invoke the JSP servlet on jspf files.
Solution: change the file to meujstl.jsp, and it should include ok.
2 - The file needs to be standalone with regards to importing
- tag libraries
- packages (if any)
etc etc.
so you will need to import the core jstl taglib at the top of the page to use it with <jsp:include>
Cheers,
evnafets -
Enhancement request: stylesheets for JSP fragments
empty
Thank you for the feedback. Some other great enhancements are not too far
down the road, including visual layout for Tiles applications and management
of your Tiles definitions. Definitely stay tuned and continue to let us
know what you would like to see in the product.
M7 Support
"Clark Archer" <[email protected]> wrote in message
news:41127e8f$[email protected]..
Would it be possible to have a method of specifying a default stylesheetfor JSP fragments in NitroX's JSP design view? I'm using Tiles for most
of my new presentation layer development and one problem is that, since
the stylesheet is typically specified in the layout rather than the
final JSP, NitroX does not display styled JSP in the design view. -
Including JSP fragment file in a JSP
Hi, there,
I'm trying to include a fragment JSP file (with an extension .jspf as suggested by JSP1.2 spec) in a JSP file as follows:
<jsp:include page="/header.jspf"/>
But it looks like OC4J thinks it is a static file and thus all JSP tags are ignored. I have to change the file extension from "jspf" to "jsp" to make it work.
Same thing happens with the RequestDispatcher.include method.
Is there a way to handle this in OC4J such as adding a servlet mapping?
Thanks.
LiYou might consider using an include directive instead of an include action. The "jsp:include" element is the include action. This executes at "run time" as an internal forward from the servlet container. However, an include directive executes at servlet generation time (compile time).
So, instead of doing "jsp:include", you would do the following:
<%@ include file="/stuff.jspf" %>
This should allow your JSP fragment to be compiled into the servlet it is being included from. -
Jsf 1s phase of life cycle how knows ths components of the jsp with jsf tag
i wish to know how faces servlet knows the jsp s view components while creaTI NG component tree at first request to input jsp which may have jsf tags.in the first phase faces servlet doesnot know input jsp with jsf tags what componnets it has. it is actually atthe response send or forward time which is the final phase when the tag ge executed and output is sent to client.i did understandin jsf life cycle in 1 st phase component tree is created at first request in 1 st phase .
Hi,
though a FacesContext holds the values used by a request, it doesn't mean it lives for as long as the request. The best explanation I found is from the JavaDocs
release
public abstract void release()
+Release any resources associated with this FacesContext instance. Faces implementations may choose to pool instances in the associated FacesContextFactory to avoid repeated object creation and garbage collection. After release() is called on a FacesContext instance (until the FacesContext instance has been recycled by the implementation for re-use), calling any other methods will cause an IllegalStateException to be thrown.+
The implementation must call setCurrentInstance(javax.faces.context.FacesContext) passing null to remove the association between this thread and this dead FacesContext instance.
Throws:
java.lang.IllegalStateException - if this method is called after this instance has been released
Frank -
JSP in custom tag attributes...
Sirs,
A very nice feature from a development perspective, would be the ability
to use JSP code within custom tags. Say I have a page on which I wish
to give all the information on a widget. Say further that I have
implemented a tag that writes out all the info of a widget as HTML
table. I would like to write something like this:
<mytaglib:widgetTag widgetID="<%=request.getParameter("widget_id")%>"
/>
As far as I know, in the current implementation of custom taglibs this
does not seem to be possible. Instead you end up writing something like
this:
<mytaglib:widgetTag>
<mytaglib:getWidget><%=request.getParameter("widget_id")%>"</mytaglib:getWidget>
<mytaglib:displayWidget />
</mytaglib:widgetTag>
Which is much more like a scripting language than a heirarchical XML .
Now, I could always just use the request object within the tag helper
classes, but this gives up flexibility and can introduce security
issues, and it also makes the tags much more difficult to work with...
In short, we should push for JSP evaluation of tag attributes. Weblogic
could leap ahead of other app servers in this area (making up for the
custom tag performance issues, to be solve in sp6) and Sun would, once
again, follow Weblogic's lead and rewrite the standard to include this
functionality.
Regards,
Carson Gross
Carson,
Perhaps the problem is that you are treating custom tags like one would
construct an imperative language. I have never had to put Java or use beans
or %= or even parameters to tags into a JSP because of custom tags.
The real problem is writing/packaging/maintaining all those tags; sure could
use a tool that did just that ;-)
Peace,
Cameron Purdy
[email protected]
http://www.tangosol.com
WebLogic Consulting Available
"Carson Gross" <[email protected]> wrote in message
news:[email protected]...
> Sirs,
>
> A very nice feature from a development perspective, would be the ability
> to use JSP code within custom tags. Say I have a page on which I wish
> to give all the information on a widget. Say further that I have
> implemented a tag that writes out all the info of a widget as HTML
> table. I would like to write something like this:
>
> <mytaglib:widgetTag widgetID="<%=request.getParameter("widget_id")%>"
> />
>
> As far as I know, in the current implementation of custom taglibs this
> does not seem to be possible. Instead you end up writing something like
> this:
>
> <mytaglib:widgetTag>
>
>
<mytaglib:getWidget><%=request.getParameter("widget_id")%>"</mytaglib:getWid
get>
>
> <mytaglib:displayWidget />
> </mytaglib:widgetTag>
>
> Which is much more like a scripting language than a heirarchical XML .
> Now, I could always just use the request object within the tag helper
> classes, but this gives up flexibility and can introduce security
> issues, and it also makes the tags much more difficult to work with...
>
> In short, we should push for JSP evaluation of tag attributes. Weblogic
> could leap ahead of other app servers in this area (making up for the
> custom tag performance issues, to be solve in sp6) and Sun would, once
> again, follow Weblogic's lead and rewrite the standard to include this
> functionality.
>
> Regards,
> Carson Gross
>
-
Hi! I'm trying to mix jsf template with JSP 2.0 tag.
I almost did it, but still have some trouble.
MyForm.jspf:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib prefix="tmpl" tagdir="/WEB-INF/tags" %>
<tmpl:date bean="${MyForm}" property="date" />
date.tag
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ attribute name="bean" type="java.lang.Object" %>
<%@ attribute name="property" %>
<c:set var="form" value="${bean}" scope="session"/>
<c:set var="property" value="${property}" scope="session"/>
<f:subview id="time">
<h:inputText id="date" value="#{form[property]}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:inputText>
because I have to use JSP EL (${MyForm}) to pass a parameter to the tag the managed bean is not initialized, submit fails for the first time, but works after the bean being initialized.
Again setting "property" to session scope otherwise it doesn't work, so I will have this during the session... I am lost in JSP EL/JSF EL context relation.
Does anyone use it???
Sincerely,
D.I made a little improvement, but still have some questions...
MyForm.jspf:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib prefix="tmpl" tagdir="/WEB-INF/tags" %>
<tmpl:date bean="ResidentAttentionForm" property="date" />
date.tag:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ attribute name="bean" %>
<%@ attribute name="property" %>
<c:set var="bean" value="${bean}" scope="request"/>
<jsp:scriptlet>
javax.faces.context.FacesContext.getCurrentInstance().getApplication().getVariableResolver().resolveVariable(javax.faces.context.FacesContext.getCurrentInstance(), (String)request.getAttribute("bean"));
</jsp:scriptlet>
<c:set var="form" value="${sessionScope[bean]}" scope="session"/>
<c:set var="property" value="${property}" scope="session"/>
<f:subview id="time">
<h:inputText id="date" value="#{form[property]}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:inputText>
The problem here:
1. how can I access from JSF EL to the tag attribute without passing it to the request??? (I've seen the question in the forum, but not the answer...)
2. Is there a way to initialize a bean with dynamic name (<c: set var="${name}"?
3. When we will have jsf 1.2 done? ;-) I know they said "with J2EE5", but it also has been said "J2EE5 - summer 2005" and now everyone is talking about 2006 (?). Why can't they make jsr for jsp 2.1 and jsf 1.2 before J2EE5?.
Sincerely,
D. -
[weblogic-9.1] JSP 2.0 tag file gets compiled but not reloaded
I am trying to use a JSP 2.0 tag file on weblogic 9.1. Everything works as expected until I reload the page after changing the tag file. Consider the following files, simple.jsp and simple.tag:
h5. /simple.jsp
<%@ page language="java" %>
<%@ taglib prefix="sandbox" tagdir="/WEB-INF/tags" %>
<html>
<body>
This output comes from the jsp.
<sandbox:simple>
</sandbox:simple>
</body>
</html>h5. /WEB-INF/tags/simple.tag
<%@ tag language="java" %>
<div>This output comes from a tag file
</div>The output of a call to simple.jsp is:
<html><head>
</head><body>
This output comes from the JSP.
<div>This output comes from a tag file</div>
</body></html>So far, so good. Now I change the content of simple.tag to
<%@ tag language="java" %>
<div>This output comes from *simple.tag*<div>On a new call to simple.jsp,
1. Weblogic notices that the file has been changed,
2. generates the TagHandler .java file
3. compiles the .java file
But the new class file seems not to be loaded by weblogic; the resulting HTML does not change. It is not a browser cache issue, as I can see Javelin compilation errors. E.g., changing the tag file content to
<%@ tag language="j" %>
<div>This output comes from simple.tag</div>leads to the following (expected) error:
Compilation of JSP File '/sandbox/simple.jsp' failed:
simple.tag:1:18: "j" is not a valid setting for the language attribute.
<%@ tag language="j" %>
^-^
Changes to the .jsp file are reflected in the HTML output.
Am I missing something? Is there any flag I have to set in my weblogic configuration?You are right in saying that decoding has nothing to
do with rendering per se.I will go even further than Erik did, and dispute this statement.
Consider that you are generating an <input> tag for a text field. Among other things, you have to generate a "name" attribute. Who decides what to put there? The renderer that actually created the markup.
The "renderer" really does
two completely different things. But both should
nevertheless be separate from the component
implementation itself. You could still have the
renderer doing the decoding part, which arguably would
rarely change, and somehow delegate the actual
rendering to an implementation in a tag file.Whether you implement decoding in a separate class or inside the component, what request parameter name do you look for? It is not reasonable to assume that ALL possible renderers will choose the same parameter name ... hence, decoding and encoding are inextricably linked (the code doing the decoding has to know what kind of markup the code doing the encoding actually created). In JavaServer Faces, the current APIs create that linkage by requiring that the decode and encode be done by the same class (either the component, if you are not delegating, or the renderer if you are).
Craig -
JSP 2.x - Tag files with body-content="JSP"
I've been looking at the JSP 2.1 draft and see that, as with the previous JSP release, it is not allowed for tag-files to have body-content="JSP". I've tried to find a good answer for that on the web, but there's no one who can enlighten me. I've tried to tweak the source of Apache Tomcat 6.0.13 (Validator.ValidateVisitor and TagFileProcessor.TagFileDirectiveVisitor, both in org.apache.jasper.compiler) to accept body-content="JSP" in tag files - with great success. It is possible to have scriptlets within tags from tag files and it works as expected.
My reason for wanting scriptlets in the body-content of tags from tag files is that it would encourage a more contextual, nested (and in my eyes, a more beautiful) structure of JSP-pages, as opposed to the JSTL flat structure, where f.ex. the sql:query tag does not reside within a sql:setDataSource tag, but instead refers to the datasource through an EL-variable. I suppose that it has been constructed in this way only to make it possible for programmers to include scriptlets in-between sql:query tags that use the same datasource.
Not that it is not possible to nest tag-file tags, but I suspect that many programmers then would like to keep a flat structure so as to maintain the possibility of inserting scriptlets where needed - outside any tag which is based on a tag-file.
So, why is it not allowed for tag-files to have body-content="JSP"?Thanks for the reply, evnafets.
I'm aware that scriptet-code is generally being discouraged, although I don't understand why. I think that having a standard tag-library is a wonderful idea, but in the case of JSTL, I'm not that pleased. It relies heavily on EL, which I see as an unnecessary abstraction.
Let me give you an example. The JSTL does database-connections and queries in this way:
<sql:setDataSource var="datasource" url="jdbc:oracle:thin:@localhost:1521:TEMP" driver="oracle.jdbc.OracleDriver" user="scott" password="tiger" />
<sql:query sql="SELECT * FROM EMP" dataSource="datasource" var="resultset" />This could also be accomplished without EL in a hierarchical structure:
<sql:dataSource url="jdbc:oracle:thin:@localhost:1521:TEMP" driver="oracle.jdbc.OracleDriver" user="scott" password="tiger">
<sql:query sql="SELECT * FROM EMP">
BodyContent <% perhapsWithScriptlets; %>
</sql:query>
</sql:dataSource>...using TagSupport.findAncestorWithClass for the query to reference the datasource which it is enclosed in. (in Tomcat, the class would be called dataSource_tag. BTW, why is this not standardised in JSP?)
I would then also like to be able to use scriptlet-code inside the tags as I could if the tags were written as tag-classes, extending BodyTagSupport, and being defined in a formal, cumbersome TLD file.
Why the difference in functionality between SimpleTagSupport and BodyTagSupport - or rather; why is it then not possible to specify that a tag-file should extend BodyTagSupport rather than SimpleTagSupport? -
JSP Fragments (JSP 1.x) or JSP Segments (JSP 2.0)
I currently build a web project from a WAR file which includes JSP fragments (<root-context>/includes/*.jsp). When I compile the project JDeveloper 9.0.3.1035 will try and compile the fragments which will fail.
Sun recommends an alternate extension of '.JSPF'. When I rename the JSP fragments using this extension, JDeveloper will correctly exclude them from compilation. However no code insight, code highlighting, tag completion etc that JDeveloper does so well is available. Is there a way around this issue ?The following solution solves most of this issue;
From the menu select tools/preferences,
Select File Types,
Select JSP Source,
Click Add button and enter the .jspf extension.
Restarting JDeveloper allocates the correct association with new .jspf files inserted to the project but those inserted prior to adding the .jspf extension have an incorrect association. Even selecting 'remove from project' then 'add to project' will not set up the correct association.
Can these files be correctly associated via some other means ? -
I am trying to use the JSP Fragments feature of JSP 2.0 specification which is supported by WLP 9.2
<jsp:attribute name="stringFrag">
This is the output of chaining 2 defined strings: ${result}
</jsp:attribute>
Workshop is complaining about the unknown tag for jspYes, that's true. It looks like the bug is there in the eclipse.
https://www.eclipse.org/bugs/show_bug.cgi?format=multiple&id=105460
I appreciate if you guys find any work around for this problem in weblogic portal 9.2.
Good luck !
Sriman -
Error while running JSP with custom tag
I am trying to run a jsp with a tag and I am getting the following error when I run the jsp:
"Unable to open taglibrary /WEB-INF/jsp/mytaglib.tld : Parse Error in the tag library descriptor: External parameter entity "%(DOCTYPE);" has characters after markup."
I have no idea what this is, can anyone help me here?
tx
-ABIts difficult to tell without looking at your TLD file i.e. mytaglib.tld
However, a guess is that you may be refering to an invalid or otherwise corrupted DTD from your TLD.
Check that out.
The official DTD for TLDs in JSP 1.1 is http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd
and the official DTD for TLDs in JSP 1.2 is http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd
Maybe you are looking for
-
The Elder Scrolls II: Daggerfall in AUR, anyone would like to test?
Recently I found a way to unpack archives used in Daggerfall, so now there is nothing that stops us from having it in AUR. Especially, that Daggerfall is now free, released by Bethesda for 15 years of TES anniversary. The package contains last Dagger
-
How to handle error or exceptions in jsf
Hi i have a code using DTO and DAO.I want to handle errors in jsf automatically(ie without return parameter in java code .).Hoe i can handlethose errors in faces.config.
-
Hi All, I am trying to retrieve relational attributes from a confirmed dimension to the Essbase Cube. However I am facing lot of issues/errors during rpd development. Both the Essbase Cube hierarchy and Table that contians attributes are from same re
-
How do I get encrypted PDFs to be read in Adobe X?
I am testing this version, and the install went fine. When I went to view one of our encrypted documents, it said it needed a digital ID. Well, the Digital IDs are installed, they carried over from version 9. I even uninstalled and reinstalled, but g
-
How to download mac OSX version of CS6 Master Collection Trial from within Windows 7?
From windows, Adobe Download Assistant only gives the links to the windows versions of the trial software. I need to download the mac version trial. Any Idea??