I work with Spring MVC and JSP. I want to input the class product using a form. Class Product has another object Catalog
Product class
public class Product {
private int productId;
private Catalog catalog;
private String sku;
private String productName;
private int availableQuantity;
private String uom;
public Product() {
}
Catalog is
public class Catalog {
protected static Logger logger = Logger.getLogger(Catalog.class.getName());
private int catalogId;
private String catalogName;
private List<Product> products= new ArrayList<Product>();
public Catalog() {
}
I created a modelAttribute product in the controller
model.addAttribute(new Product());
return "product/addProduct";
I want to input the catalog id using a dropdown. This dropdown is
<tr>
<th><label for="catalog_id">Catalog id:</label></th>
<td><sf:select path="catalog" items="${catalogList}" />
</td>
</tr>
The jsp is:
<sf:form method="POST" modelAttribute="product">
<table border="0">
<tr>
<th><label for="catalog_id">Catalog id:</label></th>
<td><sf:select path="catalog" items="${catalogList}" />
</td>
</tr>
<tr>
<th><label for="product_name">Product Name:</label></th>
<td><sf:input path="productName" size="128" id="product_name" /><br/>
<sf:errors path="productName" cssClass="error" />
</td>
</tr>
<tr>
<th><label for="product_sku">Product sku:</label></th>
<td><sf:input path="sku" size="32" id="product_sku" /><br/>
<sf:errors path="sku" cssClass="error" />
</td>
</tr>
<tr>
<th><label for="product_availablequantity">Available Quantity:</label></th>
<td><sf:input path="availableQuantity" id="product_availablequantity" /><br/>
<sf:errors path="availableQuantity" cssClass="error" />
</td>
</tr>
<tr>
<th><label for="product_unitofmeasure">Unit of measure:</label></th>
<td><sf:input path="uom" size="32" id="product_unitofmeasure" /><br/>
<sf:errors path="uom" cssClass="error" />
</td>
</tr>
<tr>
<th></th>
<td><input type="submit" value="Save" /></td>
</tr>
</table>
</sf:form>
</body>
</html>
How do I have to define the path product.catalog.catalogId?
Related
Let's say I have rendered the output rom the get request on an html template, now I need to use this same data to pass to a post request via a button on a same page. How do I do that?
I'm trying to do something like this:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Customer Home</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div th:replace="fragments/header :: header">
</div>
<div class="container">
<p> Thanks for booking with Gamma Airlines, here are your booking summary: </p>
<table th:object="${booking} class="table table-bordered table-striped">
<tbody>
<tr>
<td>Source</td>
<td th:text="${routeStart}"></td>
</tr>
<tr>
<td>Destination</td>
<td th:text="${routeDestination}"></td>
</tr>
<tr>
<td>Booking Charges</td>
<td th:text="${bookingCharges}"></td>
</tr>
<tr>
<td>Booking Charges Currency</td>
<td th:text="${chargesCurrency}"></td>
</tr>
<tr>
<td>Booking Date</td>
<td th:text="${#calendars.format(bookingDate)}">July 11, 2012 2:17:16 PM CDT</td>
<tr>
<td>
<div class="col-sm-9">
<form action="#" th:action="#{/email}"
th:object="${booking}" method="post"
role="form">
<button type="submit" class="btn btn-primary btn-block">Email</button>
</form>
</div>
</td>
<td>
<div class="col-sm-9">
<form action="#" th:action="#{/genpdf}"
th:object="${booking}" method="post"
role="form">
<button type="submit" class="btn btn-primary btn-block">Generate PDF</button>
</form>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
Edit: Somebody please help tell me a simple method to pass the object since I have to use it at many places and object contains many child object as well in some cases. eg. the following case:
<div style = "margin-top: 2cm" class="container">
<table class="table table-bordered table-striped">
<thead>
<tr>
<td>Source</td>
<td>Destination</td>
<td>Amount</td>
<td>Currency</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<tr th:if="${offers.empty}">
<td colspan="5">No Offers</td>
</tr>
<tr th:each="offer : ${offers}">
<td th:text="${offer.route.from}"></td>
<td th:text="${offer.route.to}"></td>
<td th:text="${offer.price.amount}"></td>
<td th:text="${offer.price.currency}"></td>
<td>
<form action="#" th:action="#{/user/booking}"
th:object="${offer}" method="post"
role="form">
<button type="submit" class="btn btn-primary btn-block">Book</button>
</form>
</td>
</tr>
</tbody>
</table>
</div>
UPDATE 2:
I even changed the template by sending a new object in the get request and try to assign values one by one but I still get it as null in a controller.
<table class="table table-bordered table-striped">
<thead>
<tr>
<td>Source</td>
<td>Destination</td>
<td>Amount</td>
<td>Currency</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<tr th:if="${offers.empty}">
<td colspan="5">No Offers</td>
</tr>
<tr th:each="offer : ${offers}">
<td th:text="${offer.route.from}"></td>
<td th:text="${offer.route.to}"></td>
<td th:text="${offer.price.amount}"></td>
<td th:text="${offer.price.currency}"></td>
<td>
<form action="#" th:action="#{/user/booking}"
th:object="${booking}" method="post"
role="form">
<input type="hidden" th:attr="value = ${offer.route.from}" th:field="*{routeStart}" />
<input type="hidden" th:attr="value = ${offer.route.to}" th:field="*{routeDestination}" />
<input type="hidden" th:attr="value = ${offer.price.amount}" th:field="*{bookingCharges}" />
<input type="hidden" th:attr="value = ${offer.price.currency}" th:field="*{chargesCurrency}" />
<button type="submit" class="btn btn-primary btn-block">Book</button>
</form>
</td>
</tr>
</tbody>
</table>
These are my get and post methods:
#RequestMapping(value="/user/booking", method = RequestMethod.GET)
public ModelAndView getOffers()
{
ModelAndView modelAndView = new ModelAndView();
AirlineOffer[] offersArray= airlineClient.getOffers();
List<AirlineOffer> offers = Arrays.asList(offersArray);
modelAndView.addObject("offers", offers);
Booking booking = new Booking();
modelAndView.addObject("booking", booking);
modelAndView.setViewName("user/booking");
return modelAndView;
}
/** POST method for submitting deposit request */
#RequestMapping(value = "/user/booking", method = RequestMethod.POST)
public ModelAndView book(#Valid Booking booking,
BindingResult bindingResult, HttpServletRequest request)
{
ModelAndView modelAndView = new ModelAndView();
......
}
Alright, I finally resolved it using the following in my form:
<table class="table table-bordered table-striped">
<thead>
<tr>
<td>Source</td>
<td>Destination</td>
<td>Amount</td>
<td>Currency</td>
<td>Action</td>
</tr>
</thead>
<tbody>
<tr th:if="${offers.empty}">
<td colspan="5">No Offers</td>
</tr>
<tr th:each="offer, stat : ${offers}">
<td th:text="${offer.route.from}"></td>
<td th:text="${offer.route.to}"></td>
<td th:text="${offer.price.amount}"></td>
<td th:text="${offer.price.currency}"></td>
<td>
<form action="#" th:action="#{/user/booking}"
th:object="${booking}" method="post"
role="form">
<input type="hidden" th:value="${offer.route.from}" name="routeStart" />
<input type="hidden" th:value = "${offer.route.to}" name="routeDestination" />
<input type="hidden" th:value = "${offer.price.amount}" name="bookingCharges" />
<input type="hidden" th:value = "${offer.price.currency}" name="chargesCurrency" />
<button type="submit" class="btn btn-primary btn-block">Book</button>
</form>
</td>
</tr>
</tbody>
All it took was to remove th:field and add the name attribute.
Maybe this question was asked a lot but not in the same way so here is my problem and I hope someone can help.
After having retrieved some research rows from database and returned the results into a List which I have bound to the my Spring MVC Controller Model:
if(!result.hasErrors())
{
try{
List<Question> questionlist = questionservice.findByCategoryAndLevel(questionform.getCategory(),questionform.getLevel());
model.addAttribute("questionlist",questionlist);
return "addExam";
}catch(NullPointerException e)
{
return "redirect:/admin/addexam";
}
}
Here is my view:
<form:form action="addexam" method="POST" modelAttribute="questionlist">
<table class="table table-striped table-bordered table-hover" id="sample_1">
<thead>
<tr>
<th class="table-checkbox">
<input type="checkbox" class="group-checkable" data-set="#sample_1 .checkboxes"/>
</th>
<th>
Category
</th>
<th>
level
</th>
<th>
Type of question
</th>
<th>
Status
</th>
<th>
</th>
</tr>
</thead>
<tbody>
<c:forEach items="${questionlist}" var="question">
<c:choose>
<c:when test="${question.isVisible()}">
<tr class="odd gradeX">
<td>
<input type="checkbox" class="checkboxes" />
</td>
<td>
${question.category.getCategoryName() }
</td>
<td>
${question.level }
</td>
<c:choose>
<c:when test="${question.isSingleChoiceQuestion() }">
<td>Question à choix unique</td>
</c:when>
<c:otherwise>
<td>Question à choix mutiple</td>
</c:otherwise>
</c:choose>
<td class="center">
<c:choose>
<c:when test="${question.getState() == 'Desactivated'}">
<span class="label label-sm label-default"> Desactivated </span>
</c:when>
<c:when test="${question.getState() == 'Activated'}">
<span class="label label-sm label-success"> Activated </span>
</c:when>
<c:when test="${question.getState() == 'Pending'}">
<span class="label label-sm label-warning"> Pending </span>
</c:when>
</c:choose>
</td>
<td>
View
</td>
</tr>
</c:when>
</c:choose>
</c:forEach>
</tbody>
</table>
</form:form>
Now how do I submit the selected items?
yes i wanted to display the question list and then pick the ones i needed via a checkbox
i created a form, it holds the list of Idquestions
public class checkedquestion {
private List<Long> listIdQuestion ;
//getter & setter
}
then added a path attribute to checkbox like below :
<form:form action="submit" method="POST" modelAttribute="checkedquestion">
// .......
<td>
<form:checkbox value="${question.idQuestion}" path="listIdQuestion"/>
</td>
By submitting the list of id i have the ones i needed :
public String add(#ModelAttribute ("checkedquestion") #Valid CheckedQuestion checkedquestion , BindingResult result )
{
if(!result.hasErrors())
{
List<Long> list = checkedquestion.getListIdQuestion();
List<Question> questionlist = questionservice.getQuestion(list);
}
}
it seems to work fine
Give a id/name to input checkbox type as below
<input type="checkbox" class="checkboxes" id="someId" name="someId" value="uniqueValueToEachCheckBox"/>
Then after submitting your form, you can able to access your selected checkbox values in your controller as below.
request.getParameterValues("someId");
I'm really new to Spring MVC framework and I'm in desperate need of help right now.
For some reason, my redirect does not work its giving me HTTP Status 400, with no error on console that is why it is very hard to debug.
Scenario:
I have 2 forms. The first form is saving properly then redirects to 2nd form, but when I repeat my code to pass it to the 3rd form I get an http 400 error. I'm pretty sure I replicated what I used on the first form.
View:
<form:form method="POST" commandName="kiosk"
action="${pageContext.request.contextPath}/kiosk/kiosk-initial-info-save.html">
<div align="center">
<br />
<div id="addKioskContainer">
<div class="datagrid1" align="center" style="width: 33%;">
<table align="center">
<thead>
<tr>
<th colspan="4" style="text-align: left;">Initial Information</th>
</tr>
</thead>
</table>
</div>
<div>
<table>
<tr>
<td>
<h3 align="left"> You are applying for <label style="color: blue;">Restructured Loan</label> in <label style="color: blue;">Eastwood.</label></h3>
</td>
</tr>
</table>
</div>
<div id="initialInfoContainer">
<table cellpadding="0" cellspacing="10">
<tr>
<td style="font-size: 12px;" >
<b>Purpose of Loan: </b>
</td>
<td>
<form:input path="loanPurpose" size="40"></form:input>
</td>
</tr>
</table>
</div>
<br />
<div id="applicantInfoContainer">
<div class="datagrid2" align="center" style="width: 95%;">
<table align="center">
<thead>
<tr>
<th colspan="4" style="text-align: left;">Applicant's Information</th>
</tr>
</thead>
<tr>
<td style="font-size: 12px;" >
<b>Last Name: </b><label style="color: red;">*</label>
</td>
<td>
<form:input path="appLastName" size="40"></form:input>
</td>
</tr>
<tr>
<td style="font-size: 12px;" >
<b>First Name: </b><label style="color: red;">*</label>
</td>
<td>
<form:input path="appFirstName" size="40"></form:input>
</td>
</tr>
<tr>
<td style="font-size: 12px;" >
<b>Middle Name: </b><label style="color: red;">*</label>
</td>
<td>
<form:input path="appMiddleName" size="40"></form:input>
</td>
</tr>
<tr>
<td style="font-size: 12px;" >
<b>Birthdate: </b><label style="color: red;">*</label>
</td>
<td>
<form:input path="appBirthDate" size="20"></form:input>
</td>
</tr>
<tr>
<td style="font-size: 12px;" >
<b>w/ Comaker: </b><label style="color: red;">*</label>
</td>
<td>
<form:checkbox path="withCoMaker"></form:checkbox>
</td>
</tr>
</table>
</div>
</div>
<br />
<div id="comakerInfoContainer">
<div class="datagrid2" align="center" style="width: 95%;">
<table align="center">
<thead>
<tr>
<th colspan="4" style="text-align: left;">Comaker's Information</th>
</tr>
</thead>
<tr>
<td style="font-size: 12px;" >
<b>Last Name: </b><label style="color: red;">*</label>
</td>
<td>
<form:input path="comakerLastName" size="40"></form:input>
</td>
</tr>
<tr>
<td style="font-size: 12px;" >
<b>First Name: </b><label style="color: red;">*</label>
</td>
<td>
<form:input path="comakerFirstName" size="40"></form:input>
</td>
</tr>
<tr>
<td style="font-size: 12px;" >
<b>Middle Name: </b><label style="color: red;">*</label>
</td>
<td>
<form:input path="comakerMiddleName" size="40"></form:input>
</td>
</tr>
<tr>
<td style="font-size: 12px;" >
<b>Birthdate: </b><label style="color: red;">*</label>
</td>
<td>
<form:input path="comakerBirthDate" size="20"></form:input>
</td>
</tr>
</table>
</div>
</div>
<br />
<div align="center">
<table>
<tr>
<td align="center"><input type="submit" value="Next" id="btnProceedKiosk"/></td>
<td></td>
</tr>
</table>
</div>
</div>
</div>
Controller:
#RequestMapping( value = "/kiosk-initial-info", method = RequestMethod.GET )
public ModelAndView initialInfoKioskPage()
{
ModelAndView modelAndView = new ModelAndView( "kiosk-initial-info" );
modelAndView.addObject( "kiosk", new Kiosk() );
return modelAndView;
}
#RequestMapping( value = "/kiosk-initial-info-save", method = RequestMethod.POST )
public ModelAndView saveInitialInfo( #ModelAttribute
Kiosk kiosk )
{
ModelAndView modelAndView = new ModelAndView( "kiosk-initial-info" );
modelAndView.addObject( "kiosk", new Kiosk() );
return new ModelAndView( "redirect:/kiosk/kiosk-initial-info.html" );
}
Model:
package com.etel.kiosk.model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table( name = "kioskmain" )
public class Kiosk
{
#Id
#GeneratedValue
private Integer id;
private String loanType;
private String branch;
private String loanPurpose;
private String appLastName;
private String appFirstName;
private String appMiddleName;
private Date appBirthDate;
private Boolean withCoMaker;
private String comakerLastName;
private String comakerFirstName;
private String comakerMiddleName;
private Date comakerBirthDate;
public Integer getId()
{
return id;
}
public void setId( Integer id )
{
this.id = id;
}
public String getLoanType()
{
return loanType;
}
public void setLoanType( String loanType )
{
this.loanType = loanType;
}
public String getBranch()
{
return branch;
}
public void setBranch( String branch )
{
this.branch = branch;
}
public String getLoanPurpose()
{
return loanPurpose;
}
public void setLoanPurpose( String loanPurpose )
{
this.loanPurpose = loanPurpose;
}
public String getAppLastName()
{
return appLastName;
}
public void setAppLastName( String appLastName )
{
this.appLastName = appLastName;
}
public String getAppFirstName()
{
return appFirstName;
}
public void setAppFirstName( String appFirstName )
{
this.appFirstName = appFirstName;
}
public String getAppMiddleName()
{
return appMiddleName;
}
public void setAppMiddleName( String appMiddleName )
{
this.appMiddleName = appMiddleName;
}
public Date getAppBirthDate()
{
return appBirthDate;
}
public void setAppBirthDate( Date appBirthDate )
{
this.appBirthDate = appBirthDate;
}
public Boolean getWithCoMaker()
{
return withCoMaker;
}
public void setWithCoMaker( Boolean withCoMaker )
{
this.withCoMaker = withCoMaker;
}
public String getComakerLastName()
{
return comakerLastName;
}
public void setComakerLastName( String comakerLastName )
{
this.comakerLastName = comakerLastName;
}
public String getComakerFirstName()
{
return comakerFirstName;
}
public void setComakerFirstName( String comakerFirstName )
{
this.comakerFirstName = comakerFirstName;
}
public String getComakerMiddleName()
{
return comakerMiddleName;
}
public void setComakerMiddleName( String comakerMiddleName )
{
this.comakerMiddleName = comakerMiddleName;
}
public Date getComakerBirthDate()
{
return comakerBirthDate;
}
public void setComakerBirthDate( Date comakerBirthDate )
{
this.comakerBirthDate = comakerBirthDate;
}
}
DaoImpl
public void updateKiosk( Kiosk kiosk )
{
Kiosk kioskToUpdate = getKiosk( kiosk.getId() );
kioskToUpdate.setBranch( kiosk.getBranch() );
kioskToUpdate.setLoanPurpose( kiosk.getLoanPurpose() );
kioskToUpdate.setAppLastName( kiosk.getAppLastName() );
kioskToUpdate.setAppFirstName( kiosk.getAppFirstName() );
kioskToUpdate.setAppMiddleName( kiosk.getAppMiddleName() );
kioskToUpdate.setAppBirthDate( kiosk.getAppBirthDate() );
kioskToUpdate.setWithCoMaker( kiosk.getWithCoMaker() );
kioskToUpdate.setComakerLastName( kiosk.getComakerLastName() );
kioskToUpdate.setComakerFirstName( kiosk.getComakerFirstName() );
kioskToUpdate.setComakerMiddleName( kiosk.getComakerMiddleName() );
kioskToUpdate.setComakerBirthDate( kiosk.getComakerBirthDate() );
getCurrentSession().update( kioskToUpdate );
}
Your answers will be of great help. Thanks.
I'm trying to create simple add/remove form using annotation based Spring MVC.
'Add' functionality comes smoothly, but when I tried to add another button to form i've got stuck.
Here is my code:
Controller actions:
#RequestMapping(value = "/books/documentType.do", method = RequestMethod.GET)
public String getDocType(
#RequestParam(required = false, value = "id") Long id,
ModelMap model) {
DocTypeDTO docType = new DocTypeDTO();
if (id != null)
docType = docTypeConverter.getDTO(id);
model.addAttribute("docType", docType);
return "/books/documentType";
}
#RequestMapping(value = "/books/documentType.do", method = RequestMethod.POST)
public String setDocType(
#ModelAttribute("docType") DocTypeDTO docType,
BindingResult result,
SessionStatus sessionStatus
) {
docTypeValidator.validate(docType, result);
if (result.hasErrors())
return "/books/documentType";
else {
docTypeConverter.saveDTO(docType);
sessionStatus.setComplete();
return "redirect:/books/documentTypes.do";
}
}
Awfully markuped form:
<form:form method="post" commandName="docType" id="editForm">
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#dbdbdb">
<tr>
<td></td>
<td>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td class="spacer"><img src="/images/spacer.gif" width="116" height="1" border="0"/></td>
<td class="spacer"><img src="/images/spacer.gif" width="216" height="1" border="0"/></td>
</tr>
<tr>
<td class="form-cell-text-underlined">Отображать на сайте</td>
<td colspan="2">
<form:checkbox path="shownOnSite"/>
</td>
</tr>
<tr>
<td class="form-cell-text-underlined">Международный</td>
<td colspan="2">
<form:checkbox path="international"/>
</td>
</tr>
<tr>
<td class="form-cell-text-underlined">Внутренний код</td>
<td colspan="2">
<form:input path="internalCode"/>
</td>
</tr>
<tr>
<td class="form-cell-text-underlined">Код</td>
<td colspan="2">
<form:input path="code"/>
<form:errors path="code"/>
</td>
</tr>
<tr>
<td class="form-cell-text-underlined">Код IATA</td>
<td colspan="2">
<form:input path="codeIATA"/>
</td>
</tr>
<tr>
<td class="padded-underlined">Название</td>
<td colspan="2">
<form:input path="name"/>
<form:errors path="name"/>
</td>
</tr>
<tr>
<td class="padded-underlined">Название(Англ.)</td>
<td colspan="2">
<form:input path="nameEn"/>
</td>
</tr>
<tr>
<td colspan="3">
<input type="submit" value="Сохранить">
</td>
</tr>
</table>
</td>
<td></td>
</tr>
</table>
Thanks!
With Spring MVC 3, this is reasonably straight-forward to do with just JSP and Controller. For example, these two submit buttons handle 'previous' and 'save' actions:
<input value="Save" name="save" type="submit" id="btnSave" class="submit_button">
<input value="Previous" name="previous" type="submit" id="btnPrevious" class="submit_button">
Then, in the controller, you accept the input name as a param in the request mapping, along with the controller 'address':
#RequestMapping(value="thisForm.form", params="save")
public String save() {
// save
}
#RequestMapping(value="thisForm.form", params="previous")
public String doPreviousStuff() {
// get mapping for previous page and return
}
If you really want two submit buttons on your form, you can do it with Javascript like this (using jQuery in this example):
<SCRIPT language=JavaScript>
function remove() {
$('#editForm').attr("action", "documentTypeRemove.do");
$("#editForm").submit();
}
</SCRIPT>
...
<button type="button" onclick="remove();">Remove</button>
Then create another RequestMapping in your controller:
#RequestMapping(value = "/books/documentTypeRemove.do", method = RequestMethod.POST)
public String removeDocType(...
I am new to struts 2. I am facing problem in filling Select tag with list property. The values are supplied from action class.Please provide me sample sode for this scenario.
My action class
public class TripDetailsAdd extends ActionSupport {
#Override
public String execute() throws Exception {
return SUCCESS;
}
public String populate() {
VehicleDAO vehicleDAO = new VehicleDAO();
this.lstVehicles.addAll(vehicleDAO.getAllVehicles());
return "populate";
}
private String vehicleId;
private Collection lstVehicles = new ArrayList<VehiclesVO>();
}
Jsp page content:
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sform" uri="/struts-dojo-tags"%>
<%# 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">
<%#page import="com.vms.business.dao.VehicleDAO"%>
<%#page import="java.util.Collection"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Trip Details</title>
</head>
<body>
<s:form action="tripDetailsAdd" method="POST" >
<s:hidden name="expenseTypeId"></s:hidden>
<table width="100%" height="96%" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><!-- Menu Starts --> <jsp:include
page="/pages/menu.jsp"></jsp:include> <!-- Menu End -->
<table width="95%" align="center">
<tr>
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="highlight">Trip Details Add</td>
<td><s:actionerror /><s:actionmessage /></td>
</tr>
<tr>
<td class="header3shadow" colspan="2"><img height="2"
border="0" width="100%"></img></td>
</tr>
</table>
<table>
<tr>
<td> </td>
</tr>
</table>
<div
style="overflow: auto; height: expression((document.body.clientHeight -80) +px ');">
<table width="60%" cellspacing="0" cellpadding="0" border='0'>
<tr>
<td class="FieldTitle" valign="top">
<table width="100%" cellspacing="4" cellpadding="0" border='0'>
<s:select headerKey="0" headerValue="Select One" required="*" label="Vehicle No."
labelSeparator=":" list="lstVehicles" listKey="vehicleId" listValue="regNo"></s:select>
</td>
</tr>
<tr>
<td>
<table width="100%" cellspacing="4" cellpadding="0" border='0'>
<s:textfield labelposition="left" requiredposition="right"
name="totalIncome" label="Total Income" cssStyle="FieldTitle"
labelSeparator=":"></s:textfield>
</table>
</td>
</tr>
</table>
<table cellpadding="0" width="60%" cellspacing="0" border="0">
<tr>
<td align="right"><s:submit label="Add" value="Add"></s:submit></td>
</tr>
</table>
</div>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</s:form>
</body>
</html>
Mapping
<action name="*TripDetailsAdd" method="{1}"
class="com.vms.trip.presentation.TripDetailsAdd">
<result name="success" type="redirect">showTripDetailsList
</result>
<result name="populate">/pages/tripdetails/TripDetailsAdd.jsp
</result>
<result name="error">/pages/tripdetails/TripDetailsAdd.jsp
</result>
<result name="input">/pages/tripdetails/TripDetailsAdd.jsp
</result>
</action>
In this if i add Validation file or If any error occurs in page drop down is not loading.Please help me..
Struts2 select tag
<s:select label="Pets"
name="petIds"
list="petDao.pets"
listKey="id"
listValue="name"
value="%{petDao.pets.{id}}"
/>
In the above. value = default selection, list = collection (of Map) coming from your action class, listKey = Key for map, listValue = value for map.
Edit (after looking at provided code):
your problem is that you do not have any getter in action class that corresponds with lstVehicles (which is mentioned in list property of your select tag)
Add this to your action class:
public List getLstVehicles ()
{
return this.lstVehicles;
}