Solved

Struts and external javascript files

Posted on 2003-11-11
5
794 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xjc and jaxb 2 95
sortaSum challenge java 17 174
memory representation of int[][][] a=new int[2][][]; 10 60
maven webservice example issue 2 156
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…

680 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