1

To test Salesforce function, I develop a Visualforce page which use a Visualforce component.

In the Visualforce page, I call the Visualforce component and in the Visualforce component, I have an attribution which an instance of my Visualforce controler and which is transmitted by the Visuaforce page.

This is my code :

Controler :

public without sharing class TestController {

    public String theHour{get; set;}
    public Double random{get; set;}
    public TestController myController { get { return this; } }

    public TestController(){
        this.theHour = this.setTheHour();

        this.random = Math.random();

        System.debug('*** On charge la page !');
    }

    public TestController(ApexPages.StandardController sc) {}

    public String setTheHour(){
        DateTime now = DateTime.now();

        return now.hour() + ':' + now.minute() + ':' + now.second();
    }

    public PageReference setHour(){
        this.theHour = this.setTheHour();

        System.debug('*** theHour : ' + this.theHour);

        return NULL;
    }
}

Visualforce component :

<apex:component allowDML="true">

    <apex:attribute name="myController" type="TestController" required="true" description="handle to the pkb controller" />

    <apex:form id="myForm">

    </apex:form>

</apex:component>

I don't understand why but I get this error :

Type is not visible : testcontroller

And in the controler, I have a variable TestController which is public.

Why this error please? Aurélien

2
  • And if you add controller="TestController" in <apex:component> tag ?
    – SF_user
    Apr 23, 2015 at 9:42
  • It doesn't work, I still get the same error message. :/
    – Oupat
    Apr 23, 2015 at 9:57

2 Answers 2

1

I don't know why but I get this error when I develop with the Eclipse software but I don't get this erreor when I develop in Salesforce.. ?

So, my development works in Salesforce..

This is my final code : Visualforce page :

<apex:page controller="TestController">

    <c:TestComponent myController="{!myController}" />

</apex:page>

The controller :

public without sharing class TestController {

  public String theHour{get; set;}
  public Double random{get; set;}
  public TestController myController { get { return this; } }

  public TestController(){
    this.theHour = this.setTheHour();

    this.random = Math.random();
  }

  public TestController(ApexPages.StandardController sc) {}

  public String setTheHour(){
    DateTime now = DateTime.now();

    return now.hour() + ':' + now.minute() + ':' + now.second();
  }

  public PageReference setHour(){
    this.theHour = this.setTheHour();

    System.debug('*** theHour : ' + this.theHour);

    return NULL;
  }
}

The component :

<apex:component allowDML="true">

    <apex:attribute name="myController" type="TestController" required="true" description="handle to the pkb controller" />

    <apex:form id="myForm">

        <apex:actionFunction name="setHour" action="{!myController.setHour}" rerender="testSection1,testSection2">
            <apex:param name="setHour" value="" />
        </apex:actionFunction>

        <apex:pageBlock id="testPanel">

            <apex:pageBlockSection id="testSection1">
                <apex:outputText value="{!myController.random}" />
            </apex:pageBlockSection>

            <apex:pageBlockSection id="testSection2">
                <apex:outputText value="{!myController.theHour}" />
            </apex:pageBlockSection>


            <apex:pageBlockSection id="testSection3">
                <apex:outputLink value="#" id="contactusForm" onclick="setHour(); return false;" rendered="true" >Click me !</apex:outputLink>
            </apex:pageBlockSection>
        </apex:pageBlock>

    </apex:form>
</apex:component>

Thanks for your help. :)

0

You can't set the type with your object. You need to set type="sObject" like this :

<apex:component allowDML="true" controller="TestController">
    <apex:attribute name="myController" type="sObject" required="true" description="handle to the pkb controller" />

See the doc to know what type you can set :

https://www.salesforce.com/docs/developer/pages/Content/pages_compref_attribute.htm

2
  • I readed the documentation. It said : Custom Apex types (classes) TestController is a Visualforce Controller.
    – Oupat
    Apr 23, 2015 at 10:24
  • Ok, and if you replace public without sharing class TestController by public with sharing class TestController and keep controller="TestController"?
    – SF_user
    Apr 23, 2015 at 10:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .