• richardc020
  • NEWBIE
  • 0 Points
  • Member since 2016
  • Web Application Developer


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies

Hi,
I have created one VF page (Name: vfPageOne) and having my controller to populate data for that VF page. I have defined the "contentType="text/javascript"" for the VF page so that I can include this VF page into another VF page.

I have create another VF page (Name: vfPageTwo) and including 'vfPageOne' into this second VF page.

Here is my code snippet of 'vfPageOne' is.
#*******************************************
<apex:page controller="ctrlOne" contentType="text/javascript">

    <script>
    var srchInput = {!srchData};   // {!srchData} is coming from controller in JSON format.
        alert({!srchData});
    </script>
</apex:page>
#*******************************************


Here is my code snippet of 'vfPageTwo' is.
#*******************************************
<apex:page controller="ctrlTwo">
    <apex:includeScript value="apex/PPF_SearchKeywords"/>
    <script>
         alert(srchInput);
    </script>
    <apex:form >
    <apex:inputText value="{!srchKeyword}" id="srchbox1"/>
    </apex:form>
</apex:page>
#*******************************************

I am trying to access js variable 'srchInput' from 'vfPageTwo' which got populated in 'vfPageOne'. In 'vfPageTwo', i could see the values. But in VF page two, alert() is saying undefined for 'srchInput'. I could have done away with one vf page and controller, but I want to reduce the viewstate size of second VF page.

Let me know how I can achieve this.

  • January 21, 2013
  • Like
  • 0

I need to implement a visualforce page that serves a javascript text file.  This is based on this blog entry: http://www.nimbleuser.com/blogs/Developers/Developers/Visualforce_Static_Resource_Alternative.aspx

 

<apex:page contentType="text/javascript" cache="false" expires="0">
//alert('ping');
if (document.getElementById('cas21') != null)
 {
    var divsInthepage = document.getElementsByTagName("DIV");
    for (i = 40; i < divsInthepage.length; i++)
    {

        if (divsInthepage[i].innerHTML.indexOf("topButtonRow", 1) > 1 && divsInthepage[i].innerHTML.indexOf("requiredBlock", 0) < 1)
        {
            divsInthepage[i].innerHTML = '&lt;table  border="0" cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;&lt;td class="pbTitle"&gt;&lt;img src="/s.gif" alt="" width="1" height="1" class="minWidth" title="" /&gt;&lt;h2 class="mainTitle"&gt;Case Edit&lt;/h2&gt;&lt;/td&gt;&lt;td class="pbButton" id="topButtonRow"&gt;&lt;input value="Submit"  class="btn" title="Submit" name="save" type="submit" /&gt; &lt;input value="Cancel"  class="btn" title="Cancel" name="cancel" type="submit" /&gt;&lt;/td&gt;'
        }
        if (divsInthepage[i].innerHTML.indexOf("bottomButtonRow", 1) > 1 && divsInthepage[i].innerHTML.indexOf("requiredBlock", 0) < 1)
        {
            divsInthepage[i].innerHTML = '&lt;table  border="0" cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;&lt;td class="pbTitle"&gt;&lt;img src="/s.gif" alt="" width="1" height="1" class="minWidth" title="" /&gt;&lt;/td&gt;&lt;td class="pbButtonb" id="bottomButtonRow"&gt;&lt;input value="Submit"  class="btn" name="save" tabindex="11" title="Submit" type="submit" /&gt; &lt;input value="Cancel"  class="btn" name="cancel" title="Cancel" type="submit" /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;'
        }
        if (divsInthepage[i].innerHTML.indexOf("Assign using active assignment rules", 1) > 1 && divsInthepage[i].innerHTML.indexOf("requiredBlock", 0) < 1)
        {
            divsInthepage[i].innerHTML = '&lt;table  class="detailList" border="0" cellpadding="0" cellspacing="0"&gt;&lt;tr  class="detailRow last"&gt;&lt;td colspan="4"&gt;&lt;input  checked="checked" id="cas21" name="cas21" tabindex="10" type="checkbox" value="1" /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;'
        }
        if (divsInthepage[i].innerHTML.indexOf("&lt;h3&gt;Optional&lt;span", 1) > 1 && divsInthepage[i].innerHTML.indexOf("requiredBlock", 0) < 1)
        {
            divsInthepage[i].innerHTML = ''
        } {
    }
}
</apex:page>

It seems that any occurence of "<" or "&" is triggering the issue. I discovered that setting the version number for the file to 18 fixed the issue.  What can I do to format the javascript so that it does not cause validation errors?

  • October 10, 2011
  • Like
  • 0
The class attribute isn't being set when I use outputField. As you can see in my example the HTML output is missing the class attribute which was set to XXX


My Page:


<apex:page controller="TestPageCon">
<apex:outputField styleClass='XXX' value='{!field.amount}'/>
</apex:page>


My Controller:


public class TestPageCon {
public Opportunity getField() {
return [select id, amount from Opportunity limit 1];
}
}


Actual HTML output:


<span id="j_id0:j_id1">$60,000.00</span>

Where did my XXX go?

I have an output field in a pageBlock section and I am trying to make the value red. The field is Amount on opportunity but I am using it as a proxy variable to hold a currency total. Any idea why my styles aren't working?

Code:
<apex:pageBlockSectionItem >
<apex:outputLabel value="Total NSP Amount" for="nsptotal"/>
<apex:outputField value="{!masterDiscount.Amount}" id="nsptotal" style="color: red; font-weight: bold"/>
<apex:pageBlockSectionItem >

Thanks,
Jason