Not sure what I'm doing wrong on this one. Attempting to make a button that can delete added entities from database. I'm getting a 405 error but I am not sure if I'm getting this because of something I'm doing in the controller or something badly I wrote in thymeleaf. Thanks for any help.
Controller:
#Controller
public class BuyerController {
private BuyerService buyerService;
#Autowired
public void setBuyerService(BuyerService buyerService){
this.buyerService = buyerService;
}
#RequestMapping("/add-buyer")
public String showBuyerPager(Model model){
List<Buyer> buyers = buyerService.findAllBuyers();
model.addAttribute("buyers", buyers);
model.addAttribute("buyer", new Buyer());
return "add-buyer";
}
#GetMapping("/showBuyerForm")
public String addBuyerForm(Model model){
model.addAttribute("buyer", new Buyer());
model.addAttribute("buyerId", new Buyer().getBuyerId());
return "add-buyer";
}
#PostMapping("/addBuyer")
public String postBuyerForm(#ModelAttribute("buyer") Buyer buyer, Model model){
buyerService.saveBuyer(buyer);
model.addAttribute("buyer", new Buyer());
return "redirect:/";
}
#GetMapping("/deleteBuyer")
public String deleteBuyer(#RequestParam("buyerid") Long id){
buyerService.deleteBuyer(id);
return "redirect:/";
}
}
View:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Title</title>
<link href="styles.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<header> Welcome to Toner Stock </header>
<h1>Add Buyer</h1>
<div id="mynav" align="center">
<ul>
<li>Home</li>
<li>Add Buyer</li>
<li>Add Manager</li>
<li>Current Stock</li>
<li>Transactions</li>
<li>Order Form</li>
</ul>
</div>
<div id="display-table" align="center">
<form th:action="#{/addBuyer}" th:object="${buyer}" style="width:100%" method="post">
<table>
<td><label>First Name: </label></td>
<td><input type="text" th:field="*{firstName}"/></td>
<td><label>Last Name: </label></td>
<td><input type="text" th:field="*{lastName}"/></td>
<td><label>Enter Address: </label></td>
<td><input type="text" th:field="*{buyerAddress}"/></td>
<td><input type="submit" value="save"/></td>
</table>
</form>
</div>
<div>
<div>
<table id="info-table" align="center" border="1">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Address</th>
</tr>
<tr th:each="buyer : ${buyers}">
<td th:text="${buyer.firstName}"></td>
<td th:text="${buyer.lastName}"></td>
<td th:text="${buyer.buyerAddress}"></td>
<td>
<form th:action="#{/deleteBuyer}" th:object="${buyer}" method="post">
<input type="hidden" name="buyerid" id="buyerid" value="${buyer.buyerId}"/>
<input type="submit" value="Delete" onClick="return confirm('sure?')"/>
</form>
</td>
</tr>
</table>
</div>
</div>
<div>
<select>
<option th:each="buyer : ${buyers}"
th:text="${buyer.firstName}"
th:value="${buyer.buyerId}"
></option>
</select>
</div>
<div>
<div>
</div>
</div>
</body>
</html>
I don't know much about Thymeleaf but you can keep it simpler and change your front-end code from form to basic link :
<c:url var="deleteBuyer" value="/DeleteBuyer">
<c:param name="buyerId" value="${buyer.buyerId}" />
</c:url>
<a class="simpleLink" href="${deleteBuyer}">delete</a>
And handle it in your controller :
` #GetMapping("/DeleteBuyer")
public String deleteAnswer(#RequestParam("buyerId") int theId) {
buyerService.deleteBuyer(theId);
return "redirect:/";
}`
I hope this help you.
Change the
<form th:action="#{/deleteBuyer}" th:object="${buyer}" method="post">
To GET to conform with the Spring request mapping
<form th:action="#{/deleteBuyer}" th:object="${buyer}" method="get">
Here are all available HTTP Methods
Related
I have a view in which I have a Form to create a new Exercise object, and a table to display all exercises. Now I want that the table automatically refreshes with the newly created exercise. Currently it displays the table as empty, until I manually go to localhost:8080/exercise again.
Here's my controller:
#Controller
public class ExerciseController {
#Autowired
private ExerciseService exerciseService;
#Autowired
private ModelMapper modelMapper;
#GetMapping("/exercise")
public String exerciseView(final Model model) {
List<Exercise> exerciseList = exerciseService.getAllExercises();
model.addAttribute("exerciseDTO", new ExerciseDTO());
model.addAttribute("title", "Create an Exercise");
model.addAttribute("exercises", exerciseList);
return "exercise";
}
#PostMapping("/exercise")
public String createExercise(#ModelAttribute final ExerciseDTO exerciseDto) {
final Exercise exercise = this.modelMapper.map(exerciseDto, Exercise.class);
this.exerciseService.createExercise(exercise);
return "exercise";
}
}
And my thymeleaf template:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="template :: head"></head>
<body>
<header th:replace="template :: navbar"></header>
<h1>Form</h1>
<form action="#" th:action="#{/exercise}" th:object="${exerciseDTO}" method="post">
<p>Name: <input type="text" th:field="*{name}" /></p>
<p>Description: <input type="text" th:field="*{description}" /></p>
<p>Exercise type:
<select th:field="*{type}" id="typeSelector">
<option th:each="type : ${T(com.nsterdt.routinierbackend.data.enums.ExerciseType).values()}"
th:value="${type}" th:text="${type.displayName}">
</option>
</select>
</p>
<p id="bpmRow">BPM: <input type="number" th:field="*{bpm}" id="bpmInput" /></p>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>
<br>
<table>
<tr>
<th>Name</th>
<th>Description</th>
<th>Type</th>
<th>BPM</th>
</tr>
<tr th:each="exercise : ${exercises}">
<td th:text="${exercise.name}"></td>
<td th:text="${exercise.description}"></td>
<td th:text="${exercise.type}"></td>
<td th:text="${exercise.bpm}"></td>
</tr>
</table>
</body>
</html>
Now I thought the createExercise method returning "exercise" would call the exerciseView method and thus calling exerciseService.getAllExercises(). Is there a way to achieve this functionality? Or is there an even better way, without reloading the whole page?
To serve up data without page refreshes you'd need a client side technology like Angular or React. Or plain old javascript. But you can't serve up new data to a page in spring mvc w/o page refreshes.
You can use AJAX to send requests from a client side to a server side and receive an answer without refreshing the page.
Unfortunately I don't have enough time and I can't complete the code but you can do something like this:
function submitItems() {
var contextPath = $("meta[name='ctx']").attr("content");
var exerciseDto = {};
exerciseDto.name = $("#name").val();
exerciseDto.description = $("#description").val();
exerciseDto.typeSelector = $("#typeSelector).val();
exerciseDto.bpmInput = $("#bpmInput").val();
$.ajax({
dataType : "json",
type : "post",
url : contextPath + "/exercise",
data : JSON.stringify(exerciseDto),
cache : false,
contentType : "application/json",
beforeSend : function(xhr) {
xhr.setRequestHeader(header, token);
},
success : function(data) {
console.log(data);
//HERE YOU NEED ACTION TO UPDATE TABLE.
},
error : function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR.responseText);
console.log('getJSON request failed! ' + textStatus);
}
});
}
and then your view must be like this:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="template :: head"></head>
<body>
<header th:replace="template :: navbar"></header>
<h1>Form</h1>
<form onsubmit="submitItems();return false;">
<p>Name: <input id="name" type="text" /></p>
<p>Description: <input id="description" type="text" /></p>
<p>Exercise type:
<select th:field="*{type}" id="typeSelector">
<option th:each="type : ${T(com.nsterdt.routinierbackend.data.enums.ExerciseType).values()}"
th:value="${type}" th:text="${type.displayName}">
</option>
</select>
</p>
<p id="bpmRow">BPM: <input type="number" id="bpmInput" /></p>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>
<br>
<table>
<tr>
<th>Name</th>
<th>Description</th>
<th>Type</th>
<th>BPM</th>
</tr>
<tr th:each="exercise : ${exercises}">
<td th:text="${exercise.name}"></td>
<td th:text="${exercise.description}"></td>
<td th:text="${exercise.type}"></td>
<td th:text="${exercise.bpm}"></td>
</tr>
</table>
</body>
</html>
Bear in mind that you need to create an JS action that will update the table. There are quite a few ways of doing that (you can push new data to the Datatable or add new content using JS functions).
I hope this will help you understand a bit more how the AJAX works.
PS. You will have to update your controller as well to return the results, in your instance will be
#PostMapping("/exercise")
public createExerciseDomainTYPEHERE createExercise(#RequestBody final ExerciseDTO exerciseDto) {
final Exercise exercise = this.modelMapper.map(exerciseDto, Exercise.class);
//this.exerciseService.createExercise(exercise);
//return "exercise";
return this.exerciseService.createExercise(exercise);
}
You will have to change this line
public createExerciseDomainTYPEHERE createExercise(#RequestBody final ExerciseDTO exerciseDto) {
to your createExercise Domain Type.
Need some advice how should I retrieve a list of exhibits.
In my html template below, I only put one record of exhibit. If i were to put additional rows/records of exhibit, how do i go about mapping them to the controller.
HTML Template
<h3>Exhibit Details</h3>
<div class="table-responsive">
<table id="exhibitTable"
class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Exhibit Type</th>
<th>Description</th>
<th>Marking</th>
<th>Remarks</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="form-group col-md-3">
<div class="cols-sm-10">
<select class="form-control selectpicker cols-md-3"
th:value="${exhibit.exhibitType}" id="exhibitType"
name="exhibitType" roleId="exhibitType">
<option value="">Select Type</option>
<option>Desktop</option>
<option>Laptop</option>
<option>Mobile Device</option>
<option>Portable Storage</option>
<option>Server</option>
<option>Video System</option>
<option>Save As</option>
<option>Others</option>
</select>
</div>
</div>
</td>
<td>
<div class="form-group col-md-3">
<input type="text" name="exhibitDescription"
id="exhibitDescription"
th:value="${exhibit.exhibitDescription}" />
</div>
</td>
<td>
<div class="form-group col-md-3">
<input type="text" name="exhibitMarking" id="exhibitMarking"
th:value="${exhibit.exhibitMarking}" />
</div>
</td>
<td><div class="form-group col-md-3">
<input type="text" name="exhibitRemarks" id="exhibitRemarks"
th:value="${exhibit.exhibitRemarks}" />
</div></td>
</tr>
</tbody>
</table>
</div>
Controller
#RequestMapping(value = "/register", method = RequestMethod.POST)
public String registerIncidentPost(#ModelAttribute("incident") Incident incident,
#ModelAttribute("exhibit") Exhibit exhibit, Principal principal) throws Exception {
long year = Calendar.getInstance().get(Calendar.YEAR);
incident.setIncidentYear(year + "");
Long refNo = incidentService.findMaxRefNoCurrentYear(year + "");
if (refNo == null)
refNo = (long) 1;
else
refNo += 1;
incident.setIncidentRefNo(refNo);
incident.setIncidentStatus(Incident.INCIDENT_REGISTERED);
incident.setIncidentOpeningTimestamp(new Date());
User user = userService.findByUsername(principal.getName());
incident.setIncidentCreatedBy(user);
incidentService.createIncident(incident);
exhibitService.createExhibit(exhibit);
return "redirect:/incident";
}
I've attempted to add the following to my template
<tr data-th-each="exhibit:${exhibitList}">
and the following to my controller
#ModelAttribute("exhibitList") ArrayList<Exhibit> exhibitList
but did not work.
Thanks in advance.
I can only assume this is vb.net since you didn't specify. You need to pass in the complete dataset to the page. Each item in the dataset will be one pre-loaded instance of the model. Then you can do a for each loop on the page itself and generate the html dynamically. Hope this helps.
my problem is that I need to get the radio buttons that are selected in HTML file and use it in the PostMapping.
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Do Test Excercise</title>
<script language="javascript">
</script>
</head>
<body>
<h1>Do Test Exercise</h1>
<form method="POST">
<span align="left" th:each="question : ${exercise.getQuestions()}">
<p valign="top" th:text="${question.text}">Text</p>
<tr align="left" th:each="solution : ${question.getSolutions()}">
<input width="5%" type="radio" th:name="${question.question_ID}" th:text="${solution.text}"
th:value="${solution.text}"/><BR>
</tr>
</span>
<input type="submit" value="Submit">
</form>
</body>
</html>
However I don't know how to get that values for the radio buttons and save it in a array of String
#GetMapping("doTest/{post}/{exercise}")
public String doTest(Model model, #PathVariable String exercise) {
model.addAttribute("exercise", exercisesDAO.getExerciseByType(exercise, "Test"));
return "exercise/doTestExercise";
}
#PostMapping("doTest/{post}/{exercise}")
public String doTest(#RequestParam(value = "solution") String[] solution, #PathVariable String post, #PathVariable String exercise, RedirectAttributes redirectAttributes) {
exercisesDAO.solve(exercise, solution, "admin", "Test");
redirectAttributes.addAttribute("post", post);
redirectAttributes.addAttribute("exercise", exercise);
return "redirect:/showMark/{post}/{exercise}";
}
Thanks
You need to change the name of your inputs from th:name="${question.question_ID}", to th:name="${'solution['+ question.question_ID + ']'}". After that, you need to change your controller, so that instead of an array of Strings, it will receive a HashMap, where you will get for each id, the chosen solution.
Form
<form method="POST" th:action="#{doTest/${post.id}/${exercise.id}}">
<span align="left" th:each="question : ${exercise.getQuestions()}">
<p valign="top" th:text="${question.text}">Text</p>
<tr align="left" th:each="solution : ${question.getSolutions()}">
<input width="5%" type="radio" th:name="${'solution['+ question.question_ID + ']'}" th:text="${solution.text}" th:value="${solution.text}"/><BR>
</tr>
</span>
<input type="submit" value="Submit">
</form>
Controller
#PostMapping("doTest/{post}/{exercise}")
public String doTest(#RequestParam(value = "solution") HashMap<String, String> solutions, #PathVariable String post, #PathVariable String exercise, RedirectAttributes redirectAttributes) { ... }
Attempting to make a button for much longer than one would assume it takes for a newbie.
The Error message I'm getting is:
'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "${id}"
What am I doing wrong? Thanks in advance.
My Controller:
#Controller
public class BuyerController {
private BuyerService buyerService;
#Autowired
public void setBuyerService(BuyerService buyerService){
this.buyerService = buyerService;
}
#RequestMapping("/add-buyer")
public String showBuyerPager(Model model){
List<Buyer> buyers = buyerService.findAllBuyers();
model.addAttribute("buyers", buyers);
model.addAttribute("buyer", new Buyer());
return "add-buyer";
}
#GetMapping("/showBuyerForm")
public String addBuyerForm(Model model){
model.addAttribute("buyer", new Buyer());
model.addAttribute("buyerId", new Buyer().getBuyerId());
return "add-buyer";
}
#PostMapping("/addBuyer")
public String postBuyerForm(#ModelAttribute("buyer") Buyer buyer, Model model){
buyerService.saveBuyer(buyer);
model.addAttribute("buyer", new Buyer());
return "redirect:/";
}
#PostMapping("/deleteBuyer/{id}")
public String deleteBuyer(#PathVariable Long id){
buyerService.deleteBuyer(id);
return "redirect:/";
}
}
View:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Title</title>
<link href="styles.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<header> Welcome to Toner Stock </header>
<h1>Add Buyer</h1>
<div id="mynav" align="center">
<ul>
<li>Home</li>
<li>Add Buyer</li>
<li>Add Manager</li>
<li>Current Stock</li>
<li>Transactions</li>
<li>Order Form</li>
</ul>
</div>
<div id="display-table" align="center">
<form th:action="#{/addBuyer}" th:object="${buyer}" style="width:100%" method="post">
<table>
<td><label>First Name: </label></td>
<td><input type="text" th:field="*{firstName}"/></td>
<td><label>Last Name: </label></td>
<td><input type="text" th:field="*{lastName}"/></td>
<td><label>Enter Address: </label></td>
<td><input type="text" th:field="*{buyerAddress}"/></td>
<td><input type="submit" value="save"/></td>
</table>
</form>
</div>
<div>
<div>
<table id="info-table" align="center" border="1">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Address</th>
</tr>
<tr th:each="buyer : ${buyers}">
<td th:text="${buyer.firstName}"></td>
<td th:text="${buyer.lastName}"></td>
<td th:text="${buyer.buyerAddress}"></td>
<td>
<form th:action="#{/deleteBuyer/${id}}" th:object="${buyer}" method="post">
<input type="hidden" th:field="${buyer}">Delete</input>
<button type="submit" onClick="return confirm('sure?')"/>
</form>
</td>
</tr>
</table>
</div>
</div>
<div>
<select>
<option th:each="buyer : ${buyers}"
th:text="${buyer.firstName}"
th:value="${buyer.buyerId}"
></option>
</select>
</div>
<div>
<div>
</div>
</div>
</body>
</html>
I'm not a thymeleaf expert but it looks like your form th:action="#{/deleteBuyer/${id}}" should be th:action="#{/deleteBuyer/{id}(id=${buyer.buyerId})}"
I am using struts 1.2. My struts flow is working properly but when I am using validate() method of action form for validation. my form is automatically submitted. and this validation method get called.
I am not sure this is normal behavior of struts or some configuration are missing in my application.
Please help me to understand it.
following are the config and code
<action path="/Postaddd"
type="bseller.postadd.PostaddAction"
parameter="dispatch"
scope="request"
validate="true"
name="PostadddForm">
<forward name="posterror" path="ordererror.page"/>
<forward name="successPost" path="bseller.successPost.page"/>
</action> public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
{
Logger log= Logger.getLogger("BSELLER_APPLICATION");
log.info("validate method called");
ActionErrors errors = new ActionErrors();
log.info("Email Id: " + getEmailid());
if(!Validation.isValidEmailAddress(getEmailid()))
{
errors.add("emailid", new ActionMessage("prompt.email.error"));
}
if(!Validation.isPhoneNumberValid(getMobile()))
{
errors.add("mobile", new ActionMessage("prompt.contactno.error"));
}
if(!Validation.isNumeric(getPrice()))
{
errors.add("price", new ActionMessage("prompt.price.error"));
}
return errors;
}
///////////////
<%# page contentType="text/html;charset=UTF-8" language="java"%>
<%# taglib uri="/WEB-INF/displaytag.tld" prefix="display" %>
<%# taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%# taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%# taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%# taglib uri="/WEB-INF/c.tld" prefix="c"%>
<%# page import="bseller.utils.*" %>
<%# page import="java.util.*" %>
<%#page import="bseller.utils.CategorydetailObject"%>
<%#page import="org.apache.struts.taglib.logic.IterateTag"%><head>
<title><bean:message key="homepage.title" /></title>
<html:base />
<style type="text/css">
#import url("<%=request.getContextPath()%>/css/main.css");
#import url("<%=request.getContextPath()%>/css/submitpost.css");
</style>
<script language="javascript" src="jquery_mini.js"></script>
<script language="javascript" src="jquery.dimensions.js"></script>
<script language="javascript" src="js/Ajax_Function.js"></script>
<script language="javascript">
var name = "#floatMenu";
var menuYloc = null;
$(document).ready(function(){
menuYloc = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px")))
$(window).scroll(function () {
offset = menuYloc+$(document).scrollTop()+"px";
$(name).animate({top:offset},{duration:500,queue:false});
});
});
</script>
<script>
function ret_home()
{
alert("home");
return false;
}
function ret_aboutus()
{
alert("about us");
return false;
}
function ret_contactus()
{
alert("contact us");
return false;
}
function getSubcatValue(categoryValue)
{
//alert(document.getElementById("categorySelect").Value);
document.getElementById("categorySelect").Value =categoryValue;
//alert(document.getElementById("categorySelect").Value);
//alert(categoryValue);
//var data="catvalue="+categoryValue;
//alert(data);
//datafromajax="";
// alert("before1"+datafromajax);
var url="Subcategory_Ajax.jsp?catvalue="+categoryValue;
sendRequest(url);
//alert("after"+datafromajax);
//datafromajax="";
document.getElementById("categorySelect").Value="";
}
/*function setUploadImageOption(ordertype);
{
if(ordertype=="Required")
{
//document.getElementById("UploadImage").visible= false;
document.getElementById('UploadImage').style.visibility = 'hidden';
}
}*/
function onchangeSubcat(subcatValue)
{
// alert(subcatValue);
//alert(document.getElementById("subCatSelect").Value);
document.getElementById("subCatSelect").Value =subcatValue;
//alert(document.getElementById("subCatSelect").Value);
//subcatValue=subcatValue;
}
//populatedropdown
</script>
<style type="text/css">
body {
height:2000px;
color:#111;
font:10px "Lucida Grande", "Lucida Sans", "Trebuchet MS", verdana, sans-serif;
}
#floatMenu {
position:absolute;
top:200px;
left:55%;
margin-left:235px;
width:200px;
}
#floatMenu ul {
margin-bottom:20px;
}
#floatMenu ul li a {
display:block;
border:1px solid #999;
background-color:#000;
background:'images/tab_bg1.gif'
border-left:6px solid #999;
text-decoration:none;
color:#ccc;
padding:5px 5px 5px 25px;
}
#floatMenu ul li a:hover {
color:#fff;
background-color:#333333;
}
#floatMenu ul.menu1 li a:hover {
border-color:#09f;
}
#floatMenu ul.menu2 li a:hover {
border-color:#9f0;
}
#floatMenu ul.menu3 li a:hover {
border-color:#f09;
}
</style>
</head>
<body>
<span id="er"></span>
<%!
List l;
HashMap<String ,ArrayList<CategorydetailObject>> hm =null; %>
<%
try
{
hm =(HashMap<String ,ArrayList<CategorydetailObject>>)config.getServletContext().getAttribute("PRODUCTS");
}
catch(Exception e)
{
}
%>
<input type="hidden" name="subcatfromajax" id="subcatfromajax"></input>
<DIV class=city><DIV id=welcome></DIV><DIV id=main><DIV id=block><DIV id=header><font size=4 color=blue >
Post Your Advertisement</DIV><DIV class=blank5></DIV><DIV class=blank5></DIV>
<html:messages id="" />
<html:form action="/Postaddd.do?dispatch=submitPost" method="post" enctype="multipart/form-data" >
<TABLE cellSpacing=0 cellPadding=0 width='98%'background='images/background_city.gif' border=0><TBODY>
<TR>
<TD><div class="post_ad_fonts">Email</div><div style="float:left">
<input style="width:162px" type="text" maxlength="64" name="emailid" id="emailid" class="post_ad_field" value='' />
</div>
<div class="blank10"></div>
</TD>
</TR>
<TR>
<TD><DIV id=bb1><div class="post_ad_fonts">City</div><div style="float:left">
<select class="post_ad_field" style="width:165px" name='citySelectBox' id='citySelectBox'>
<option id='0' name='0' value='0'>Select City</option>
<option name='22' id='22' value='Ahmedabad' >Ahmedabad</option><option name='211001' id='211001' value='Allahabad' >Allahabad</option><option name='23' id='23' value='Bangalore' >Bangalore</option><option name='462001' id='462001' value='Bhopal' >Bhopal</option><option name='24' id='24' value='Chandigarh' >Chandigarh</option><option name='25' id='25' value='Chennai' >Chennai</option><option name='26' id='26' value='Coimbatore' >Coimbatore</option><option name='27' id='27' value='Delhi' >Delhi</option><option name='403108' id='403108' value='Goa' >Goa</option><option name='132222' id='132222' value='Gurgaon' >Gurgaon</option><option name='580020' id='580020' value='Hubli' >Hubli</option><option name='28' id='28' value='Hyderabad' >Hyderabad</option><option name='142222' id='142222' value='Indore' >Indore</option><option name='152222' id='152222' value='Jaipur' >Jaipur</option><option name='144001' id='144001' value='Jalandhar' >Jalandhar</option><option name='831001' id='831001' value='Jamshedpur' >Jamshedpur</option><option name='421301' id='421301' value='Kalyan' >Kalyan</option><option name='208001' id='208001' value='Kanpur' >Kanpur</option><option name='29' id='29' value='Kochi' >Kochi</option><option name='30' id='30' value='Kolkata' >Kolkata</option><option name='162222' id='162222' value='Lucknow' >Lucknow</option><option name='141001' id='141001' value='Ludhiana' >Ludhiana</option><option name='625001' id='625001' value='Madurai' >Madurai</option><option name='575001' id='575001' value='Mangalore' >Mangalore</option><option name='31' id='31' value='Mumbai' >Mumbai</option><option name='32' id='32' value='Mysore' >Mysore</option><option name='172222' id='172222' value='Nagpur' >Nagpur</option><option name='422001' id='422001' value='Nashik' >Nashik</option><option name='400701' id='400701' value='NaviMumbai' >NaviMumbai</option><option name='201301' id='201301' value='Noida' selected>Noida</option><option name='800001' id='800001' value='Patna' >Patna</option><option name='33' id='33' value='Pune' >Pune</option><option name='360001' id='360001' value='Rajkot' >Rajkot</option><option name='182222' id='182222' value='Surat' >Surat</option><option name='400601' id='400601' value='Thane' >Thane</option><option name='620015' id='620015' value='Trichy' >Trichy</option><option name='695001' id='695001' value='Trivandrum' >Trivandrum</option><option name='390001' id='390001' value='Vadodara' >Vadodara</option><option name='520001' id='520001' value='Vijayawada' >Vijayawada</option><option name='531001' id='531001' value='Vizag' >Vizag</option></select>
<input type='hidden' name='city' id='city' value='201301'/>
</div>
<div class="blank10"></div>
</div>
</TD></TR>
<TR>
<TD>
<div class="post_ad_fonts">Category</div>
<div style="float:left">
<select class="post_ad_field" style="width:165px" name='categorySelect' id='categorySelect'" onchange="getSubcatValue(this.value);">
<option id='0' value='0'>Select Category</option>
<%
Set<Map.Entry<String,ArrayList<CategorydetailObject>>> set =hm.entrySet();
for(Map.Entry<String,ArrayList<CategorydetailObject>> me: set)
{
String cat= me.getKey();
%>
<option name="<%=cat %>" id="<%=cat %>" value="<%=cat %>"> <%=cat %></option>
<%
}
%>
</select>
<input type='hidden' name='categorySelect' id='categorySelect' value=''/>
</div>
<div class="blank10"></div>
</TD>
</TR>
<TR>
<TD>
<div class="post_ad_fonts">SubCategory</div>
<div style="float:left">
<select class="post_ad_field" style="width:165px" name='subCatSelect' id='subCatSelect' onchange="onchangeSubcat(this.value);">
<option id='0' value='0'>Select SubCategory</option>
</select>
<input type='hidden' name='subCatSelect' id='subCatSelect' value=''/>
</div>
<div class="blank10"></div>
</TD>
</TR>
<TR>
<TD>
<DIV id=bb1><div class="post_ad_fonts">Head Line</div>
<div style="float:left">
<input style="width:440px" type="text" maxlength="64" name="headline" id="headline" class="post_ad_field" value='' />
</div>
<div class="blank10"></div>
</div>
</TD>
</TR>
<TR>
<TD>
<DIV id=bb1><div class="post_ad_fonts">Description</div>
<div style="float:left;width :440px;">
<table border="0" style="margin:0px"><tr><td><div id="showbar">Loading Html Editor...<img src="images/ajax_loader.gif" alt="loading"/></div></td></tr></table>
<textarea name="description" id="description " onfocus="if(this.value=='Adding more detail here will help you get more responses.')this.value='';" style="width:440px;height:170px">Adding more detail here will help you get more responses.</textarea>
</div>
</div>
</TD>
</TR>
<TR>
<TD>
<div class="post_ad_fonts">Mobile No.<br/><span style="font-weight:normal">(Optional)</span></div>
<div style="float:left">
<input style="width:162px" type="text" maxlength="14" name="mobile" id="mobile" class="post_ad_field" value="" />
</div>
<div class="blank10"></div>
</TD>
</TR>
<TR>
<TD>
<div class="post_ad_fonts">Price<br/><span style="font-weight:normal">(Optional)</span></div>
<div style="float:left">
<input style="width:162px" type="text" maxlength="14" name="price" id="price" class="post_ad_field" value="" />
</div>
<div class="blank10"></div>
</TD>
</TR>
<TR>
<TD>
<div class="post_ad_fonts">Owner type<br/></div>
<div style="float:left">
<select class="post_ad_field" style="width:165px" name='owner' id='owner'>
<option id='0' name='0' value='0'>Individual</option>
<option name='22' id='22' value='Ahmedabad' >Broker</option></select>
<input type='hidden' name='ownertype' id='ownertype' value='Individual'/>
</div>
<div class="blank10"></div>
</TD>
</TR>
<TR>
<TD>
<div class="post_ad_fonts">Order type<br/></div>
<div style="float:left">
<select class="post_ad_field" style="width:165px" name='order' id='order'">
<option id='0' name='0' value='Available'>Available</option>
<option name='22' id='22' value='Required' >Required</option></select>
<input type='hidden' name='ordertype' id='ordertype' value='Available'/>
</div>
<div class="blank10"></div>
</TD>
</TR>
<TR>
<TD>
<div class="post_ad_fonts">Upload Image<br/></div>
<div style="float:left" id="UploadImage">
<html:file property="image1"></html:file>
<html:file property="image2"></html:file>
<html:file property="image3"></html:file>
<input type="file" name="image4">
</div>
<div class="blank10"></div>
</TD>
</TR>
<tr><td><div class="post_ad_fonts"><br/></div><div style="float:middle"><html:submit>POST ORDER</html:submit></div> </td></tr>
</TBODY></TABLE></html:form></DIV></DIV></DIV><DIV class=blank10></DIV></DIV></DIV>
<div id="floatMenu">
<ul class="menu1">
<li> Home </li>
</ul>
<ul class="menu2">
<li> About Us </li>
<!--<li> </li>
<li> </li>-->
</ul>
<ul class="menu3">
<li> Contact Us </li>
</ul>
</div>
the validate method of actionform is always called when the form is submitted. you cannot manually call it unless you r reimplementing struts in ur own way. if u want a method to do the same work as the validate method, move the code of the validate method into another method and call it in the validate method. I do not completely understand what you are trying to do so please be more specific.