Slide Show using Apex and Visualforce

Visualforce:

<apex:page standardController="Photo__c" extensions="SlideShow" sidebar="false">

  <apex:form >

   
    <center>
 
    <apex:image url="{!tmp}"/> 
     
    <br/>
    <br/>
    <br/>
          
    <apex:commandButton action="{!prev}" value="Previous"/>&nbsp;&nbsp;&nbsp;
    <apex:commandButton action="{!nxt}" value="Next"/>   
   
    </center>
   
  </apex:form>
 
</apex:page>

Apex:

Public Class SlideShow
{
    public List<Photo__c> photo {get; set;}
    public String imageTag {get; set;}
    public String photoUrl {get; set;}
    public Integer strt=0,ed=1,len=0,i=0,indx=0;
   
    public String tmp {get; set;}
   
    public SlideShow(ApexPages.StandardController controller)
    {          
      String sql = 'SELECT image__c FROM Photo__c';
      photo = Database.query(sql);
      imageTag = photo.get(indx).image__c;
     
      strt = imageTag.indexOf('src=',0) + 5;
      ed = imageTag.lastIndexOf('alt=') - 2;
      tmp = imageTag.substring(strt,ed);
    }          
   
    public void prev()
    {
      if(indx != 0)
      {
      indx = indx - 1;
      String sql = 'SELECT image__c FROM Photo__c';
      photo = Database.query(sql);
      imageTag = photo.get(indx).image__c;
     
      strt = imageTag.indexOf('src=',0) + 5;
      ed = imageTag.lastIndexOf('alt=') - 2;
      tmp = imageTag.substring(strt,ed);
      }
    }   

    public void nxt()
    {  
      len = [SELECT COUNT() FROM Photo__c];
      if(indx != (len-1))
      {
      indx = indx + 1;
      String sql = 'SELECT image__c FROM Photo__c';
      photo = Database.query(sql);
      imageTag = photo.get(indx).image__c;
     
      len =imageTag.length();
      strt = imageTag.indexOf('src=',0) + 5;
      ed = imageTag.lastIndexOf('alt=') - 2;
      tmp = imageTag.substring(strt,ed);
      }     
    }       
}

6 comments:

  1. For some reason the next button is not working correctly it throws index out of bounds

    ReplyDelete
  2. It works perfectly for me. Check ur code and mail me if the problem exists. Cheers...

    ReplyDelete
  3. Thanks, it worked perfectly...

    ReplyDelete
  4. I have one image in one field which is url data type and multiple image url's in long text area data type seperated by semicolon. In this case how could I achieve image slider slide show in visualforce page? Can you please help on this...

    ReplyDelete
  5. Hi I would like to login in to this SF to view but I am getting a username or password error. Can you confirm if the username or password above has changed. Thanks!

    ReplyDelete
    Replies
    1. Check this site for slide show

      http://siebel16-developer-edition.na12.force.com/InfallibleTech__SiteHomePage

      Cheers!

      Delete