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
rajesh k 10rajesh k 10 

How to call a controller method using output link?

Fabien TaillonFabien Taillon
Use commandLink instead of outputLink:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_commandLink.htm

rajesh k 10rajesh k 10
Hi,
           Hi Prem,
                      using <apex:outputlink> pagereference working. But When isErro is true how to call  below i extended class method  like doback()

String ipAddress = ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');
      isError = isNewUser(cid, ipAddress);            //CurrentUserIp Method


Hi,
         This is my page
<apex:page controller="Myctrl">
<apex:form id="formid">
<script>
function MyFunction(iserror){
     alert(iserror);
     if(iserror == true)
     {
     alert('Hello');

    }
}
function MyFunction1(iserror,id,cid){
     alert(iserror);
     if(iserror == true)
     {
     alert('Hello');

    }
    window.open('/apex/RecordDetailPage?RecId=' + id + '&ConId=' + cid);
}
</script>

<apex:commandButton value="Back" action="{!doBack}" oncomplete="MyFunction({!isError})" rerender="formid"/>
<apex:repeat value="{!listRecords}" var="UR">
          <tr>
         <td>
                  <apex:outputLink onclick="MyFunction1({!isError},{!UR.Id},{!cid})">{!UR.Number__c}</apex:outputLink>
        </td>
    </tr>
</apex:repeat>
</apex:form>
</apex:page>

Controller:
=========

public class Myctrl extends CurrentUserIp {

         public DropSave__c pdfObject{get; set;}

        public Boolean isError{get; set;}

public ApexPages.StandardSetController con {
        get {
                if(con == null) {
              
                    con = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Id,Name,Number__c  FROM DropSave__c ]));
                                      
                }
                return con;
        }
        set;
    }
public Myctrl()
{

String ipAddress = ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');
      isError = isNewUser(cid, ipAddress);
cid = ApexPages.currentPage().getParameters().get('conid');
}
public PageReference doBack()
        {
             String ipAddress = ApexPages.currentPage().getHeaders().get('X-Salesforce-SIP');
                 isError = isNewUser(cid, ipAddress);
               if(isError == false){ PageReference ref=new PageReference('/apexBackpage');
                return ref.setRedirect(true);}return null;
        }
}


NOTE:Here       isNewUser(cid, ipAddress); is related to "CurrentUserIp" class.Using this class Every time i will check My Field Ipaddress(This field is there in my contact object) and Current system ipaddress.



please help me............
Cloud_forceCloud_force
you can call controller method using action attribute of command lin 

<apex: commnad link action="{!methodname}"/>

thanks,
http://www.forcexplore.com/2014/08/visualforce-and-apex-tutorial-for-beginners.html
Yash JagtapYash Jagtap
@Cloud_force, the link you shared is changed, mentioned below is updated one.

http://forcexplore.blogspot.com/2014/08/visualforce-and-apex-tutorial-for-beginners.html 

Thanks.