This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Dynamic javascript generation?  RSS feed

 
Sol Mayer-Orn
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.
 
Marcin Majewski
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"

 
Tim Holloway
Bartender
Posts: 18709
71
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!