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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

colr__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
Gurvinder Pal SinghCommented:
@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
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

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:
Convert the js file in to JSP and used the format tag ...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sathish David Kumar NArchitectAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.