Solved

Struts and external javascript files

Posted on 2003-11-11
5
792 Views
Last Modified: 2012-05-04
Hi,

I use the Struts 1.1 Framework and I want to use external javascript files to validate my forms.
But the files depend on the Locale of the Web browser. If it's ES --> src="js/es/myfile.js" and if it's US --> src="js/us/myfile.js"
Unfortunately there is no tag "srckey" with Struts 1.1.

Any suggestions ?

Thanks a lot in advance,

Highlander1536
0
Comment
Question by:highlander1536
5 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 9724661
You can get the Locale of the user out of the HTTP headers...

http://www.w3.org/International/questions/qa-accept-lang-locales.html

What does:

<%
  String bigLoc = request.getHeader( "accept-language" ) ;
  out.println( "<b>" + bigLoc + "</b>" ) ;
  if( bigLoc != null && bigLoc.length() > 2 )
    bigLoc = bigLoc.substring( 0, 2 ) ;
  out.println( "<tt>" + bigLoc + "</tt>" ) ;
%>

give you?
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 9728335
In struts, you should be using Action.getLocale() to get client's current locale. Based on current local, you should try to see if the a js file exists, if not you should fall back to default js file.

Let us know if you have further enquires.
0
 
LVL 2

Accepted Solution

by:
DidierD earned 125 total points
ID: 9762134
You can use the Struts Validator for this.
In validation.xml you can define a locale specific formSet. For example
<form name="loginForm" locale="fr" country="CA">

There are already some basic validators available. The mask can be very usefull. But you can also add your own (Javascript) to the validator-rules.xml.

For more information about this see http://jakarta.apache.org/struts/userGuide/dev_validator.html
0
 

Author Comment

by:highlander1536
ID: 9762420
OK, thanks a lot.
Last question : do you know where I can download some usefull validator-rules.xml ?
0
 
LVL 2

Expert Comment

by:DidierD
ID: 9762540
Thanks for the points :)

If you look in the validator-rules.xml that comes with Struts validator, you see that there are already basic validators in it. These should help you, to create your own validators. Basic validators are required, mask, range, maxLength, minLength, date, creditCard, email, byte, short, integer, long, float, double.
I don't know where you can download other examples.

Hope this helps.

Greetz,
Didier

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can I clean log of  running tomcat 7 server ? 3 127
iterator example remove 8 75
HTML5 vs JSP - REST based application development 4 1,183
countXY challenge 28 160
Are client relationship the only driver of a successful MSP? While important, client relationships are only one component. Learn how else MSPs can broaden their horizon and differentiate themselves.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

792 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