You need to sign in to do that
Don't have an account?
Scott Stanell
CommandButton Populate Field in PageBlockTable
Hello, I have a VF page containing a pageBlockTable with a number of rows. Each row has a command button added to it. I am trying to learn how to populate one of the fields on the row containing the command button when it is clicked. In the code below, I would just like to place a sample value in the comment field just to the left of the Start button. I've seen some jQuery samples, but can't seem to get the code to update only the comment field for the row that has the button.
Thank you in advance.
Scott
<apex:pageBlockTable id="itemRows" value="{!woLineItems }" var="woitem"> <apex:column headerValue="Line Item">{!woitem.LineItemNumber}</apex:column> <apex:column headerValue="Description">{!woitem.Description}</apex:column> <apex:column headerValue="Comments"><apex:inputField value="{!woitem.Comments__c}"/></apex:column> <apex:column headerValue="Start"><apex:commandButton value="Start"/></apex:column> </apex:pageBlockTable>
Thank you in advance.
Scott
You will have to update your code as follows:
Currently, you have not assigned any action to the command button so the page doesn't know the action to be performed when the button is clicked.YOu are also going to rerender the pageblock once the control comes back to the page from the controller using command button property : rerender -please update your page as shown below:
<apex:page controller=“Democontroller" >
<apex:pageBlockTable id="itemRows" value="{!woLineItems }" var="woitem"> <apex:column headerValue="Line Item">{!woitem.LineItemNumber}</apex:column>
<apex:column headerValue="Description">{!woitem.Description}</apex:column>
<apex:column headerValue="Comments">
<apex:inputField value="{!woitem.Comments__c}"/></apex:column> <apex:column headerValue="Start">
<apex:commandButton value=“Start” action={!save} reRender="itemRows" /></apex:column> </apex:pageBlockTable>
Controller definition:
public class DemoController{
public Pagereference save(){
//Code to save the table row content in the respective Sobject
return null;
}
}