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
Big EarsBig Ears 

<apex:param> in tables seemingly producing inconsistent results

I have a table on a Visualforce page where the first two columns have buttons that can edit or delete the corresponding rows. Both buttons use essentially the same code and call very similar APEX code. However, one works, and the other does not:

 

 Works:

 

VISUALFORCE

 

<td>

<apex:commandbutton action="{!edit}" value="Edit" rerender="itemList">

<apex:param name="editid" value="{!rowitem.Id}"/>

</apex:commandbutton>

</td>

 

APEX CODE

 

public PageReference edit() {

String editid = getParam('editid');

editItem = [SELECT id, Name,Total_Price__c,Quantity__c, Description__c,Agreed_Carriage__c,Agreed_Price__c,Reference__c,Purchase_Order__c FROM SFDC_Purchase_Requisition__c WHERE Id=:editid];

return null;

}

  

 DOESN'T WORK

VISUALFORCE

 

<td>

<apex:commandbutton action="{!del}" value="Del">

<apex:param name="delid" value="{!rowitem.Id}"/>

</apex:commandbutton>

</td>

 

APEX CODE

 

public PageReference del() {

try {

String delid = getParam('delid');

SFDC_Purchase_Requisition__c item = [SELECT Id FROM SFDC_Purchase_Requisition__c WHERE Id=:delid];

delete item;

} catch (Exception e) {

ApexPages.addMessages(e);

}

return null;

}

 

 The error I get is a standard "List has no rows for assignment to SObject", due to the fact that it seems to think that "delid" is a null string.

 

I have added debug logs to each instance of Apex that output the current page. In the sample that works, the parameter "editid "can be seen and is correctly formed within the url of the current page.

 

Oddly, when debugging the code that doesn't work, it seems that the parameter isn't correctly passed into the url. I was able to find the {!rowitem.id} but it isn't linked to the name "delid". Instead it seems to be linked to what must be a Salesforce code name which looks something like:

 

 

j_id0%3Aj_id28%3Aj_id44%3Aj_id46%3A0%3Aj_id66=a0qR0000000JBkNIAW // a0qR0000000JBkNIAW is the rowitem id

 

I've also put in other test parameters and found a similar occurance. 

 

The table is formed from nested  <tr> and <td> tags and in all other ways performs as expected. I was just wondering if anybody knew of a reason behind this?

 

 

Message Edited by Big Ears on 07-14-2009 09:50 AM
ESES

Salesforce also has a query param called delid, so may be the parameter gets preprocessed by SFDC servers. Try renaming your parameter to something else,

 

for example:BigEars_delId

 

 

 

Big EarsBig Ears

Thanks for your response!

 

Unfortunately, that's not solved the problem. i wish I could report better news.

 

Interestingly, when I change the <apex:param> name away from "delid" to something else (I used name="BlahBlah"), the replacement name doesn't appear in the system.debug log of the page url.

 

I've also moved the command button outside of the table to see if that is affecting it (I'd heard there may be some bugs around table and passing of parameters), but that doesn't seem to fix it, either.

 

It simply seems as though the <apex:param> tag isn't doing it's job in this circumstance.

 

 

Big EarsBig Ears

Further to this issue,

 

I've found that the problem only occurs when including an <apex:detail> at the top of the page of code. When removed, and the <apex:commandbutton> tags are replaced with <apex:commandlink>, the code works.

 

The <apex:detail> tag refers to a parent object of the list of SObjects I'm manipulating in the table. 

 

I've also tried building the detail section manually, but that also causes the problem (as soon as I make a reference to the parent object)

 

Therefore the problem lies elsewhere in the code, but I'm not sure how or why.

Message Edited by Big Ears on 07-16-2009 05:20 AM
Message Edited by Big Ears on 07-16-2009 05:21 AM
Message Edited by Big Ears on 07-21-2009 08:09 AM
JohannesBorrmanJohannesBorrman

i really wonder why this happens. having the same issue and don't like using commandlinks because now i have to investigate how to style them like a button. darn!

 

anybody got a solution for that? i really hope i do something wrong!

 

regards, johannes

d3developerd3developer

I've had a lot of problems like this. Most seem to be caused by multiple items of the same type on the page. What I do in most cases is include whatever fields I need to set in a separate JQuery-based modal dialog box which is rerendered each time it is called.

 

The values are always correctly assigned that way.

JohannesBorrmanJohannesBorrman
could you post an example of this?
d3developerd3developer

<apex:includeScript value="{!URLFOR($Resource.JQuery_UI,'jquery-ui-1/js/jquery-1.3.2.min.js')}"/> <apex:includeScript value="{!URLFOR($Resource.JQuery_UI,'jquery-ui-1/js/jquery-ui-1.7.1.custom.min.js')}"/> <apex:stylesheet value="{!URLFOR($Resource.JQuery_UI,'jquery-ui-1/css/smoothness/jquery-ui-1.7.1.custom.css')}"/> <script type="text/javascript"> $(function(){ $("#addAnswer").dialog({ autoOpen: false, modal: true, closeable: false, resizable: false, width: 600 }); }); </script> ... <apex:repeat value="{!qi.SurveyQuestionAnswers1__r}" var="ai"> <apex:panelGrid columns="5" width="400px"> ...

</apex:panelGrid>

</apex:repeat> <apex:form > <apex:commandLink oncomplete="$('#addAnswer').dialog('open')" reRender="aa" value="Add Answer"> <apex:param name="randnametofixSFDCbug" value="{!qi.id}" assignTo="{!qid}" /> </apex:commandLink><BR/> </apex:form> ... <!-- This is the content of the modal dialog for adding an answer --> <div id="addAnswer" style="display: none" > <div id="aa"> <apex:outputpanel id="aad"> <h3>My Answer</h3><BR/><BR/> <apex:form > <apex:inputText value="{!at}" title="Answer Text"/><BR/> <apex:commandButton action="{!addAnswer}" oncomplete="$('#addAnswer').dialog('close')" value="Add" rerender="sEdit"/> <apex:commandButton value="Cancel" immediate="true" oncomplete="$('#addAnswer').dialog('close')"/> </apex:form> </apex:outputpanel> </div> <!-- aa --> </div> <!-- addAnswer -->

 

Hopefully that is enough to get you started. As you can see the code is within a nested loop but still works.

 

If you have any questions feel free to post back.

Chirag MehtaChirag Mehta

Gents, 

 

Any solutions?

I am also facing the same issues of making a commandLink work inside a repeat->repeat->td. 

 

 

 

<apex:repeat value="{!listData}" var="l" rendered="{!NOT(ISNULL(listData))}">

<apex:repeat value="{!l.Items}" var="c"><tr>

<td>{!l.Title}</td>

<td>{!c.Description}</td>

<td>{!c.Name}</td>

<td>

<apex:commandLink value="View" action="{!viewId}">

<apex:param assignTo="{!selectedId}" name="selectedId" value="{!c.Id}" />

</apex:commandLink>

</td>

</tr>

</apex:repeat>

 

 

Message Edited by Chirag Mehta on 03-10-2010 10:38 AM