Controller of Spring MVC working but model is empty in JSP - java

Visit my previous question to see my configurations of spring mvc Spring MVC Controller working but not creating the specified response URL ,It is creating the url from request mapping string
Now am facing one strange error in jsp page
The Controller class method is
#RequestMapping(value="/branchshow.travel", method=RequestMethod.GET)
public String getBranchShow(){
List<BranchModel> branches = branchService.getBranches();
System.out.println(branches.size());
new ModelMap().addAttribute("branches", branches);
return "/branch/branchshow";
}
I got the requested jsp page but the model named 'branches' is empty in jsp. I got the size of list as 140 in console. So it means that returned model is empty in 'branchshow.jsp'
I checked many links, all are saying its because of jsp version but am using 3.0
my web.xml starting is
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID"
version="3.0">
so the version is 3.0
I would like to show my branchshow.jsp code here
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# page isELIgnored="false" %>
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Service-Home</title>
<!-- resources linking -->
<spring:url value="/resources/js/login_forms.js" var="login_forms"/>
<spring:url value="/resources/js/jquery.js" var="jqueryjs"/>
<spring:url value="/resources/js/bootstrap.min.js" var="bootstrapminjs"/>
<spring:url value="/resources/css/bootstrap.min.css"
var="bootstrapmincss"></spring:url>
<spring:url value="/resources/css/custom.css" var="customcss">
</spring:url>
<spring:url value="/resources/css/simple-sidebar.css" var="sidebarcss">
</spring:url>
<spring:url value="/resources/images/toggle.png" var="hide"/>
<spring:url value="/resources/images/insert.png" var="insert"/>
<spring:url value="/resources/images/edit.png" var="update"/>
<spring:url value="/resources/images/delete.png" var="delete"/>
<spring:url value="/resources/images/search.png" var="search"/>
<!-- Custom CSS -->
<link rel="stylesheet" href="${bootstrapmincss}">
<link rel="stylesheet" href="${sidebarcss}">
<link rel="stylesheet" href="${customcss}">
</head>
<body>
<div id="wrapper">
<!-- Sidebar -->
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li>
<font color="WHITE" style="font-style:bold">CALICUT TRAVELS-SERVICES</font>
</li>
<li>
Master
<ul>
<li>Branch</li>
<li>Hotel</li>
<li>Air line</li>
<li>Customers</li>
<li>Staff</li>
<li>Suppliers</li>
</ul>
</li>
<li>
Packages
<ul>
<li>Airline</li>
<li>Hotel</li>
<li>Transportation</li>
</ul>
</li>
<li>
Sales Invoices
<ul>
<li>Book rooms</li>
<li>Book tickets</li>
<li>Book visa</li>
<li>Book package</li>
</ul>
</li>
<li>
Sales Returns
<ul>
<li>Cancel rooms</li>
<li>Cancel tickets</li>
<li>Cancel visa</li>
<li>Cancel Package</li>
</ul>
</li>
<li>
Miscellaneous
<ul>
<li>Taxi</li>
<li>Food</li>
</ul>
</li>
<li>
Purchase
<ul>
<li>Airline</li>
<li>Hotel</li>
<li>Visa</li>
<li>Transportation</li>
<li>Packages</li>
</ul>
</li>
<li>
Purchase Returns
<ul>
<li>Airline</li>
<li>Hotel</li>
<li>Visa</li>
<li>Transportation</li>
<li>Package</li>
</ul>
</li>
<li>
Reports
<ul>
<li>Sales invoices</li>
<li>sales returns</li>
<li>purchase invoices</li>
<li>purchase returns</li>
<li>packages</li>
<li>Customer summery report</li>
</ul>
</li>
</ul>
</div>
<!-- /#sidebar-wrapper -->
<!-- Page Content -->
<div id="service-home-conetent">
<div class="container-fluid">
<div class="row">
<table>
<tr>
<th align="center" width='20'><img alt="HIDE" src="${hide}" width='20'></th>
<th align="center" width="400" colspan="4"><h2>BRANCH</h2></th>
</tr>
<tr align="center">
<th align="center" width='200'></th>
<th align="center" width='20'><img src="${insert}" width='20'></th>
<th align="center" width='20'><img src="${update}" width='20'></th>
<th align="center" width='20'><img src="${delete}" width='20'></th>
<th align="center" width='20'><img src="${search}" width='20'></th>
</tr>
<tr>
<th align="center" width='200'></th>
<th align="center" width='20'>Insert</th>
<th align="center" width='20'>update</th>
<th align="center" width='20'>Delete</th>
<th align="center" width='20'>Search</th>
</tr>
</table>
<input type="hidden" id='form_use' value='view'/>
<fieldset class="well the-fieldset">
<legend class="the-legend"> BRANCHES </legend>
<table>
<tr>
<th> Branch Name</th>
</tr>
<c:forEach var="branch" items="${branches}">
<tr>
<td>${branch.branchName}</td>
</tr>
</c:forEach>
</table>
</fieldset>
</div>
</div>
</div>
<!-- /#page-content-wrapper -->
</div>
<!-- /#wrapper -->
<!-- jQuery -->
<script src="${jqueryjs}"></script>
<!-- Bootstrap Core JavaScript -->
<script src="${bootstrapminjs}"></script>
<script src="${login_forms}"></script>
<!-- Menu Toggle Script -->
<script>
$("#menu-toggle").click(function(e) {
e.preventDefault();
$("#wrapper").toggleClass("toggled");
});
</script>
I enabled EL in jsp then also this issue persists. If anybody faced this issue before let me know the solution

On the line you create a new ModelMap but you don't return it
new ModelMap().addAttribute("branches", branches);
You method could return a ModelAndView object to store your model attribute 'branches' and view '/branch/branchshow'
#RequestMapping(value="/branchshow.travel", method=RequestMethod.GET)
public ModelAndView getBranchShow() {
ModelAndView mav = new ModelAndView();
List<BranchModel> branches = branchService.getBranches();
System.out.println(branches.size());
mav.getModelMap().put("branches", branches);
mav.setViewName("/branch/branchshow");
return mav;
}

Related

HTML page not displaying when called from backend using springboot and thymeleaf

I have this controller file code. This accepts data from the frontend in the form of #RequestParams. Once I have received the values, I am trying to call another html file called cart .html by adding an attribute using the addAttribute function in models.
#GetMapping("/cart")
#ResponseBody
public String getIfBorrowedBook(Model model, #RequestParam List<Integer> bookIds) {
System.out.println(bookIds);
// if(ifBorrowed.equals("on")) {
// Books book = booksService.findById(bookId);
// book.setIfBorrowed(true);
// booksService.save(book);
List<Books> booksInCart = new ArrayList<>();
for(Integer id:bookIds) {
booksInCart.add(booksService.findById(id));
}
System.out.println(booksInCart);
model.addAttribute("booksInCart", booksInCart);
return "cart";
}
This is my cart.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="ISO-8859-1">
<title>List Books</title>
<link rel="stylesheet" type="text/css" href="/webjars/bootstrap/css/bootstrap.min.css" />
<script type="text/javascript" src="/webjars/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/webjars/bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container text-center">
<h1>
Cart
</h1>
<div>
<table class="table table-striped table-bordered">
<thead class="thead-dark">
<tr>
<th>Title</th>
<th>Genre</th>
<th>Author</th>
<th>Edition</th>
</tr>
</thead>
<tbody>
<tr th:each="book: ${booksInCart}">
<td th:text="${book.title}">Title</td>
<td th:text="${book.genre}">Genre</td>
<td th:text="${book.author}">Author</td>
<td th:text="${book.edition}">Edition</td>
<td>
</td>
</tr>
</tbody>
<div>
</div>
</table>
</div>
</div>
</body>
</html>
This is the show_filtered books file that has a form which is submitted to the controller get request once a buttom is clicked.
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="ISO-8859-1">
<title>List Books</title>
<link rel="stylesheet" type="text/css" href="/webjars/bootstrap/css/bootstrap.min.css" />
<script type="text/javascript" src="/webjars/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/webjars/bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container text-center">
<div>
<h1>
<div th:text="'Books on '+${filteredBooks[0].genre}"></div>
</h1>
</div>
<div>
<form th:action="#{/cart}">
<table class="table table-striped table-bordered">
<thead class="thead-dark">
<tr>
<th>Title</th>
<th>Genre</th>
<th>Author</th>
<th>Edition</th>
<th>Borrow Book</th>
</tr>
</thead>
<tbody>
<tr th:each="book: ${filteredBooks}">
<td th:text="${book.title}">Title</td>
<td th:text="${book.genre}">Genre</td>
<td th:text="${book.author}">Author</td>
<td th:text="${book.edition}">Edition</td>
<td>
<input type="checkbox" name="bookIds" th:value="${book.bookId}" th:checked="${book.ifBorrowed}"/>
</td>
</tr>
</tbody>
<div>
<a href="cart">
<button type="submit" class="btn btn-primary">Add to Cart</button>
</a>
</div>
</table>
</form>
</div>
</div>
</body>
</html>
But when I try to return the cart string at the end of getIfBorrowed() method, I am not getting the cart.html file. I am just getting a string that says cart on the webpage. This cart.html file is location in src/main/resources/templates. Therefore spring mvc should automatically be able to recognize the file but it does not do so.

css included in JSP is not working across browser

I have an issue where my CSS is not getting picked up in chrome and firefox but works well in IE8. I didn't check in higher versions of IE though.
below is the code where you can see Soo.css is included in the top and I'm trying to access the CSS for class="TableHeader" in the 2nd td in the table.
I can see the hyperlink for 'Home' in IE8 but not in chrome and firefox. But if I remove the clas="tableheader", I can see the hyperlink for "Home" in both the browser.
I don't see why it shouldn't work across browser. What is the right way to include. I have so many pages where it just works fine. below is the code snippet:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%# taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%# taglib uri="/WEB-INF/abc.tld" prefix="abc" %>
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<%# page import="java.util.*" %>
<%# page import="java.text.*" %>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="IBM WebSphere Studio">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/theme/Soo.css"/>
<%
Locale locales = Locale.US;
SimpleDateFormat SFormatDate;
DateFormat CurrentYear;
CurrentYear = DateFormat.getDateInstance(DateFormat.LONG, locales);
Date today = new Date();
SFormatDate = new SimpleDateFormat("MM/dd/yyyy", locales);
CurrentYear = new SimpleDateFormat("yyyy ", locales);
String flag = "N";
%>
<center>
<table width="100%" border="1" cellpadding="0" cellspacing="0" summary="Table used for formatting.">
<tbody>
<tr>
<td colspan="3">
<a href="http://www.abc" target="_blank" title="www.abc">
<img src="<%=request.getContextPath()%>/images/p1_abc_logo.gif" width="157" height="25" border="0" alt="Click here to go to www.abc.">
</a>
</td>
<td align="right" colspan="1">
<img alt="Skip Repetitive Navigation Links" border="0" src="<%=request.getContextPath()%>/images/test_blank.gif">
<span style="color: gray">|</span>
<a href="<%=request.getContextPath()%>/../../../pol1/i2_chgrequest.cfm"
style="color: black"
target="system_feedback"
title="Feedback">Feedback</a>
<span style="color: gray">|</span>
<a href="<%=request.getContextPath()%>/../../../pol1/profile/index.cfm?fa=profile"
title="Click for Personal Profile"
style="color: black">Personal Profile</a>
<span style="color: gray">|</span>
<a href="<%=request.getContextPath()%>/../../../pol1/logout.cfm"
style="color: black"
title="Logout">Logout</a>
<span style="color: gray">|</span> <a name="skipnav1"></a>
</td>
</tr>
<!-- Side Bar -->
<tr valign="top">
<td nowrap width="12%" class="TableHeader" colspan="1">
<img alt="Skip Repetitive Navigation Links" border="0" src="<%=request.getContextPath()%>/images/test_blank.gif"> <br>
<br>
<p style="margin-left: 1em; margin-right: 1em">
<!-- remove href before code freeze -->
<!--a href="<%=request.getContextPath()%>/test.jsp" style="text-decoration: none; color: white"> Back to Main Menu </a-->
<a href="<%=request.getContextPath()%>/../../../pol1/viewer001/i3_menu.cfm?fa=account_menu&group=BMEU&toplevelpage=true"
title="Message Center"
style="text-decoration: none; color: white">Home</a>
</p>
</td>
</tr>
</tbody>
</table>

<c:forEach> tag not work properly

My java code is
#RequestMapping(value = "/common_views/view-lecturer-Projects")
public String viewLecturerProjects(HttpServletRequest request, ModelMap map) {
String userId=request.getParameter("userId");
map.put("viewUserProjects", projectService.findProjectByUserId(Long.valueOf(userId)));
System.out.println("=================>Project type= "+projectService.findProjectByUserId(Long.valueOf(userId)).getTypeOfProject());
System.out.println("=================>Project title= "+projectService.findProjectByUserId(Long.valueOf(userId)).getTitleOfProject());
// System.out.println("===============>Project= "+(projectService.findProjectByUserId(Long.valueOf(userId))).get(0).getTitleOfProject());
return "common_views/viewLecturerProjects";
}
the page /common_views/view-lecturer-Projects is
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Index - SIL-Bridge</title>
</head>
<body>
<jsp:include page="/WEB-INF/includes/header.jsp" flush="true" />
<jsp:include page="/WEB-INF/includes/menubar.jsp" flush="false" />
<div class="main main-inner">
<div class="container">
<div class="row">
<div class="span12">
<div class="widget widget-nopad">
<div class="widget-header"><i class="icon-list-alt"></i>
<h3>Home</h3>
</div>
<!-- /widget-header -->
<div class="widget-content">
<form id="view-all-lecturer-project" class="form-horizontal">
<fieldset>
<table id="viewAllLecturersProject" class="table table-striped table-bordered">
<thead>
<tr>
<th>Title of the project</th>
<th>Type of the project</th>
</tr>
</thead>
<tbody>
<c:forEach items="${viewUserProjects}" var="viewUserProject">
<tr>
<td><c:out value="${viewUserProject.titleOfProject}"/></td>
<td><c:out value="${viewUserProject.typeOfProject}"/></td>
</tr>
</c:forEach>
</tbody>
</table>
<br/><br/>
</fieldset>
</form>
</div>
</div>
<!-- /widget -->
</div>
</div>
<!-- /row -->
</div>
<!-- /container -->
</div>
<!-- /main-inner -->
</body>
</html>
In this page values ${viewUserProject.titleOfProject},${viewUserProject.typeOfProject}` not disply in this page but java code print values
Write the following taglib import statement on top of your jsp.
<%# taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core" %>
and if you dont have JARSS for JSTL, then download from below URL and put that JAR into your Build Path of project.
http://www.oracle.com/technetwork/java/index-jsp-135995.html

Enabling back button with Ajax

Following is my index.jsp:
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<s:head/>
<sj:head/>
<script type="text/javascript" src="jquery.validate.js"></script>
<script type="text/javascript" src="validate.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
<title>My Air - Home</title>
</head>
<body>
<div id="MainPage">
<jsp:include page="header.jsp"></jsp:include>
<div id="mainContent">
<jsp:include page="menubar.jsp"></jsp:include>
<div id="mainContentTop">
<div id="ContentLeft">
<jsp:include page="search.jsp"></jsp:include>
</div>
<div id="contentRight">
<jsp:include page="topdeals.jsp"></jsp:include>
</div>
</div>
</div>
<jsp:include page="footer.jsp"></jsp:include>
</div>
</body>
</html>
Following is my search.jsp:
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>\
<s:form action="searchFlight" theme="css_xhtml" cssClass="form1small" name="searchFlightForm">
<div class="searchHeadersmall">Search Flight</div>
<div id="searchForm1">
<s:actionerror/>
<s:select list="#application.cityList" headerValue="--------Select--------" headerKey="select" name="searchFlightDetails.from" label="Leaving From"></s:select>
<s:select list="#application.destlist" headerValue="---------Select-------" headerKey="select" name="searchFlightDetails.to" label="Going To"></s:select>
<sj:datepicker id="date0" label="Date" name="searchFlightDetails.dateoftravel" readonly="true" minDate="0"/>
<s:select list="#{'1':'1','2':'2','3':'3','4':'4','5':'5'}" headerValue="" headerKey="" name="searchFlightDetails.noofpassengers" label="No of tickets" style="width:50%; float:left"></s:select>
<div class="inputsmall nobottombordersmall">
<s:radio label="Type" name="searchFlightDetails.nonstop"
list="#{'Y':'NonStop','N':'Normal'}"/>
</div>
<div id="submitdivid1">
<sj:submit value="Show Flights" targets="mainContent"/>
</div>
</div>
</s:form>
When form is submitted the following searchFlightSuccess.jsp is loaded in mainContent <div>:
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<s:if test="#session.username!=null">
<jsp:include page="menubaruser.jsp"></jsp:include>
</s:if>
<s:if test="#session.username==null">
<jsp:include page="menubar.jsp"></jsp:include>
</s:if>
<div id="searchHeaderHistory">Search Results</div>
<div class="CSSTableGenerator">
<table>
<colgroup>
<col span="1" style="width: 5%;">
<col span="1" style="width: 10%">
<col span="1" style="width: 15%">
<col span="1" style="width: 10%">
<col span="1" style="width: 15%">
<col span="1" style="width: 15%">
<col span="1" style="width: 15%">
<col span="1" style="width: 5%">
<col span="1" style="width: 10%">
</colgroup>
<thead>
<tr>
<td colspan="9">From:<s:property
value="searchFlightDetails.from" />
To:<s:property value="searchFlightDetails.to" /></td>
</tr>
</thead>
<tbody>
<tr>
<td>Flight ID</td>
<td>Provider</td>
<td>Departure Source</td>
<td>Via</td>
<td>Via Arrival</td>
<td>Via Departure</td>
<td>Destination Arrival</td>
<td>Fare</td>
<td></td>
</tr>
<s:iterator value="searchedFlightsList" var="flights">
<tr>
<td align="center"><s:property
value="#flights.flightDetails.fid" /></td>
<td align="center"><s:property
value="#flights.flightDetails.providerDetails.pname" /></td>
<td align="center"><s:property value="#flights.sourcedepdate" />,<s:property
value="#flights.sourcedeptime" /> hrs</td>
<td align="center"><s:property
value="#flights.flightDetails.routeDetails.via" /></td>
<td align="center"><s:property value="#flights.viaarrdate" />,<s:property
value="#flights.viaarrtime" />hrs</td>
<td align="center"><s:property value="#flights.viadepdate" />,<s:property
value="#flights.viadeptime" />hrs</td>
<td align="center"><s:property value="#flights.destarrdate" />,<s:property
value="#flights.destarrtime" />hrs</td>
<td width="5%" align="center"><s:property
value="#flights.flightDetails.fares2d" /></td>
<td width="5%" align="center">
<s:form
action="passengerDetailsLink" method="get" theme="simple"
id="passengerDetailsLink_%{#flights.sid}">
<s:hidden value="%{#flights.sid}" name="sid" />
<s:hidden value="%{#flights.flightDetails.fares2d}" name="fare" />
<s:hidden value="%{searchFlightDetails.from}" name="from" />
<s:hidden value="%{searchFlightDetails.to}" name="to" />
<s:hidden value="%{searchFlightDetails.noofpassengers}"
name="passengers" />
<s:hidden value="1" name="flag" />
<sj:submit value="Book" targets="mainContent"
cssClass="orangebuttonsmall" />
</s:form></td>
</tr>
</s:iterator>
</tbody>
</table>
</div>
The scenario is as follows:
I entered some values in search.jsp. I submitted the form, and accordingly some results got loaded into the mainContent <div>. Since form was submitted using Struts 2 jQuery plugin submit , the URL remains the same and hence browser back button doesn't work. If I want to go back, how can I do that.
I read about some hash technique but , I am not able to apply it to this.
In the header tag of Struts2 jQuery use ajaxhistory attribute. Setting this attribute to true enabled browser history for Ajax requests. For details see wiki of header tag.

struts 2 jquery plugin not working

I have jsp loginSuccess.jsp as follows:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<html>
<head>
<s:head />
<sj:head />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
<title>Login</title>
</head>
<body>
<div id="MainPage">
<jsp:include page="header.jsp"></jsp:include>
<jsp:include page="menubaruser.jsp"></jsp:include>
<div id="mainContent" >
<div style="width:898px"><br><center>Welcome Mr. <b><s:property value="#session.name"/> </b></center> </div>
<div id="ajaxdiv">
<div id="ContentLeft">
<jsp:include page="search.jsp"></jsp:include>
</div>
<div id="contentRight">
<jsp:include page="topdeals.jsp"></jsp:include>
</div>
</div>
<br>
<div>
<jsp:include page="userHistoryWidget.jsp"></jsp:include>
</div>
</div>
<jsp:include page="footer.jsp"></jsp:include>
</div>
</body>
</html>
This page include many widgets , two of which are search.jsp and userHistoryWidget.jsp. Now when i run this page, everything is fine but the jquery datepicker tag doesn't work.I mean the calender doesn't show up. If i remove the head tag from loginSuccess.jsp, then the datepicker starts working but then the submit button that are coded to send asynchronous request in userHistoryWidget.jsp stops working. They don't respond to clicks.
userHistoryWidget.jsp is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<html>
<head>
<s:head />
<sj:head />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
</head>
<body>
<div id="searchHeaderHistory">User History</div>
<div class="CSSTableGenerator">
<table>
<colgroup>
<col span="1" style="width: 5%;">
<col span="1" style="width: 10%;">
<col span="1" style="width: 8%;">
<col span="1" style="width: 15%;">
<col span="1" style="width: 15%;">
<col span="1" style="width: 6%;">
<col span="1" style="width: 6%;">
<col span="1" style="width: 17%;">
<col span="1" style="width: 18%;">
</colgroup>
<tr>
<td>Ticket ID</td>
<td>Booking Date</td>
<td>Flight ID</td>
<td>From</td>
<td>To</td>
<td>Total Fare</td>
<td>Net Fare</td>
<td></td>
<td></td>
</tr>
<s:iterator value="ticketsList" var="ticket" status="stat">
<tr>
<td align="center"><s:property value="#ticket.tid" /></td>
<td align="center"><s:property value="#ticket.bookingdate" /></td>
<td align="center"><s:property
value="#ticket.scheduleDetails.flightDetails.fid" /></td>
<s:if test="#ticket.flag==3">
<td><s:property
value="#ticket.scheduleDetails.flightDetails.routeDetails.via" /><br>
<s:property value="#ticket.scheduleDetails.via_dep_date" /> <s:property
value="#ticket.scheduleDetails.via_dep_time" />hrs</td>
</s:if>
<s:if test="#ticket.flag==1 ||#ticket.flag==2||#ticket.flag==4">
<td><s:property
value="#ticket.scheduleDetails.flightDetails.routeDetails.source" /><br>
<s:property value="#ticket.scheduleDetails.source_dep_date" /> <s:property
value="#ticket.scheduleDetails.source_dep_time" />hrs</td>
</s:if>
<s:if test="#ticket.flag==1 ||#ticket.flag==2||#ticket.flag==3">
<td><s:property
value="#ticket.scheduleDetails.flightDetails.routeDetails.destination" /><br>
<s:property value="#ticket.scheduleDetails.dest_arr_date" /> <s:property
value="#ticket.scheduleDetails.dest_arr_time" />hrs</td>
</s:if>
<s:if test="#ticket.flag==4">
<td><s:property
value="#ticket.scheduleDetails.flightDetails.routeDetails.via" /><br>
<s:property value="#ticket.scheduleDetails.via_arr_date" /> <s:property
value="#ticket.scheduleDetails.via_arr_time" />hrs</td>
</s:if>
<td align="center"><s:property value="#ticket.fare" /></td>
<td align="center"><s:property value="#ticket.dealFare" /></td>
<td style="width: 150px" align="center">
<s:url id="getPassengers" value="/getPassengers.action">
<s:param name="Tid" value="#ticket.tid" />
</s:url>
<sj:a id="link_%{#stat.index}" href="%{getPassengers}" targets="ajaxdiv" cssClass="orangebuttonsmall">
View Details
</sj:a>
</td>
<td style="width: 150px" align="center">
<s:a action="cancel" id="button1" style="float:left" cssClass="orangebuttonsmall">Cancel Ticket
<s:param name="Tid" value="#ticket.tid"></s:param>
</s:a>
</td>
</tr>
</s:iterator>
</table>
</div>
</body>
</html>
search.jsp is as follows:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<html>
<head>
<s:head />
<sj:head />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="style.css" media="all" />
<link rel="stylesheet"
href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
$("#datepicker").datepicker();
});
</script>
<title>Search</title>
</head>
<body>
<s:form action="searchFlight" method="post" theme="css_xhtml" cssClass="form1small">
<div class="searchHeadersmall">Search Flight</div>
<div id="searchForm1">
<s:select list="cityList" headerValue="--------Select--------" headerKey="-1"
name="searchFlightDetails.from" label="Leaving From"></s:select>
<s:select list="destlist" headerValue="---------Select-------" headerKey="-1"
name="searchFlightDetails.to" label="Going To"></s:select>
<s:textfield label="Date" name="searchFlightDetails.date_of_travel"
id="datepicker" />
<s:select list="#{'1':'1','2':'2','3':'3','4':'4','5':'5'}"
headerValue="" headerKey="-1"
name="searchFlightDetails.no_of_passengers" label="No of tickets"
style="width:50%; float:left"></s:select>
<div class="inputsmall nobottombordersmall">
Type
<s:radio label="Type" name="searchFlightDetails.nonstop"
list="#{'Y':'NonStop','N':'Normal'}" theme="simple" />
</div>
<div id="submitdivid1">
<sj:submit id="submitsearch" value="Show Flights" targets="mainContent"/>
</div>
</div>
</s:form>
</body>
</html>
Can somebody help me solve this problem? Thanks in advance..
If your intention is just to include the JSPs in other pages to form a complete page, then I suggest remove the repeated part (html, head, body & other similar tags) and contain only specific part, so that the resulting html contains only ONE html, head & body tag.
Secondly, sj plugin requires <sj:head jqueryui="true"/> for the UI components to work. Looking at your code, it appears the the parent page is loginSuccess.jsp & hence, it's <head> should contain this sj:head definition.
Try removing the redundant code and hopefully, it should work.

Categories