Tuesday 15 July 2014

Use of Param Tag and Command link:-

 We have another scenario, i.e As users select the account, by clicking the name of the account, a message is displayed alerting which account was selected.

 <apex:page controller="fifthinterview">
  <apex:form >
      <apex:pageBlock title="Interview Five" id="Test">
         <apex:pageMessages > </apex:pageMessages>
     
         <apex:pageBlockTable value="{!Data}" var="acc">
            <apex:column >
                <apex:commandLink value="{!acc.name}" action="{!Calling}" reRender="Test">
                    <apex:param name="Txt" value="{!acc.id}"/>
                </apex:commandLink>
            </apex:column>
            <apex:column value="{!acc.Name}"/>
            <apex:column value="{!acc.BillingState}"/>
            <apex:column value="{!acc.Phone}"/>
            <apex:column value="{!acc.Website}"/>
          </apex:pageBlockTable>
      </apex:pageBlock>
  </apex:form>
</apex:page>


 public class fifthinterview{
    public fifthinterview(){
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,' Select an Account by Clicking its name.'));
    }
    List<Account> Varacc;
    public List<Account> getData()
    {
        string str1=Apexpages.currentpage().getParameters().get('id');
        Varacc =[Select id,Name,BillingState,Phone,Website from Account];      
        if(varacc.size()>0)
        {
            return Varacc;
        }
        return null;
    }
    public void Calling() {
        string str1=Apexpages.currentpage().getParameters().get('txt');
        Account varacc=[select id,name from Account where id=:str1];
        String ex=varacc.name;
        {
             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,' You have Selected--> '+varacc.name+'-Organization'));
        }
    }   
}

No comments:

Post a Comment