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
Amoun777Amoun777 

Trying to return the current Row to Apex from a pageBlockTable

I'm using ajax in a VF page via the actionsupport call and can rerender a section (notes) based on the column, but can't see how to determine the current row of a pageBlockTable.  Here's a snippet:
 

VF:

<apex:column headerValue="{!sunTitle}">

    <apex:inputField id="sunday"value="{!hoursList.Sunday__c}" style="width: 40px">

    <apex:actionsupport event="onfocus" action="{!sunNotes}" rerender="notes"/>

    </apex:inputField>

</apex:column>

 

Apex:

public PageReference sunNotes()

{

   refreshTotals();

   currentNote = 'Sunday';

   notesValue = Hours[currentHour].SundayNotes__c;

   noteIsActive = true;

   return null;

}

 

Where currentHour (an integer) would equal the current row in my pageBlockTable, ideally.  Any help you could provide would be seriously appreciated.

 

Thanks!!

Adam

Ron HessRon Hess
i think i need to see more of your page, what is the repeat list ?


you will end up using apex : param inside the action function , where you pass the name= and value= of the current item that has focus

if you can build a simple page using accounts object and post the entire page, that would help greatly.
Amoun777Amoun777

Sure.  I'll post more of the page along with some of my apex code to show what I am trying to do.  I have custom objects called Hours__c (the child rows) and my VF page is an extension of the parent Time_Cards__c object.  I’m in a deadline situation and realize I could crunch this code down quite a bit but I also just started coding in Salesforce a couple months ago so I’m not up to speed yet.  Dreamforce in SF was my introduction and I’ve been living it ever since.

 

My latest (failed) attempt to get the current pageBlockTable row value back to Apex when onfocus or onclick was fired looks like this:


<apex:actionsupport event="onfocus" action="sunNotes('{!Hours.curRow__c}');" rerender="notes"/>

// This does pass a value in (Hours.curRow__c) but does not rerender notes

 

Here's part of the VF page I have so far:

 

<-- misc. header/button code-->

 

The following is the list of days I want to have a dynamically changing Notes section bind to:

<apex:column headerValue="{!sunTitle}">

<apex:inputField id="Sunday" value="{!hoursList.Sunday__c}" style="width: 40px">

<apex:actionsupport event="onfocus" action="{!sunNotes}" rerender="notes"/>

</apex:inputField>

</apex:column>

<apex:column headerValue="{!monTitle}">

<apex:inputField id="monday" value="{!hoursList.Monday__c}" style="width: 40px">

<apex:actionsupport event="onfocus" action="{!monNotes}" rerender="notes"/>

</apex:inputField>

</apex:column>

<apex:column headerValue="{!tueTitle}">

<apex:inputField id="tuesday" value="{!hoursList.Tuesday__c}" style="width: 40px">

<apex:actionsupport event="onfocus" action="{!tueNotes}" rerender="notes"/>

</apex:inputField>

</apex:column>

etc...

then the notes get rendered in the "notes" section:

 

<apex:inputTextarea value="{!notesValue}" id="theTextarea" rows="5" style="width: 100%" rendered="{!noteIsActive}"/>

</apex:pageBlockSection>

</apex:pageBlock>

</apex:form>

</apex:page>

 

Some of my Apex code for this page:

      public PageReference projectFocus()

      {

            refreshTotals();

            noteIsActive = false;

            currentNote = '';

            notesClear();

            return null;

      }

     

      public PageReference billToFocus()

      {

            refreshTotals();

            noteIsActive = false;

            currentNote = '';

            notesClear();

            return null;

      }

 


      // This is what I've been trying to use to get the current row in my handler:

      // public PageReference sunNotes(Integer i)

      //

      // but the following is what I've got complied for now, with no row # passed in:

      public PageReference sunNotes()

      {

      //    currentHour = i; // This is where I'd like to store the current row from my pageBlockTable

 

            refreshTotals();

            currentNote = 'Sunday'; // Keeps the notes associated with Sunday - this is the COL I have already

            notesValue = Hours[currentHour].SundayNotes__c;

            noteIsActive = true;

            return null;     

      }

 

      public PageReference monNotes()

      {

            refreshTotals();

            currentNote = 'Monday';

            notesValue = Hours[currentHour].MondayNotes__c;

            noteIsActive = true;

            return null;

      }

 

      // etc. 

 

 

Thank you so much for your assistance!!

 

Sincerely,

Adam

 

 

Ron HessRon Hess

i don't see the notes section you are trying to rerender. 

it is easier to debug if you use the SRC button when posting  Insert Source Code  if this is missing, you are probably on safari, it shows up on firefox


anyway you can try this :
Code:
<apex:actionsupport event="onfocus" action="{!tueNotes}" rerender="notes">

 <apex:param name="tues" value="{!hoursList.somefield}" />
</apex:actionSupport>

 
then in your controller, you can read the parameter that was bound at the time the event fired.
you do this with :
Code:
currentrow = ApexPages.currentPage().getParameters().get('tues');

 
however this will only work if you have something in your hours list element that you can index on , like ID


i can only guess that the tag theTextarea is enclosed in an output panel with id="notes"

Amoun777Amoun777
That works perfectly!!  Thank you so much for your help Ron!!!
um-dontaskmeum-dontaskme

Ron (or others),

 

Thanks again - I've lost count of the number of times of used your posts to solve a problem.

 

I used the post above to add a commandbutton to each row of a pageBlockTable.  When clicked, it updates a field on the record displayed in that row.  I also asked it to rerender the table, because the updated field value excludes it from the the query results for that table.  Basically, click the "OK" button and drop that item off the table.

 

But, rerendering the pageBlockTable doesn't refresh the list.  I also have a selectList where the user chooses which Opportunity Owner to view.  It also rerenders the table, and that works fine.  Changing away from the current Opportunity Owner and then back in that selectList shows the item has been removed from the pageBlockTable.  They use the same rerender instructions, so I assume the problem involves asking for the rerender from inside the table itself?

 

I've tried moving the id up to the pageBlock and to an outputPanel surrounding it, but the same behavior takes place.  It won't update the list from the commandbutton click. 

 

I've tried to figure out how to call the query that populates the table from the button's action, but that didn't work.  I've tried creating a second query for table contents and trying to force the table to use that instead.  I'm afraid I just know enough to be dangerous.

 

Any ideas?

 

Here's my page:

 

<apex:page controller="displayAtRiskopps" tabStyle="Opportunity">

<apex:form id="AtRiskOppForm">
<apex:outputPanel rendered="true">
<apex:pageBlock >

<apex:panelGrid columns="2">
<apex:selectList id="OppOwner" value="{!oppowner}" multiselect="false" size="1">
<apex:selectOptions value="{!items}"/>
<apex:actionSupport event="onchange" rerender="OppTable"/>
</apex:selectList>
</apex:panelGrid>

<apex:pageBlockTable id="OppTable" value="{!Opps}" var="o" rendered="true">
<apex:column >
<apex:commandButton value="OK"/>
<apex:actionsupport event="onclick" action="{!markReviewed}" rerender="OppTable">
<apex:param name="oppid" value="{!o.id}" />
</apex:actionSupport>
</apex:column>
<apex:column >
<B><apex:outputLink value="/{!o.id}" target="_blank">View</apex:outputLink></B>
</apex:column>
<apex:column headervalue="Opportunity Name" value="{!o.name}"/>
<apex:column headervalue="Stage" value="{!o.Stagename}"/>
<apex:column headervalue="Amount" value="{!o.Amount__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:outputPanel>
</apex:form>
</apex:page>

 And here's the relevant parts of the custom controller:

 

 

    public List<Opportunity> getOpps() {
        OppList = [SELECT id, name, ownerid, account.name, amount__c, StageName, Date_Entered_Current_Stage__c, At_Risk_Review_Date__c, amount, Subscription_Amount__c  
                FROM Opportunity 
                WHERE ownerid = :oppowner AND ((At_Risk_Review_Date__c = null) OR (At_Risk_Review_Date__c < :date.today().addDays(-90))) limit 20];
        return OppList;
        
    }


    public PageReference markReviewed() {
        
        ID oppid = ApexPages.currentPage().getParameters().get('oppid');
        Opportunity reviewOpp = [Select id, At_Risk_Review_Date__c from Opportunity where id = :oppid];
        reviewOpp.At_Risk_Review_Date__c = date.today();
        update reviewOpp;
        return null;
    }