I have two files. choose.jsp and little.jspf
choose.jsp
<c:import url="little.jspf">
<c:param name="his" value="${param.choice}"></c:param>
</c:import>
little.jspf
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<br />
this is little.jsp <br />
I just heard that somebody here said ${param.his} is important.
Output
output is I just heard that somebody here said ${param.his} is important.
But when I change the .jspf to .jsp it compiles fine. Is it not possible to pass parameter to .jspf file ?
A .jspf file is supposed to be statically included (with the <%#include %> directive) inside another JSP. Not dynamically included or imported.
I would create a JSP tag file instead of using c:import.
Related
Hi I am getting an error where my s:select will work fine in the parent jsp file but when it is within another jsp file that is being called upon by the parent.jsp it doesn't seem to work anymore. I removed everything down to just these two lines and all the extra stuff around the select. Any suggestion or advice is greatly appreciated!
parent.jsp
<%# taglib uri="/struts-tags" prefix="s" %>
<s:select label="some label"
list="#{'01':'Dev','2':'Manager','03':'Customer'}"
name="test"
/>
<s:component template="child.jsp" templateDir="/pub/" theme="folder1" />
child.jsp
<%# taglib uri="/struts-tags" prefix="s" %>
<s:select label="some label"
list="#{'01':'Dev','2':'Manager','03':'Customer'}"
name="test"
/>
File structure
/pub
----/folder1
--------parent.jsp <-- dropdown displays appears
--------child.jsp <--- dropdown breaks
Error message
Struts Problem Report
Struts has detected an unhandled exception:
Messages:
Non-normalized name, starts with "/": /pub//simple/select.ftl
File:
freemarker/cache/TemplateCache.java
Line number:
914
From what I understand turns out it seems to be that you need to set the templateDir inside the child.jsp to the path to the template directory that it is within Struts 2 so it can find the code for s:select. This code managed to fix the issue:
<s:set var="templateDir" value="%{'template'}" scope="page"/>
An example will make this clearer!
The jsp file...
<%# taglib prefix ="jam" uri= "http://jam.tld" %>
<%# page language="java" contentType="text/html; charset=UTF-8" pageEncoding="ISO-8859-1"%>
<%
String targetPage = true ? "toast" : "bread";
%>
<jam:text onmousedown="movePage('<%=targetPage%>');" id="<%=targetPage%>"><%=targetPage%></jam:text>
Note - the taglib is not mine and I have no control over it. (it isn't really called jam either :).
This then creates this HTML...
<td onmousedown="movePage('<%=targetpage%>;');" id="toast">toast</td>
Which as you can see: the <%=targetPage%> was only replaced/parsed in the non-javascript bit?
The compiled jsp file looks like this:
jspx_th_jam_005ftext_005f2.setOnmousedown("movepage('<%=targetpage%>')");
Anyone know what is going on, or how to fix it?
Why is the <%=%> tag being ignored when it is part of JavaScript statement?
:)
Here's a bit of a cheat solution, you dont need the JSP tag in that JS call. In fact, it's tidier this way
<jam:text onmousedown="movePage(this.id);" id="<%=targetPage%>"><%=targetPage%></jam:text>
I am trying to execute the following jsp code which contains the optiontransferselect tag. However I am getting the below exception:
org.apache.jasper.JasperException: /abc.jsp(10,0) No tag "optiontransferselect label" defined in tag library imported with prefix "s"
Please find the below code i have used.
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Optiontransferselect Tag Example!</title>
</head>
<body>
<s:form>
<s:optiontransferselect label="Employee Records" name="leftSideEmployeeRecords" leftTitle="RoseIndia" rightTitle="JavaJazzUp" list="{'Deepak Kumar', 'Sushil Kumar','Vinod Kumar','Deepak Monthy','Deepak Mihanti', 'Sushil Kumar', 'Ravi Kant Kumar'}" headerKey="headerKey" headerValue="--- Please Select ---" doubleName="rightSideEmployeeRecords" doubleList="{'Amar Deep Patel', 'Amit Kumar','Chandan Kumar', 'Noor Kumar','Tammana Kumari'}" doubleHeaderKey="doubleHeaderKey" doubleHeaderValue="--- Please Select ---" />
</s:form>
</body>
</html>
Please Guide.
You are using older version of struts-core-xxx.jar in your project. Are you using 2.3.16 or above?
To use optiontransferselect tag you need to use struts-core-2.3.16 or higher..
You need to include the <s:head> tag which drags in some javascript that is needed to get the <s:optiontransferselect> tag to work.
I currently have my .tag files declared with:
<%#taglib prefix="t" tagdir="/WEB-INF/tags" %>
Example of the path of a tag file :
/WEB-INF/tags/test.tag
And I use them like so :
<t:test oneAttributeKey="oneAttributeValue">
some content...
</t:test>
My problem : I don't want to put all my tag files in one single folder, "/WEB-INF/tags".
I would prefere to have them in different subdirectories :
/WEB-INF/tags/users/
/WEB-INF/tags/widgetsA/
/WEB-INF/tags/widgetsB/
(...)
Is this possible, without creating a different taglib prefix for each and everyone of them?
Example of what I'd like to avoid :
<%#taglib prefix="t_users" tagdir="/WEB-INF/tags/users" %>
<%#taglib prefix="t_widgetsA" tagdir="/WEB-INF/tags/widgetsA" %>
<%#taglib prefix="t_widgetsB" tagdir="/WEB-INF/tags/widgetsB" %>
Example of what I would like, using a single "t" prefix :
<t:users/onetag oneAttributeKey="oneAttributeValue">
some content...
</t:users/onetag>
Does a similar solution exist?
UPDATE : BalusC showed it's possible to use one prefix only, by defining all the tag files in a single .tld. I guess my question was not clear enough then : I'd like to know if it's possible to use the tag files in multiple subdirectories, without having to specify a path to each of them anywhere except in the element that use them (ex: "<t:users/onetag")!
What I do not like about JSP Tags is that they act very differently than regular JSP files, even if they actually share very similar content. In fact, I even decided to put all my jsp files inside the /WEB-INF/tags/ folder, so they are side to side with the tag files (I had to choose /WEB-INF/tags/ for that, since this folder is mandatory for the tag files, for some reason)! I don't understand why some of my files containing HTML would go in /WEB-INF/jsp/ and some others in /WEB-INF/tags/!!
I want to be able to group the jsp and tag files into directories, depending of what they are related to! Example :
/WEB-INF/tags/users/userProfileLayout.tag
/WEB-INF/tags/users/employeeProfile.jsp
/WEB-INF/tags/users/employerProfile.jsp
/WEB-INF/tags/widgetsA/widgetALayout.tag
/WEB-INF/tags/widgetsA/oldWidgetA.jsp
/WEB-INF/tags/widgetsA/newWidgetA.jsp
But this forces me to declare the path of each of the subdirectories, in multiple #tablib or in a .tld, which I find a little bit inconvenient. I'll live with it, but I think it could be improved.
Define them as <tag-file> in a single .tld file which you put in /WEB-INF folder.
E.g. /WEB-INF/my-tags.tld
<?xml version="1.0" encoding="UTF-8" ?>
<taglib
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1"
>
<display-name>My custom tags</display-name>
<tlib-version>1.0</tlib-version>
<short-name>my</short-name>
<uri>http://example.com/tags</uri>
<tag-file>
<name>foo</name>
<path>/WEB-INF/tags/users/foo.tag</path>
</tag-file>
<tag-file>
<name>bar</name>
<path>/WEB-INF/tags/widgetsA/bar.tag</path>
</tag-file>
<tag-file>
<name>baz</name>
<path>/WEB-INF/tags/widgetsB/baz.tag</path>
</tag-file>
</taglib>
Use it in your JSPs as follows
<%#taglib prefix="my" uri="http://example.com/tags" %>
...
<my:foo />
<my:bar />
<my:baz />
A pattern that I follow, even though doesn't address the OP's problem directly, I find it makes the whole situation a lot less painful, which is creating a JSP Fragment where I define all taglibs:
/WEB-INF/views/taglibs.jspf
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%# taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%# taglib prefix="layout" tagdir="/WEB-INF/tags/layout" %>
<%# taglib prefix="t_users" tagdir="/WEB-INF/tags/users" %>
<%# taglib prefix="t_widgetsA" tagdir="/WEB-INF/tags/widgetsA" %>
<%# taglib prefix="t_widgetsB" tagdir="/WEB-INF/tags/widgetsB" %>
And then include this JSP Fragment at the top of every JSP file:
/WEB-INF/views/users/employeeProfile.jsp
<%# include file="/WEB-INF/views/taglibs.jspf" %>
<layout:main>
<h1>Employee Profile</h1>
...
</layout:main>
Should work. Folder names under the specified tag-dir value become hyphen-separated parts of the tag names you would use.
I followed THIS but had no luck.
My .jsp file has in head tag:
<s:head theme="ajax" />
and in body tag
<s:datetimepicker name="dateOfBirth" label="Format (yyyy-MM-dd)" displayFormat="yyyy-MM-dd"/>
But it is not showing, here is the picture:
My generated HTML source code contains all necessary lines like in example (script tags and other are generated....)
Any ideas?
EDIT:
Following Quaternion's answer:
I was using, struts2-core-2.0.12.jar which recognized <s:datetimepicker /> tag but wasn't showing in my jsp page. After replacing struts2-core-2.0.12 with newer one struts2-core-2.2.1.jar, <s:datetimepicker /> tag wasn't recognized.
After putting <%# taglib prefix="sx" uri="/struts-dojo-tags" %> in head of the file it wasn't recognized as my tag library. Based on THIS, you should download struts2-dojo-plugin-2.1.2.jar separately and add it into your WEB-INF/lib folder (you can downlad it here --> struts-2.1.2-lib.zip --> struts2-dojo-plugin-2.1.2.jar).
After that you just use sx tag for your datetimepicker.
IMPORTANT: Don't forger to put <sx:head/> in head tag of your jsp page --> examples here.
The later versions of struts2 require:
<%# taglib prefix="sx" uri="/struts-dojo-tags" %>
Then of course change the tag namespace, using:
<sx:datetimepicker name="dateOfBirth" label="Format (yyyy-MM-dd)" displayFormat="yyyy-MM-dd"/>
See Struts2 datetimepicker It's best if you consult struts.apache.org and ensure you are using the documentation at the correct version, things change!
use
sx:head tag in the head section of jsp.
Are you sure you have <%# taglib prefix="s" uri="/struts-tags" %> included? I miss that at times wondering why things do not show up.