function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JasonGablerJasonGabler 

actionFunction causing Javascript error when using oncomplete or reRender

I'm pretty sure I'm just trying to do some straightforward AJAX here.  When I use oncomplete or reRender widhin actionFunction, I see the following Javascript error (via Firebug):

 

element.selectNodes is not a function

 

And the Javascript engine basically choke at this point.   The error happens within the Salesforce AJAX library: 

3_3_0.GAorg.ajax4jsf.javascript.AjaxScript on line 101.  This occurs at a point where the code does a try{selectNodes()} to figure out of it should run either selectNodes() or getElementsByTagName().  If the try{} fails, the catch(){} should run the getElementsByTagName().

 

I've seen this in FF3.5.6, though things seem to work fine in FF3.0.16.   In IE7 and IE8 I get data back inconsistently.  Generally if I put trash data in yahooProduct and then try good data, I will things will work fine.  However, until I do this special sequence, the AJAX will not work in IE.  I know, this part this sounds like a bug of my own making... probably is... but for the life of me I cannot pin point it.  The code isn't all that complicated.

 

If I take out oncomplete and reRender, I get no Javascript errors.  Of course, I have no way to see if the AJAX did anything, either.

 

Strangely, I can find no references to this issue on the discussion boards.  I'm not doing anything particularly fancy.  Anything stand out in my code below?

 

 

My Visualforce:

 

 

<apex:page standardController="Purchase__c" extensions="PurchaseExtension" recordSetVar="purchases" title="New Purchase">

<apex:sectionHeader title="Purchase Edit" subtitle="New Purchase"/>

<apex:messages layout="table"/>

<style>
td.labelCol {
vertical-align: middle;
}
</style>
<apex:form styleclass="p-form" id="p_form">

<apex:pageBlock title="Purchase Edit" mode="edit">

<apex:actionFunction name="updateProductDetails" action="{!updateProductDetails}" immediate="true" reRender="field_table">
<apex:param name="firstParam" assignTo="{!yahooProduct}" value="" />
</apex:actionFunction>

<apex:outputPanel id="field_table">
<table cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td class="labelCol requiredInput">Contact</td>
<td class="dataCol col02" style="height:20px;">
<apex:inputField value="{!p.Contact__c}" required="true"/>
</td>
</tr>
<tr>
<td class="labelCol requiredInput">Purchase Date</td>
<td class="dataCol col02">
<apex:inputField value="{!p.Purchase_Date__c}" required="true"/>
</td>
</tr>
<tr>
<td class="labelCol requiredInput">Yahoo! Product</td>
<td class="dataCol col02">
<apex:inputField value="{!p.Yahoo_Product__c}" required="true" onchange="updateProductDetails(this.value)" />
</td>
</tr>
<tr>
<td class="labelCol requiredInput">Item Description</td>
<td class="dataCol col02">
<input disabled="true" id="item-desc" type="text" value="{!productDesc}"/>
</td>
</tr>
<tr>
<td class="labelCol requiredInput">Item Price</td>
<td class="dataCol col02">
<input disabled="true" id="item-price" type="text" value="{!productPrice}"/>
</td>
</tr>
<tr>
<td class="labelCol requiredInput">Quantity</td>
<td class="dataCol col02">
<apex:inputField value="{!p.Quantity__c}"/>
</td>
</tr>
<tr>
<td class="labelCol requiredInput">Total</td>
<td class="dataCol col02">
<input id="total" type="text"/>
</td>
</tr>
<tr>
<td class="labelCol requiredInput">Ship Date</td>
<td class="dataCol col02">
<apex:inputField value="{!p.Ship_Date__c}" />
</td>
</tr>
</tbody>
</table>
</apex:outputPanel>

<apex:inputHidden value="{!p.Name}"/>
<apex:inputHidden value="{!p.Contact__c}"/>

<apex:commandButton value="Save" action="{!save}"/>
<apex:commandButton value="Cancel" action="{!cancel}"/>

</apex:pageBlock>

</apex:form>

</apex:page>

 

 

 

 and my Extension:

 

 

public class PurchaseExtension {
public Purchase__c p {
get {
if (p == null)
p = new Purchase__c();
return p;
}
set;
}

public Contact c {
get {
String contactId = Apexpages.currentPage().getParameters().get('id');
if (c == null) {
c = [select c.FirstName,c.LastName from Contact c where c.id = :contactId];
}
return c;
}
set;
}


String productDesc, productPrice;
public String getProductDesc() {
return productDesc;
}
public String getProductPrice() {
return productPrice;
}

String yahooProduct = 'init';
public void setYahooProduct(String p) {
yahooProduct = p;
}
public String getYahooProduct() {
return yahooProduct;
}

public PageReference updateProductDetails() {
if (yahooProduct != null) {
List<Yahoo_Products__c> yp = [select p.Item_Description__c,p.Price__c from Yahoo_Products__c p where p.Name = :yahooProduct];
if (yp.size() > 0) {
productDesc = yp[0].Item_Description__c;
productPrice = ''+yp[0].Price__c;
} else {
productDesc = 'No product details avalable';
productPrice = 'No product details avalable';
}
} else {
productDesc = 'No product?';
productPrice = 'No product?';
}
return null;
}

public PurchaseExtension(ApexPages.StandardSetController ctlr) {
p.Contact__c = c.Id;
p.Purchase_Date__c = Date.today();
}

public PageReference save() {
PageReference pr = null;
// stub
return pr;
}

public PageReference cancel() {
// stub
return null;
}

public static testMethod void testSave() {
Test.setCurrentPage(new PageReference('/?id=003A0000004JoTl'));
List<Purchase__c> pList = new List<Purchase__c>();
ApexPages.StandardSetController ctlr = new ApexPages.StandardSetController(pList);
PurchaseExtension e = new PurchaseExtension(ctlr);
e.c = new Contact(FirstName = 'Foo', LastName = 'Bar');
e.p.Yahoo_Product__c = 'a04A000000101DT';
e.save();
System.assertNotEquals(e, null);
}

public static testMethod void testUpdateProduct() {
Test.setCurrentPage(new PageReference('/?id=003A0000004JoTl'));
List<Purchase__c> pList = new List<Purchase__c>();
ApexPages.StandardSetController ctlr = new ApexPages.StandardSetController(pList);
PurchaseExtension e = new PurchaseExtension(ctlr);
e.setYahooProduct('HistProd');
e.updateProductDetails();
String newDesc = e.getProductDesc();
System.assertNotEquals(newDesc, null);
}
}

 

 

 

 

Message Edited by JasonGabler on 01-05-2010 11:13 AM
Message Edited by JasonGabler on 01-05-2010 02:37 PM
cpebre3cpebre3

I experience the same issue in IE8.... IE7 is working fine.

 

Here is the error detail:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.30729; .NET CLR 3.5.30729)
Timestamp: Fri, 22 Jan 2010 04:57:52 UTC


Message: Invalid argument.
Line: 139
Char: 96
Code: 0
URI: https://c.eu0.visual.force.com/faces/a4j/g/3_3_0.GAorg.ajax4jsf.javascript.AjaxScript

 

 

It occurs intermitently, after few clicks. My page contains a lot of actionsupport fields.

 

thanks

BlasgenBlasgen
Having the same issue.  I'm thinking right now that it could be that I'm not passing a value to the actionScript but I should be.  Going to do more testing and will get back.  Wasn't an issue two weeks ago, but now shows up.  And it's inconsistent as people point out.
Doug ACFDoug ACF

I'm seeing the same error.  Did anyone ever find a root cause or workaround?

voutchervoutcher

I've also come across this issue using FF 3.6.6. I always get this error (via firebug) but also seem to be having a strange issue where if I have an inputtext box in the area to be rerendered the commandlink doesn't seem to run properly and the response just returns the same data.

 

Don't know if this is related.

BlasgenBlasgen

I've written my own workaround for many of these issues.  Tell me which line you're having an issue on and I'll see if I have a fix for it.  The javascript is just bad and I'm pushing Salesforce to update certian pieces.  But for the time being, I have some solutions.

voutchervoutcher

I currently have a list of organizations with a view apex:commandlink. This is combined with an apex:param to reference it to the relevant organization. I then rerender a pane on the right hand side.

 

Depending on what kind of organization it is it may appear read only (just using apex:outputtext) or it might be editable (using apex:inputtext). If I use any inputext fields I get an error coming back after I click the View button. I have just managed to get some kind of error out of the system: "j_id0:PublicSearchTemplate:form:j_id77: An error occurred when processing your submitted information.".

 

This is really confusing, it works perfectly provided I don't have any inputfields in the rerendered pane.

 

Thanks for any solutions you can provide.

SteveBowerSteveBower

Care to post your code, I'm curious at to what's causing this.  Best, Steve.

NBlasgenNBlasgen

So for issues with line 139,96 (an error with SetAttribute), load the following javascript at the end of the page:

 

 

A4J.AJAX.XMLHttpRequest.prototype._copyAttribute = function (src, dst, attr) {
    var value = src.getAttribute(attr);
    if (value) {
        try {
            dst.setAttribute(attr, value);
        } catch (err) {
            //alert('Error with Salesforce: ' + err.description + '\nattr: ' + attr + '\n');
        }
    }
};

 

All I do is add a try { } catch { } statement to it.  If the attribute doesn't exist for some reason, it just moves on to the next one.  In the current Salesforce version, it terminates.

 

voutchervoutcher

I believe I've discovered my specific problem. As far as I can tell it was because I was trying to display an Account object in the inputtext fields. I'm guessing that the field level security was causing an error (not a useful error). I was only expecting the field level security to cut in when I tried to save, not on load.

calvin_nrcalvin_nr

@NBlasgenYou sir are awesome...I had so much grief with this. And this fix helped solve my problem :)

 

If you are in Dallas, TX anytime beer is on me.