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
NaypersMclgxNaypersMclgx 

Function in a pageBlockTable

Hi!, I'd like to know if is possible to have a function in a pageBlockTable that return something to print in a column, I would also like to add a parameter in this function like the example. Anyone know if this can be done, and how?,

 

thank you!.

 

function in a pageBlockTable

 

My code:

 

<apex:page sidebar="true" controller="ListOpportunities"> 
    <apex:outputPanel rendered="{!showOpportunities}">
        <apex:form >
            <apex:pageBlock title="{!userName} Opportunities">

                <apex:pageBlockTable value="{!myObjectOpportunities}" var="opp">
				
                    <apex:column headerValue="Name" >
                        <apex:outputText value="{!opp.name}" />
                    </apex:column> 
                    
                    <apex:column headerValue="Amount" >
                        <apex:outputText value="{!opp.amount}" />
                    </apex:column> 
					
		    <apex:column headerValue="stageName" >
                        <apex:outputText value="{!opp.stageName}" />
                    </apex:column> 
                    
		    <apex:column headerValue="Id" >
                        <apex:outputText value="{!opp.id}" />
                    </apex:column> 
					
 <apex:column headerValue="Custom Field" > <apex:outputText value="validateOpp(opp.id)" /> </apex:column> 

                </apex:pageBlockTable> 
            </apex:pageBlock>
        </apex:form>
    </apex:outputPanel>
</apex:page>

 

calvin_nrcalvin_nr

Try this...

 

1. Use apex:actionFunction (Documentation) to define your function. use Apex:Param to pass in parameters.

2. Write the function using Javascript

3. Invoke where you need to.

 

It should however be enclosed within <Apex:form> which you are using anyways.

 

The above link also has a great example.


- Calvin

 

 

sfdcfoxsfdcfox

You could use a wrapper class:

 

<apex:page sidebar="true" controller="ListOpportunities"> 
    <apex:outputPanel rendered="{!showOpportunities}">
        <apex:form >
            <apex:pageBlock title="{!userName} Opportunities">

                <apex:pageBlockTable value="{!myObjectOpportunities}" var="line">
				
                    <apex:column headerValue="Name" >
                        <apex:outputText value="{!line.opp.name}" />
                    </apex:column> 
                    
                    <apex:column headerValue="Amount" >
                        <apex:outputText value="{!line.opp.amount}" />
                    </apex:column> 
					
		    <apex:column headerValue="stageName" >
                        <apex:outputText value="{!line.opp.stageName}" />
                    </apex:column> 
                    
		    <apex:column headerValue="Id" >
                        <apex:outputText value="{!line.opp.id}" />
                    </apex:column> 
					
 <apex:column headerValue="Custom Field" > <apex:outputText value="{!line.validateopp}" /> </apex:column> 

                </apex:pageBlockTable> 
            </apex:pageBlock>
        </apex:form>
    </apex:outputPanel>
</apex:page>

 And the related controller:

 

public with sharing class ListOpportunities {
  public wrapper[] getmyobjectopportunities() {
     wrapper[] wrappers = new wrapper[0];
     for(opportunity o:...) {
       wrappers.add(new wrapper(o));
     }
     return wrappers;
  }

  public class wrapper {
    public wrapper(opportnity o) {
      opp = o;
    }
    public opportunity opp { get; set; }
    public string validateopp() {
      // Do something with opp here, return a string
    }
}