Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to write an error message on a jsp by calling a js function from jsp

Posted on 2006-07-07
10
Medium Priority
?
378 Views
Last Modified: 2010-04-01
hi ,
i am facing the problem of showing an error message on a jsp page once the user clicks a link.

The error message is to be shown on the same page where the link is shown.

the code is as below

(<html:link href="#" onclick="document.write(indexEnableInMatch('pmformforindexing'))">
                                                                  <bean:message bundle="POIMatches" key="pmr.details.link" />
                                                                       </html:link>)


not abel to understand what code should i write on the the event onClick?

kindly help me

regards,
jatinder

0
Comment
Question by:ramareddyj
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 5

Expert Comment

by:jpolin1
ID: 17058877
Looks like you are using struts, why not use its built in error checking?

If you want it to display an error message w/o a page refresh(another request-responce cycle),
then you need some DHTML, like swapping layers in and out via javascript.

Let me know which way you are trying to go.
0
 

Author Comment

by:ramareddyj
ID: 17058987
i am using struts framework. and i have decide to show the error message in a textbox which will be disabled all the time

what i am trying to do now is on execution of following line
onclick="indexEnableInMatch(<%='pmformforindexing'%>)">

my indexEnableInMatch() will be called and inside this function i am going to set the value of a text box to my error message

function indexEnableInMatch(FormName)
{
      alert(FormName);
      FormName.hiddenLabel.value="my error emssage ";

}

now i am facing problem in passing  the parameter "pmformforindexing" which is nothing but my action form.

any way to resolve this??

regards,
jatinder
0
 
LVL 5

Accepted Solution

by:
jpolin1 earned 500 total points
ID: 17059194
Ideally you should use struts built in form-validation.
Are you familar with this at all? There are a couple of different ways to go with it.
It will be easier to setup and easier to maintain down the road.
If the data you want to validate is already on form beans associated with your actions, then it wouldn't be too much work to get the wiring together to make this happen.

Basically all you do is override the validate method in your form beans, perform your error check there.
If you have errors you create a collection of them and return them. Then all you have to do is create a resource bundle for the actual messages and put 1 new tag on your jsp.

The other good thing is that the validation is handled on the server side, rather than client side like you are trying to do with javascript. If you do your validation on the server side, you are guarenteed to be getting good data, javascript can always be disabled or hacked around.

The latest way of doing validation within struts uses the validation framework. There is a ton of stuff out there on this. I haven't used this approach yet.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:ramareddyj
ID: 17063728
can i make the text color "RED" for a disabled text box?????
0
 
LVL 4

Assisted Solution

by:Meritor
Meritor earned 500 total points
ID: 17064595
If you are using IE then its hard to set color for disabled text box but in Mozilla/Netscape you can write the following code:
input[disabled] {color:red!important;}

As in:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title> New Document </title>
<style type="text/css">
input {
color: green;
}
input[disabled] {color:red!important;}
</style>

</head>

<body>
<form>
<input type="text" disabled value="disabled"></input><br>
<input type="text" value="normal"></input>
</form>
</body>
</html>
0
 
LVL 5

Assisted Solution

by:muktajindal
muktajindal earned 500 total points
ID: 17071822
You should use server-side validation provision by Struts to solve this. Are you aware of Struts Form validation using "validate" method in your Form classes? Just try that and pass errors from there to your jsp files and display there.

For textbox color change, you can define two separate classes for active and disabled textboxes in your CSS file. Create textboxes with the active class. Whenever you want to disable a textbox, just change the class associated with that textbox. You should get the desired results.
0
 
LVL 10

Assisted Solution

by:jaggernat
jaggernat earned 500 total points
ID: 17349532
You should use the "Struts validation framework". Its very simple to use and very powerful.

Struts validation framework comprises primarily of two files, validation.xml and validation-rules.xml(provided by struts framework).

lets say you want to validate a field "xyz" in your jsp,
In your validation.xml file , you have to write

<form name="nameoftheformbean">
<field property="xyz" depends="required">
<arg0 key="showerrormessage"/>
</field>
</form>


<field property="xyz" depends="required">  //reuired is a rule defined in validation-rules.xml file which means that the field "xyz" cannot be null.
<arg0 key="showerrormessage"/>  //showerrormessage is defined in ApplicationResources.properties file like
showerrormessage=Please enter a value in the field xyz

and thats it . Its that simple.


In your struts-config , you have to put
validate="true" and
input="NameOfJSP"

Basically this means perform the validation and if there are any errors show them on NameOfJSP.jsp

Like "required" is a rule, there are other rules.

Take a look at this excellent article from Orielley

http://www.onjava.com/pub/a/onjava/2002/12/11/jakartastruts.html

hope that helps
J
0
 
LVL 10

Expert Comment

by:jaggernat
ID: 17349555
>>>>>   input="NameOfJSP"

I meant    input="NameOfJSP.jsp"



0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will be showing you how to subnet the easiest way possible for IPv4 (Internet Protocol version 4). This article does not cover IPv6. Keep in mind that subnetting requires lots of practice and time.
Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question