This discussion is archived
9 Replies Latest reply: Oct 9, 2012 3:15 AM by 955842 RSS

Is there a way I can store the "render:stream" value in a local variable

Venkat Mohanam Newbie
Currently Being Moderated
As we know, the render:stream will always stream the output to the browser. I have a requirement where I need to process the output of render stream at the server side and print it. So I tried using ics.ReadPage and called a siteentry/csElement which has the code <render:stream variable="myvalriable"/>. But still I get the unprocessed output in the ics.ReadPage, calling the SiteEntry. Appreciate your help regarding this.
  • 1. Re: Is there a way I can store the "render:stream" value in a local variable
    tony field Explorer
    Currently Being Moderated
    The short answer is no. The longer answer is that readPage will work, if the page you're reading is cached. You can also use AJAX but that would mean your code flow would change quite a bit.

    I assume you're going to want to do some processing on the output of render:stream. You might want to consider doing the processing first, then setting the result into a variable and then calling render:stream on the variable instead. In other words, process first, then stream.

    Regards,
    Tony
  • 2. Re: Is there a way I can store the "render:stream" value in a local variable
    Venkat Mohanam Newbie
    Currently Being Moderated
    Thanks Tony, for your quick response!.

    Basically I need to pass this output to a js function like below.
    displayOverlay('renderstream-content');

    The render stream output content may have single quote and double quotes, which is breaking the js function call. So, I tried, like below
    <div id='my-div' style='display:none'><render:stream variable='myvariable'/></div>
    and then
    displayOverlay(document.getElementById('my-div').innerHtml());
    This works fine, but there is an extra <p> tags added in the output due to FCKEditor's default behavior, whenever the embedded template has some html tags like div in this case.

    So, Unless I get the renderstream content at the server side and parse it to escape all single and double quotes, I cannot get away with this issue.

    Markley has suggested to call the page using the url instead of readPage. Now we use Utilities.readURL , which perfectly returns the processed content. Now we are able to parse it and escape all single and double quotes and pass it to js function. So, this resolves the issues.
  • 3. Re: Is there a way I can store the "render:stream" value in a local variable
    tony field Explorer
    Currently Being Moderated
    Okay. You might want to look at the "encode" and "escape" attributes on render:stream - they may automatically do the proper javascript escaping for you.

    readUrl works but consumes an app server thread, so use it with caution.
  • 4. Re: Is there a way I can store the "render:stream" value in a local variable
    Venkat Mohanam Newbie
    Currently Being Moderated
    That's exactly correct Tony!.
    We get FileNotFound exception when we use Utilities.readUrl. This exception goes off, when we restart the system. We were really struggling on this issue for the past 2 days.
    Do you suggest any work around to get away with this issue?

    Also, I was trying your option, to encode/escape the value in render:stream. But I couldn't find out encode/escape attributes in render:stream tag. Could you please give us a sample code to implement in this way. Appreciate your response Tony and thanks for your time. Below is the syntax I could see in the guide. Where do we supply the attribute encode/escape in the below tag?
    <render:stream
    [value="variable_string"]
    [variable="variable name"]
    [ssvariable="session variable name"]
    [property="futuretense.ini_property"]
    [list="list_name"]
    [column="column_name"]
    [filecolumn="column_name"] />

    Edited by: Venkat Mohanam on Aug 6, 2012 5:21 AM
  • 5. Re: Is there a way I can store the "render:stream" value in a local variable
    Venkat Mohanam Newbie
    Currently Being Moderated
    Still facing some issue with the work arounds, so re-opened this issue with my question (in the above thread)

    Edited by: Venkat Mohanam on Aug 6, 2012 5:20 AM
  • 6. Re: Is there a way I can store the "render:stream" value in a local variable
    tony field Explorer
    Currently Being Moderated
    Hi Venkat -

    Sorry, my mistake! I was thinking of the escape/encode attributes on the [xlat:stream] tag - I assumed it was a pattern across the stream tags but apparently not.

    There is no way to get the output of render:stream in a variable programmatically without going through the servlet's front door. There isn't even a back door, it has to do with the way the functionality is built. It is a tricky problem to fix and it must be done by engineering.

    Your best bet is to

    a) see if you can accomplish the same thing a different way
    b) use readURL (with a URL that actually works).

    For a), have you considered retrieving your data into a variable, processing it, then calling render:stream on the variable instead of the asset field?

    Tony
  • 7. Re: Is there a way I can store the "render:stream" value in a local variable
    Venkat Mohanam Newbie
    Currently Being Moderated
    Hi Tony,

    That's fine, no problem Tony. Thanks for your response.

    For option a) if I escape the single and double quotes on the asset value before passing it to render:stream, the element execution fails, because the content contains someother include (embedded asset). Below is the sample text that I am trying to escape.
    -----------------------------------------------------------------------
    Customers for a wide range of solutions: <span id="_CSEMBEDTYPE_=inclusion&amp;_PAGENAME_=FirstSiteII%2FDocument_C%2FDocumentDisplay&amp;_cid_=1299863431444&amp;_c_=Document_C"><i>[Asset Included(Id:1299863431444;Type:Document_C)]</i></span>Web sites, product marketing sites and partner extranets. For more information click here
    -----------------------------------------------------------------------
    I guess, even the render engine looks for some specific double quotes to process the embed tag. As all the quotes are escaped by my script, the element execution itself is failing.

    For option b) the ics.readUrl sometimes throws filenotfound exception and it gets resolved only when we restart the system.
    Please suggest. Thanks for your suggestion and time...
  • 8. Re: Is there a way I can store the "render:stream" value in a local variable
    tony field Explorer
    Currently Being Moderated
    Yes, if you view the source, the embedded asset is a A HREF tag with some custom field info in it. Your pre-processor needs to be smart enough to not mangle that string.

    I would investigate the fileNotFound exception issue. That's very strange.
  • 9. Re: Is there a way I can store the "render:stream" value in a local variable
    955842 Newbie
    Currently Being Moderated
    Hi Venkat,

    This can also be achieved in this way


    String fieldData = ics.GetVar("fieldData");
    EmbeddedLink link = new EmbeddedLink(ics,fieldData,false,false,true);
         String fieldValueInString = link.evaluate();

    The fieldValueInString will contain the Required Value.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points