Forums Register Login

How to add error message before sendRedirect

+Pie Number of slices to send: Send
Hi Geeks,

I have a requirement here,

No session, no multiple jsp. All i have is one jsp which shows a drop down with go and cancel buttons and based on the drop down the same jsp will be called with respective values(which called from java methods) . Please remember everything is in a single JSP.
something like this,

<%
if(editMode == 0)
dropdown
else{
-----
values
------
}
%>

The Go button carries the dropdown value to the else part

The problem is, the drop down has null at the top followed by options, when nothing selected and clicked on go, an inbuilt java method addError needed to be added and the page shouldn't submitted to next.
Since things should happen after clicking on Go, the page is getting forwarded to the else part. All i want is, is to call the addError method and stay back to the same page even after clicking on "Go".

I have tried adding javascript onClick like this,

function fldCheck(){


if(document.frmMain.field.value == ''){
<% uiModule.addError(new Error("message"));%>
return;
//document.frmMain.action="url";
}
else
{document.frmMain.action=submit;}

}

and also tried handling within jsp like this,

if(editMode== 5 && fieldVal == 0){

uiModule.Error(new Error("ErrorMessage"));
String redirectURL = "ur";

response.sendRedirect(redirectURL);

}

Both showing the same page but no error message added. It is because the page is called and the errors are refreshed. Any ideas would help a lot.

Thanks,
Asvin
+Pie Number of slices to send: Send
When you call sendRedirect, that asks the browser to send a new request to whatever URL you provide as the parameter. You don't send a response in this case, all that happens is that your server sends a 302 return code telling the browser to redirect.

If you want the user to see error messages, then they should be in the page you're redirecting to.
+Pie Number of slices to send: Send
I understand, but not sure how to stay in the same page after hitting the action submit. Any ideas would be appreciated.
+Pie Number of slices to send: Send
I don't understand what "stay in the same page" means. It doesn't sound like it's compatible with redirecting -- could you explain what it means using normal terminology?
+Pie Number of slices to send: Send
Ok, let me try this...


the url http://localhost:8090/MyProj/MyPage/Edit=6

got the drop down with the "Go" and "Cancel". The Go button will submit the value and takes to the Url with the Edit=5 ie http://localhost:8090/MyProj/MyPage/Edit=5.

My requirement is, if the null is selected and clicked on "Go", i need the error message to be displayed and the Edit should stay at 6 ie http://localhost:8090/MyProj/MyPage/Edit=6. (which means back to the drop down page)

Hope it makes sense?
+Pie Number of slices to send: Send
I am not getting what exaclty you want but as your last post. i think..
why are not using validation on client side using javascript or jqeury to valid null. if null select at drop down not redirect.
and also show an error message.
hope it will help you.
+Pie Number of slices to send: Send

Thanks Neeraj and sorry if im not clearing the air.

My project is... every jsp page loads on a command called editCmd. editCmd is the command which will reach a class. So when I click on a link to create a new inventory, the inventory page comes fields(date created, created by, doc id.. etc). One of its field is a drop down called Order Type.

Now the requirement is, when the user clicks on the create inventory link, the drop down page should appear and then to the corresponding type, the other fields to be populated. I have created the page with the dropdown and the others. The requirement is done. The situation is, i need to include a error message if nothing selected and the go pressed.

1. When the user click create inventory, the jsp to populate the drop down -> editCmd =6 (ie dropdown page).
2. When the user clicks on Go (the form submit action takes to) -> editCmd = 5 ( ie fields page based on the entry in the drop down).

If i have selected null and clicked on Go, all the fields appears with null.

The condition here is, if any error message has to be displayed, it has to be addError method. I did use the javascript to validate the form and stop the action like this,

function fldCheck(){
if(document.frmMain.aa_type.value == ''){
<% uiModule.addError(new Error("Error"));%>
return;
//document.frmMain.action="url";
}
else
{document.frmMain.action=submit;}

}

But my problem is, when the go is clicked, the action takes me to the editCmd value 5. Which means im already in the submitted class. I can control the look of the JSP by the conditions and make the user to see only the drop down. But since im already in the submitted class, i cannot take the drop down value and resubmit again.

I need some information on how to get back to the callee form from the caller from ie after the action submit, if the value is null, i should get back to old form.

I dont have any options to change the editCmd.

Im not sure if im still clear.
Happily living in the valley of the dried frogs with a few tiny ads.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 4791 times.
Similar Threads
history problem in jsp page
Using Javascript, ajax and submit button in Custom tag file
calling function while re postingthe same page..javascript
Problem retaining form field after submission
Pie Chart display based on submitted selection usin
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:38:34.