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
MRG73MRG73 

Problems using a commandbutton/commandlink to populate nputtext values with user entered value

I have a pageblock table populated by a wrapper class from a custom controller.  I have a column that has a commandbutton that I need to be able to have the user click and populate the rest of the inputtext values in the row.  For example, if the user enters a value in the first column after the command button I need to default all the inputtext values in that row to the first value.   I have a hidden field where I can keep the row value so I know which row to update that seems to work fine.   I've tried the following options using both commandlink and commandbutton components.

 

1.  Use the action attribute of the command button/link to pass apex:param values to a controller method but the value entered by the user is not yet available.  

 

2.  Use the onclick event of the command button/link to call a javascript function to get the user entered value by using document.getElementById and then calling the function via apex:actionFunction.  Not sure why but the method specified in the action attribute of the apex:actionFunction never fires when done this way. 

 

Does anyone know of a better/easier way to allow the user to click a command button/link in a row and assign the value the user entered in the first inputtext column to the rest of the inputtext values in the row?  I believe the crux of the issue is getting the user entered value to the controller.

 

Thanks in advance for any assistance.

bob_buzzardbob_buzzard

I've used the second method a number of times.  Are you returning false from the onclick handler so that the default postback action doesn't take place?  Otherwise you end up in a strange race condition where your actionfunction submits the form but so does the command button.

MRG73MRG73

Bob - Thanks for the reply.  I tried adding that but it did not make a difference for me.  Here is what I have:

 

The columns (there are additional columns but this should convey the isssue):

<apex:column >
<apex:commandbutton value="copy" rendered="{!target.TargetName <> ''}" onclick="copyrow('{!$Component.col1Value}','{!target.TargetRow}') return false;"/>
</apex:column>
<apex:column id="col1" headerValue="{!col1header}">
<apex:inputText size="{!targetinputwidth}" value="{!target.col1Value}" rendered="{!target.TargetName <> ''}" id="col1Value" />
</apex:column>

 

The js:

function copyrow(rowvalue, currentrow) {
CopyTargetRow(document.getElementById(rowvalue).value, currentrow;
}

 

The actionfunction:

<apex:actionFunction action="{!CopyTargetRow}" name="copytargetrow" >
<apex:param name="RowValue" value="" />
<apex:param name="Row" value="" />
</apex:actionFunction>

 

 

bob_buzzardbob_buzzard

A couple of things:

 

(1) You are missing a closing bracket in the method call:

 

CopyTargetRow(document.getElementById(rowvalue).value, currentrow;

 (2) Javascript is case sensitive - you have named the actionfunction "copytargetrow" but then invoked "CopyTargetRow".

MRG73MRG73

Thanks (I've changed this thing so many times today).  Fixed those issues but same result.

MRG73MRG73

Actually the problem is different now.  The controller method is executing but the parameter values are null.

MRG73MRG73

More specifically when I have the return on the onclick handler set to false the controller method does not execute, when I allow the return the method executes but the parameter values are null.

bob_buzzardbob_buzzard

That still sounds like there is a javascript problem - returning false should stop the form submission through the button and allow the submission through the actionfunction to complete.

 

Are you working in a browser that can display javascript errors? Have you tried adding alerts to the javascript to confirm that your function is being called and that the actionfunction is available?