Monday, November 20, 2017

Commenting JavaScript in PeopleTools

If we look at some of the HTML objects which store JavaScript in PeopleTools, we will find many styles of comments. Here are a few options.

Option 1
// Option 1 - Single Line Comment;

/*
Option 1 - Multi-line Comment 1;
Option 1 - Multi-line Comment 2;
*/

Option 2
//% Option 2 - Single Line Comment;

<!%
Option 2 - Multi-line Comment 1;
Option 2 - Multi-line Comment 2;
 -->

What is the benefit of using % meta-html?

The screenshot below shows how the javascript is rendered at runtime. We can see that using the % sign allows the meta-HTML processor to recognize the comments and delete them during runtime.


PeopleBooks: Comments in HTML

Does commenting style (% meta-html) really matter for JavaScript?

Not really. PeopleTools 8.53 introduced JavaScript Minification by default. The screenshot in the previous section was generated by disabling minification (using Signon - Page Generation trace settings). Therefore, the commenting style in JavaScript does not really matter if we don't override/disable the PeopleTools (8.53+) default minification which will delete all comments (regardless of style) in JavaScripts.

PeopleBooks: Working with JavaScript in HTML Definitions


15 comments:

  1. Have always used // even for multi-line to avoid comments in output, didn't knew <!% --> exists. Thank you!

    I think it's high time Oracle should include JavaScript as object instead of using HTML object type for it.

    ReplyDelete
  2. Hi Sasank,

    Is there any easy way to search some text inside the HTML object in App Designer?. Sometimes we are not able to find the definition of some Javascript method. And the data stored in Database in case of HTML object is of BLOB form.

    ReplyDelete
    Replies
    1. You can use the 'Find In...' option as described in this discussion.
      https://community.oracle.com/thread/4111609

      Instead of using 'Text String in PeopleCode' you should use 'Text String in HTML' and search the 'Entire Database'.

      Delete
  3. Hello Shashank,

    Have you come across any partial page refresh issues like HTML area with Javascript getting wiped out when fieldchange event is fired?

    What is the best approach to avoid this? I read Jim's monkey patching technique to use net2.contentloader but did not succeed from that.

    Thanks in advance for you answer!

    ReplyDelete
  4. Hey Sasank, looks like you deleted my comment of HTML/Javascript question, can you tell me which post I should use to start this discussion? http://peoplesoftfluidui.blogspot.com/

    ReplyDelete
    Replies
    1. Hi,

      I did not delete your post. At times, if anonymous comments are posted, Blogger automatically moves it to SPAM until I review and release the comments. So, there may be a delay if comments are posted anonymously.

      That said, yes, the problem you are describing is common and one that has required us to workaround by writing javascript that works in this condition.

      I ran into this problem and worked around it in my example (this may not necessarily work for you, just intended to give you some ideas):
      https://pe0ples0ft.blogspot.com/2017/11/recaptcha-in-peoplesoft-pia-pages.html

      There is a solution for this in 8.56:
      https://pe0ples0ft.blogspot.com/2017/11/pt-8-56-htmlarea-respond-only-once.html

      Hope this helps. Thanks!

      Delete
  5. Sorry Sasank for that, thanks for the answer.

    My HTML area is dynamic, If HTML is static then I believe your solution will work.

    I'm populating HTML area with charts from Oracle Jet/Chart JS java script libraries on the fluid page. SO content on the page is drillable/dynamic, as soon as I apply changes and refresh the page with field change event HTML area disappears.

    Jim recommended to use net2.contentloader but it did not work for me. I'll have to come up with some solution.

    Thanks,
    Srini
    http://peoplesoftfluidui.blogspot.com/

    ReplyDelete
    Replies
    1. Hi Srini - Sorry for the delay in responding. Did you figure this out? I would be interested to learn how you workaround around this!

      Delete
    2. Hey Sasank, silly me after I got more time to work on this I found errors in the browser console, chart works fine now after I fixed my JS code.

      Delete
    3. One more change I made to my code is caching my javascript html objects to browser

      Delete
    4. Here is the link of my fun project to display chart with js library.

      https://ibb.co/mb9TzJ

      Delete
  6. Hello Sasank,

    Nope, I did not spend much time because of time constraints. I ended up using PeopleSoft Charts (8.55 user Oracle Jet behind the scenes but coding using People Code, no java script is involved here from developer). So basically followed workaround, by doing this I missed opportunity to provide excellent UI experience.

    I noticed something weird that when I run java script on the fluid page with out calling external java script libraries like chart JS, page works fine. For Example: I had timer on the fluid page using HTML area, this timer will get real time data from PSPRCSRQST table and display timer on the page showing when next process will run, this works fine for some reason even after drilling down the page.

    I'll update you once I figure this out.


    Thanks
    Srini
    http://peoplesoftfluidui.blogspot.com/

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete