sitemesh and spring: only index.jsp is decorated - spring

I'm trying to include sitemesh to my spring-mvc web-application.
I added this to my web.xml:
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
My decorators.xml-file:
<decorators defaultdir="/WEB-INF/decorators">
<decorator name="master" page="master.jsp">
<pattern>/</pattern>
</decorator>
</decorators>
And the master.jsp-file:
<%# taglib prefix="decorator" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
:: LiVis :: <decorator:title /> ::
</title>
<style type="text/css">#import "resources/css/generalStyle.css";</style>
</head>
<body>
<div id="wrapper">
<div id="header">
<div id="headerPicture">
<img id="livis" src="resources/images/village.png" alt="livis" />
</div>
<div id="headerMenu">
<ul id="navigation">
<li>Insert</li>
<li>Table-View</li>
<li>Graph-View</li>
<li>About</li>
</ul>
</div>
</div>
<div id="main">
<decorator:body />
</div>
</div>
</body>
</html>
I thougt, that the master.jsp would be applied to every page in my webapp, but it is only done with the index.jsp.
To óther jsp-files, which are in some folders in WEB-INF/views (see the picture) it is not done.
What could be the reason for this?
Thank you!!
Edit
A page in the vwies/admin-folder:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>Registration Page</title>
</head>
<body>
<form:form method="POST" action="/LiteratureVisualization/admin/insertTest" modelAttribute="object">
<table>
<tr>
<td>First name:</td>
<td><form:input path="author.firstname" /></td>
</tr>
<tr>
<td>Last name:</td>
<td><form:input path="author.lastname" /></td>
</tr>
<tr>
<td>Title:</td>
<td><form:input path="publication.title" /></td>
</tr>
<tr>
<td>Subtitle:</td>
<td><form:input path="publication.subtitle" /></td>
</tr>
<tr>
<td>Abstract:</td>
<td><form:input path="publication.abstr" /></td>
</tr>
<tr>
<td>Year of Launch:</td>
<td><form:input path="publication.launchYear" /></td>
</tr>
<tr>
<td>Month of Launch:</td>
<td><form:input path="publication.launchMonth" /></td>
</tr>
<tr>
<td>Volume:</td>
<td><form:input path="publication.volume" /></td>
</tr>
<tr>
<td>Number:</td>
<td><form:input path="publication.number" /></td>
</tr>
<tr>
<td>Sort of:</td>
<td><form:input path="publication.sortOf" /></td>
</tr>
<tr>
<td>Published In:</td>
<td><form:input path="publication.publishedIn" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Register"></td>
</tr>
</table>
</form:form>
</body>
</html>

Use /* instead of / in your pattern declaration.
Or if it doesn't solve the problem, look at your jsp files and check that you have html and body tags into it. If not, sitemesh can't replace the tag with ones declared in your decorator.

Related

Struts 1.....how to set scope for multiple page in dis as how to set same list scope for /delete.do link

<%#page import="com.details.EmpDetails"%>
<%#page import="java.util.ArrayList"%>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%#taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%#taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<!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=ISO-8859-1">
<title>Employee Details</title>
</head>
<body>
<%-- <%ArrayList<EmpDetails> a = (ArrayList<EmpDetails>)request.getAttribute("emp"); %> --%>
<table border="1" width="100%">
<tr>
<th>Emp ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Salary</th>
<th>Address</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<logic:iterate id="emp" name="list">
<tr align="center">
<td><bean:write name="emp" property="empId"/></td>
<td><bean:write name="emp" property="name" /></td>
<td><bean:write name="emp" property="lname" /></td>
<td><bean:write name="emp" property="sal" /></td>
<td><bean:write name="emp" property="address" /></td>
<td><form method="post">
<button>Edit</button>
</form></td>
<td>
<form id="frm" action="delete.do" method="post">
<input type="hidden" name="del" value=<bean:write name="emp" property="empId"/>>
<input type="Submit" value="Delete">
</form>
</td>
</tr>
</logic:iterate>
</table>
</body>
</html>
Error for this page
javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean: "list" in any scope
how to set scope for multiple page in dis as how to set same list scope for /delete.do link
can u please tell any solution for this code to set list scope for overall session or application so that i can access it from anywhere
no need to answer this question i got my answer
ANSWER
you have to use httpsession to setAttribute for whole session then we can use list anywhere in whole application

i am using spring mvc with tiles 3 but after deployment jsp page is not coming it is displayed as html code

<%#page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%# taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html >
<html> <head>
<title>
<%-- <tiles:getAsString name="title"/> --%>
</title>
<!-- <link rel="stylesheet" type="text/css" href="../wro/main.css" /> <script type="text/javascript" src="../wro/main.js"></script> -->
<link rel="stylesheet" type="text/css" href="../css/catalyststyle.css" media="screen"/>
<link rel="stylesheet" type="text/css" href="../css/calendar.css">
<link rel="stylesheet" type="text/css" href="../js/chosen/chosen.min.css"> <link rel="stylesheet" type="text/css" href="../js/jqueryui/jquery-ui.min.css">
<link rel="stylesheet" type="text/css" href="../js/datatables/css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="../css/overrides.css">
<script type="text/javascript" language="JavaScript" src="../js/calendar_us.js">
</script> <script type="text/javascript" src="../js/jquery.min.js"></script> <script type="text/javascript" src="../js/jqueryui/jquery-ui.custom.min.js"></script> <script type="text/javascript" src="../js/jquery.validate.min.js"></script> <script type="text/javascript" src="../js/jquery.simplemodal.min.js"></script> <script type="text/javascript" src="../js/chosen/chosen.jquery.min.js"></script>
<script type="text/javascript" src="../js/datatables/jquery.dataTables.min.js"></script>
</head>
<body>
<table class="tblone" cellspacing="0">
<tr>
<td class="header"><tiles:insertAttribute name="header"/></td>
</tr> </table> <table class="greenbg" cellspacing="2">
<tr>
<td valign="top"><fmt:message key="msg.cis"/></td>
<%-- <c:if test="${!empty user}">
<td valign="top" align="right">
<fmt:message key="sso.logged"/>
<c:out value = "${user.name}"/>
</td> </c:if> --%> </tr> </table> <table class="tblone" cellspacing="2"> <tr>
<td valign="top" class="hdrText">
<tiles:insertAttribute name="modules"/></td>
<td> </td>
</tr>
</table>
<table class="tblone" cellspacing="2">
<tr> <td valign="top" class="tblthree"><%-- <tiles:getAsString name="title"/> --%></td>
<td> </td>
</tr>
</table>
<table class="tblone" cellspacing="2">
<tr>
<td valign="top" class="tablnav"><tiles:insertAttribute name="navigation"/></td>
<td valign="top" class="tbltwo">
<tiles:insertAttribute name="body"/></td>
</tr>
</table>
<table class="tblone" cellspacing="0">
<tr/>
<tr/>
<tr/>
<tr/>
<tr>
<td><tiles:insertAttribute name="footer"/></td>
</tr>
</table>
</body>
</html>
thanks for your replay, i solved the problem, problem is, in the top line of the jsp i have given the jsp page directive ie..
"<%#page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%> "
this is not loading, so i configured my web.xml with CharacterEncodingFilter so problem solved

Jsp page is not accepting css rules under Spring Mvc project (running on Tomcat 7)

I am trying to apply a css rule in a jsp page running under spring mvc environment.
webapp/css/mystyles.css :
.center{
margin: auto; text-align: center;
}
h1{
color: red;
}
webapp/WEB-INF/jsp/Layout.jsp:
<%# taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title><tiles:insertAttribute name="title" ignore="true"/></title>
<link rel="stylesheet" type="text/css" href="../../css/mystyles.css" media="screen" />
</head>
<body>
<table border="1" cellspacing="2" align="center">
<tr>
<td height="30" colspan="2">
<tiles:insertAttribute name="header"/>
</td>
</tr>
<tr>
<td height="250" width="150">
<tiles:insertAttribute name="menu"/>
</td>
<td width="400">
<tiles:insertAttribute name="body"/>
</td>
</tr>
<tr>
<td height="30" colspan="2">
<tiles:insertAttribute name="footer"/>
</td>
</tr>
</table>
</body>
</html>
And here is part of the produced web page code I am getting with firebug :
<head>
<title>Being Java Guys | Tiles Integration</title>
<link media="screen" href="../../css/mystyles.css" type="text/css" rel="stylesheet">
<html><head><title>Apache Tomcat/7.0.35 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The requested resource is not available.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.35</h3></body></html>
</link>
</head>
<div class="center">
<h1>Header</h1>
</div>
Unfortunately I am not getting a red Header.
You have to change something so the css file gets loaded.
Tomcat can't find it at "../../css/mystyles.css" (which you show as being http://localhost/css/mystyles.css" in firebug's net tab) so the URL in the tag is either wrong or Tomcat is set up somehow wrong.
Hint: You can enter the URL for a css file in the browser address bar to try various things more easily as you change the Tomcat config or load files.
You are messing server side file locations, and URLs.
In server-side /WEB-INF/pages/../../css/mycss.css would be your css, but not when it is a page rendered by a browser. Because on the browser your JSPs URL is something else.
You shall have a <base> tag in your <head> to specify relative URLs target, and then specify URL relative to that.
Please add context path of application before css file path.
<%# taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="contextPath" scope="request" value="${pageContext.request.contextPath}" />
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title><tiles:insertAttribute name="title" ignore="true"/></title>
<link rel="stylesheet" type="text/css" href="${contextPath}/css/mystyles.css" media="screen" />
</head>
<body>
<table border="1" cellspacing="2" align="center">
<tr>
<td height="30" colspan="2">
<tiles:insertAttribute name="header"/>
</td>
</tr>
<tr>
<td height="250" width="150">
<tiles:insertAttribute name="menu"/>
</td>
<td width="400">
<tiles:insertAttribute name="body"/>
</td>
</tr>
<tr>
<td height="30" colspan="2">
<tiles:insertAttribute name="footer"/>
</td>
</tr>
</table>
</body>
</html>

How to make data remain after success validation?

I have jsp using struts bean tag library:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
</head>
<body>
<p><a class="colorGrey" href="Welcome.do">
<bean:message key="menu.label" />
</a> >><bean:message key="menu.link.addnews" /> </p>
<p><br>
</p>
<html:form action="/NewsSave">
<table width="100%" border="0">
<tr>
<td class="colorGrey" width="164" height="35">
<bean:message key="body.news.title" /> </td>
<td width="577">
<html:text property="newsTitle" size="40" value=""/> </td>
</tr>
<tr>
<td colspan="2">
<html:errors property="newstitle" />
</td>
</tr>
<tr>
<td class="colorGrey">
<bean:message key="body.news.date" /> </td>
<td>
<html:text property="newsDate" size="10" value=""/> </td>
</tr>
<tr>
<td height="21" colspan="2" valign="top">
<html:errors property="newsdate" />
</td>
</tr>
<tr>
<td class="colorGrey" height="61" valign="top">
<bean:message key="body.news.brief" /> </td>
<td valign="top">
<html:textarea property="brief" cols="40" rows="6" value=""/>
</td>
</tr>
<tr>
<td height="23" colspan="2" valign="top"><html:errors property="brief" /></td>
</tr>
<tr>
<td class="colorGrey" height="100" valign="top">
<bean:message key="body.news.content" />
</td>
<td valign="top">
<html:textarea property="content" cols="40" rows="12" value=""/>
</td>
</tr>
<tr>
<td height="23" colspan="2" valign="top">
<html:errors property="content" />
</td>
</tr>
</table>
<html:submit value="SAVE"/>
</html:form>
<form method="POST"
action="Link.do?method=newsList"
onsubmit="return confirm('<bean:message key="body.onsubmit.cancel" />')">
<input type="submit" value="CANCEL">
</form>
And I use validator plugin, which means that after receiving incorrect info it gives message bellow text field telling what's wrong. But problem is that everything disappear after submiting. So it no info in text or text-areatags. I know that it happens because of value="". But I have another page with the same fields for adding info, which should be clear from the beginning. And if I remove value="", the info from this fields will be displayed on that page after forwarding. So
What should I do to clear info from forms after forwarding to
another page?
How to make info remain after success validation?
As you mentioned, you should remove value="" as this is setting the fields to empty. If you want to clear the values then you should do this in the Action class in which your Form bean is populated.
If you are finding that your Form beans are retaining their values between requests then check that they are request scope: the scope attribute of the action element should be "request" in struts.config

Creating site with hindi fonts with I18n feature of Struts2

Hi I am trying to create an application with hindi fonts (Only Lable required to be shown in hindi)with the help of Struts2 i18n feature.
I have cretaed required properties file as global_hi.properties
for the label username ,password and submit button.
It works fine for submit button,but for password its showing *??? .
I have attached my jsp ,struts.xml and proerties fiel.
struts.xml is
<struts>
<constant name="struts.custom.i18n.resources" value="global" />
<constant name="struts.devMode" value="true" />
<package name="default" extends="struts-default, tiles-default,jfreechart-default">
<interceptors>
<interceptor name="loginInterceptor" class="common.AuthenticationInterceptor" />
<interceptor-stack name="chkSession">
<interceptor-ref name="i18n"/>
<interceptor-ref name="defaultStack" />
<interceptor-ref name="loginInterceptor" />
</interceptor-stack>
</interceptors>
<global-results>
<result name="invalid.token">common/doublePost.jsp</result>
<result name="loginAction" type="redirect">/sessionnotfound.jsp</result>
</global-results>
<action name="showHomePage">
<result type="tiles">Login</result>
</action>
<action name="locale">
<result type="tiles">Login</result>
</action>
</package>
</struts>
my jsp is
<%#page contentType="text/html;charset=utf-8" pageEncoding="UTF-8"%>
<%# taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Administration Login</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<link href="/LiquorShopManagementSystem/css/stylesheet.css" type="text/css" rel="stylesheet">
<s:head/>
</head>
<body>
<div id="header"></div>
<s:form name="frmAdminLogin" id="frmAdminLogin" method="post" action="doLogin" validate="true">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td style="border-right:fuchsia 2px solid;">
<img src="/LiquorShopManagementSystem/images/BookShop.jpg" height="250"/>
</td>
<td valign="middle">
<table align="center" cellspacing="0" cellpadding="4" border="0" width="248px">
<tr>
<td colspan="2" class="spanHeader">
<span>Back Officeghj</span>
</td>
</tr>
<tr>
<td colspan="2" align="left" class="error">
<s:property value="message" />
</td>
</tr>
<tr>
<td valign="middle">
<s:textfield required="true" requiredposition="left" maxLength="25" key="global.username" name="userMaster.loginid" title="Enter Username"/>
<s:password required="true" requiredposition="left" maxLength="8" key="global.password" name="userMaster.Password" title="Enter Password"/>
</td>
</tr>
<tr>
<td>
<s:submit cssClass="buttonText" cssStyle="background:url(/BookShop/images/submit_bg.gif) no-repeat scroll 37px 0px;" name="login" key="global.submit" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</s:form>
</body>
</html>
and properties file is
#Global messages
global.username = Username
global.password =\u0938\u092E\u094D\u092E\u0947\u0932\u0928
global.submit =\u0938\u092E\u094D\u092E\u0947\u0932\u0928
although it is working fine for submit tag.
Can any one suggest for any workaround for this.
thanks
This is what i tried and its working fine for me.All i changed the value in my property file
global.password=\u092A\u093E\u0938\u0935\u0930\u094D\u0921
and here is the output screenshot
i believe you need to check the way you are encoding your Hindi characters.
surprising, it giving following output when i am using your entries..

Resources