This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Dynamic javascript generation?  RSS feed

 
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm relatively new to JSF (using JSF 2.0).
I have no problem generating HTML files, but now ran into an unusual situation where I need to dynamically generate a *javascript* file.
Something like:


I'm aware there are other solutions, but I'm not crazy about them:
- inline my javascript inside the HTML page:
- pass 'var a' as a parameter: f(a)

But i'd rather generate a separate (dynamic) javascript file (because our real-life javascript is complex, so the generated HTML would be less readable if we inline javascript into it... and in reality we don't have a single parameter "var a", but dozens of them, which is ugly to pass).

Is it possible to do via JSF?
Or would it be better to make it a JSP (just for this javascript file)?
Thanks.
 
Greenhorn
Posts: 14
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that the best solution would be to use JSF-AJAX(A4J) combination to accomplish desired effect. If you are interested in creating dynamic js and you can abandon the power of JSF managed bean then JSP is probably your choice. On the other hand you can always reference dynamic components value as the following code (provided you have ie. a form named "myForm" with <h:inputText> named "myInput"

 
Bartender
Posts: 19673
92
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, I recommend passing parameters. Inlining hard values into the JS code can be a real problem. It's harder to debug, I think, and you have to be REAL careful that the JS isn't cached and you end up running stale JS code.
 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for the replies
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!