strut 2 s:select won't work within a jsp file - java

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"/>

Related

Struts 2 optiontransferselect tag not working in jsp?

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.

.jspf not compiling even though in jsp

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.

JSP Error -- Equal Symbol Expected

I'm relatively new to JSPs, and I'm trying to use a FormBean within one of my files.
When I try to open the JSP page on a local Tomcat server, I get the following error:
org.apache.jasper.JasperException: /entryForm.jsp (line: 4, column: 21) equal symbol expected
The first five lines of my code are:
<!DOCTYPE html>
<%# page import = "jared.simpledatabase.* %>
<jsp:useBean id="form" class="jared.simpledatabase.FormBean" scope="session"/>
<jsp:setProperty name="form" property="*"/>
Any ideas what I'm doing wrong? Thanks!
Here's a guess - missing double quote:
<%# page import = "jared.simpledatabase.*" %>
In my case it was a missing " in the jsp:param tag e.g.
<jsp:param name="X" value="{$someValue}/>
Changing it to ... fixed the issue
<jsp:param name="X" value="{$someValue}"/>

Why my included JSP file won't get processed correctly?

I am trying (and learning) to build a java web framework, and in the process of developing its' code generator based on the content of the database. In the view making process, I stumble in a difficulty, which I don't know how to solve it.
Firstly, I want all the pages to be created using the following index.jsp :
<body>
<%# include file="header.jsp" %>
<hr/>
<%# include file="body.jsp" %>
<hr/>
<%# include file="footer.jsp" %>
</body>
And, in the body.jsp, I want it to be like this :
<jsp:include page="${application_modul}" %>
Where application_modul is an attribute defined in its' controller this way :
request.setAttribute("application_modul","user_account\\view_user_account.jsp");
It can find the file correctly, but the processed jsp is not what I expected. Here :
<c:forEach items="[application.models.UserAccountModel#18a49e0, application.models.UserAccountModel#1f82982]" var="item" varStatus="status" >
<tr>
....
You can see the items attribute of jstl forEach, got its variable name (toString())...
Any Idea what the problem is????
I hope I describe my problem correctly
Many thanks!
PS :
I already create a quick fix for this, but not what I want it though. In the generated view_user_account.jsp, I do it like this :
<body>
<%# include file="header.jsp" %>
<hr/>
<c:forEach items="${row}" var="item" varStatus="status" >
<tr>
....
<hr/>
<%# include file="footer.jsp" %>
</body>
You can see that I create the whole file here...
EDITED:
PS : ${row} is an ArrayList populated with data from certain table
So, to summarize your problem in a single sentence, JSTL tags are not been parsed and they end up plain in generated HTML output?
You need to declare JSTL taglib in top of the JSP page where you're using JSTL tags to get them to run. For the JSTL core taglib, that'll be
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
I am not sure but, Try this...
index.jsp
<jsp:param name="parameterName" value="{parameterValue | <%= expression %>}" />

Struts2 datetimepicker not showing

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.

Categories