• 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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: 28398
210
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
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic