• Nerea Isabel González Gutiérrez 8
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi all!
My aim is showing the pageBlock named iconGallery, when the user click on the commandLink "Show Gallery". If I put the "loadImage" method's code inside Constructor, everything goes perfect. So I wonder if the problem is between the Controller and VF page.

VF page:
<apex:page id="NewAchievement" controller="NewAchievement_Controller">
  
  <!-- Import Component -->
    <c:loadingSpinner />
  
  <!-- Page Header -->
  <apex:sectionHeader title="Achievement Edit" subtitle="New Achievement"/>
 
  <!-- Begin Form -->
  <apex:form >

    <apex:actionFunction action="{!loadImages}" name="loadImages" reRender="iconGallery" oncomplete="hideLoadingDialog();" />
        
    <apex:pageBlock title="Achievement Edit" mode="edit">
        
        <!-- Button Section -->
        <apex:pageBlockButtons location="top">
          <apex:commandButton value="Save" action="{!save}" />
          <apex:commandButton value="Save & New" action="{!saveNew}" />
          <apex:commandButton value="Cancel" action="{!cancel}" />
        </apex:pageBlockButtons>
        
        <!-- Fields -->
        <apex:pageBlockSection columns="1" showHeader="true" title="Information">
          <apex:inputField value="{!achievement.Name}" required="true" />
          <apex:inputField value="{!achievement.Category__c}" required="false" />
          <apex:inputField value="{!achievement.Points__c}"  required="true" />
          <apex:inputField value="{!achievement.Validation_Criteria__c}" required="true" style="width: 300px"/>
        </apex:pageBlockSection>
        
        <!-- Icon Selection -->
        <apex:pageBlockSection title="Select Icon">
          <apex:commandLink value="Show gallery"
                            action="{!loadImages}"
                            reRender="iconGallery"
                            onclick="showLoadingDialog();"
                            oncomplete="hideLoadingDialog();" />

          <apex:image value="https://eu6.salesforce.com/servlet/servlet.FileDownload?file=01558000000UI88" />
        </apex:pageBlockSection>
    </apex:pageBlock>

    <!-- Icon Gallery -->

    <apex:pageBlock title="Icon Gallery" id="iconGallery" rendered="{!isClicked}">
                <apex:repeat value="{!allLinks}" var="item">
                    <apex:outputLink value="http://www.google.es">
                        <apex:image onclick="String" value="{!item}" style="padding-right: 10px; padding-bottom: 10px"/>
                    </apex:outputLink>
                </apex:repeat>
    </apex:pageBlock>
  </apex:form>
</apex:page>

Controller:
 
public class NewAchievement_Controller {
	
    public Achievement__c achievement {get; set;}
    public List<Document> allImages {get; set;}
    public List<String> allLinks {get; set;}
    public Boolean isClicked {get; set;}

    public NewAchievement_Controller () {

        allImages = new List<Document>();
        allLinks = new List<String>();
        isClicked = false;
    }

    public PageReference saveNew() {
    
        try { 
         insert achievement; 
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }   
        return (new ApexPages.StandardController(new Achievement__c())).edit();        
    }
    
    public PageReference cancel() {
       
        return (new ApexPages.StandardController(achievement).view());        
    }
    
    public PageReference save() {
        try {
            upsert(achievement);
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
        PageReference redirectSuccess = new ApexPages.StandardController(achievement).view();
        return (redirectSuccess);
    }

    public PageReference loadImages() {

         //LOAD EXISTING IMAGES (16x16)
        allImages = [SELECT Id FROM Document WHERE FolderId = '00l58000000hBuj'];

        String s = 'https://eu6.salesforce.com/servlet/servlet.FileDownload?file=';
        
        for(Integer i=0; i < (allImages.size()-106); i++) {

            Document d = allImages.get(i);
            allLinks.add(s + String.valueOf(d.Id));
        }

        isClicked = true;

        return null;
    }
}

Thank you in advance!
 
Hi all!
My aim is showing the pageBlock named iconGallery, when the user click on the commandLink "Show Gallery". If I put the "loadImage" method's code inside Constructor, everything goes perfect. So I wonder if the problem is between the Controller and VF page.

VF page:
<apex:page id="NewAchievement" controller="NewAchievement_Controller">
  
  <!-- Import Component -->
    <c:loadingSpinner />
  
  <!-- Page Header -->
  <apex:sectionHeader title="Achievement Edit" subtitle="New Achievement"/>
 
  <!-- Begin Form -->
  <apex:form >

    <apex:actionFunction action="{!loadImages}" name="loadImages" reRender="iconGallery" oncomplete="hideLoadingDialog();" />
        
    <apex:pageBlock title="Achievement Edit" mode="edit">
        
        <!-- Button Section -->
        <apex:pageBlockButtons location="top">
          <apex:commandButton value="Save" action="{!save}" />
          <apex:commandButton value="Save & New" action="{!saveNew}" />
          <apex:commandButton value="Cancel" action="{!cancel}" />
        </apex:pageBlockButtons>
        
        <!-- Fields -->
        <apex:pageBlockSection columns="1" showHeader="true" title="Information">
          <apex:inputField value="{!achievement.Name}" required="true" />
          <apex:inputField value="{!achievement.Category__c}" required="false" />
          <apex:inputField value="{!achievement.Points__c}"  required="true" />
          <apex:inputField value="{!achievement.Validation_Criteria__c}" required="true" style="width: 300px"/>
        </apex:pageBlockSection>
        
        <!-- Icon Selection -->
        <apex:pageBlockSection title="Select Icon">
          <apex:commandLink value="Show gallery"
                            action="{!loadImages}"
                            reRender="iconGallery"
                            onclick="showLoadingDialog();"
                            oncomplete="hideLoadingDialog();" />

          <apex:image value="https://eu6.salesforce.com/servlet/servlet.FileDownload?file=01558000000UI88" />
        </apex:pageBlockSection>
    </apex:pageBlock>

    <!-- Icon Gallery -->

    <apex:pageBlock title="Icon Gallery" id="iconGallery" rendered="{!isClicked}">
                <apex:repeat value="{!allLinks}" var="item">
                    <apex:outputLink value="http://www.google.es">
                        <apex:image onclick="String" value="{!item}" style="padding-right: 10px; padding-bottom: 10px"/>
                    </apex:outputLink>
                </apex:repeat>
    </apex:pageBlock>
  </apex:form>
</apex:page>

Controller:
 
public class NewAchievement_Controller {
	
    public Achievement__c achievement {get; set;}
    public List<Document> allImages {get; set;}
    public List<String> allLinks {get; set;}
    public Boolean isClicked {get; set;}

    public NewAchievement_Controller () {

        allImages = new List<Document>();
        allLinks = new List<String>();
        isClicked = false;
    }

    public PageReference saveNew() {
    
        try { 
         insert achievement; 
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }   
        return (new ApexPages.StandardController(new Achievement__c())).edit();        
    }
    
    public PageReference cancel() {
       
        return (new ApexPages.StandardController(achievement).view());        
    }
    
    public PageReference save() {
        try {
            upsert(achievement);
        } catch(System.DMLException e) {
            ApexPages.addMessages(e);
            return null;
        }
        PageReference redirectSuccess = new ApexPages.StandardController(achievement).view();
        return (redirectSuccess);
    }

    public PageReference loadImages() {

         //LOAD EXISTING IMAGES (16x16)
        allImages = [SELECT Id FROM Document WHERE FolderId = '00l58000000hBuj'];

        String s = 'https://eu6.salesforce.com/servlet/servlet.FileDownload?file=';
        
        for(Integer i=0; i < (allImages.size()-106); i++) {

            Document d = allImages.get(i);
            allLinks.add(s + String.valueOf(d.Id));
        }

        isClicked = true;

        return null;
    }
}

Thank you in advance!