Win a copy of Spring Boot in Practice this week in the Spring 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Dynamic javascript generation?

 
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"

 
Saloon Keeper
Posts: 25849
184
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for the replies
reply
    Bookmark Topic Watch Topic
  • New Topic