How to use fmt tag in javascript(js) file

Hi ,

I have some *. js file i want to use format tag lib inside the tag lib ? How can i use that ?  
LVL 20
Sathish David  Kumar NArchitectAsked:
Who is Participating?
 
Sathish David Kumar NConnect With a Mentor ArchitectAuthor Commented:
Convert the js file in to JSP and used the format tag ...
0
 
colr__Connect With a Mentor Commented:
The concept of tags dopes not exist in Javascript, you are getting miced up between Java and javascript, which are entiryl different things. The fmt exists in JSTL, which is the Java Standard tag Library - this is used o JSP pages, which themselves can contain Javascript, however they are not interchangeable
0
 
Sathish David Kumar NArchitectAuthor Commented:
ya i know that !

If i have jsp page inside script means i can use fmt tag inside the script . but seprated js file i cant use . y ?
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
Gurvinder Pal SinghConnect With a Mentor Commented:
@dravidnsr: No you can't.

Since by the time JSP tags are processed and are rendered on the browser, it is replaced by some other values, so it wont be available to javascript.
You can easily check this by doing view-source on your browser.
0
 
colr__Commented:
You can do that! A jsp page has to have a JSP extension - you can't put java scriplets or java tags inside a javascript file.
0
 
Sathish David Kumar NArchitectAuthor Commented:
then is there any other way to do that ?
0
 
Gurvinder Pal SinghCommented:
what do you want to achieve finally?
0
 
Sathish David Kumar NArchitectAuthor Commented:
i want ti use alert msg as i18n so i want to get the values in property file .

I dont want to copy the js file content to JSP because its having huge .
0
 
Gurvinder Pal SinghCommented:
you have to use that fmt tag inside a span tag, since you can get the handle to span tag in javascript, then you can use that span tag as message alert.
0
 
colr__Commented:
... or call the javascript function from your jsp, with an argument that is your internationalised text - this might be a bit simpler than tarversing the DOM to get a span tag
0
 
Sathish David Kumar NArchitectAuthor Commented:
can you bit clear . some example !!
0
 
colr__Commented:
In your javascript (.js) file, have something like the following:

function doSomething(theMsg){
    alert(theMsg);
}

And in your JSP, have something like this;

<script>
    // call the function
    doSomething('<fmt:formatNumber value="..."/>');
</script>

So you are using the tag to provide the value to the javascript, which is in an external file
0
 
Sathish David Kumar NArchitectAuthor Commented:
but i did lot of validation in single file so hoe can i pass that... its not d idea right...
0
 
colr__Commented:
I'm not sure what you mean by that.

You cannot use tags in an external js file, so the only way to get java stuff in to your javascript is to pass it as an argument as I've shown. Either that or place it in the DOM somewhere and have the javascript find and use it as suggested above.
0
 
Sathish David Kumar NArchitectAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.