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
EguiEgui 

Cannot read visualforce attribute from apex controlleur with custom VF component

Hello,

 

I'm facing an issue with a custom VF component and custom apex controlleur, the return value when reading attribute from it is still NULL.

 

Here is the VF component :

 

<apex:component controller="customControlleur"> 
    <apex:attribute name="attribute" description="" assignTo="{!attribute}" type="String"></apex:attribute>
</apex:component>

 

And the controlleur :

 

public class customController {
    
    public String  attribute { get; set; }

    public customController() {
        system.debug('&&& attribute ' + attribute );
    }
}

 

I also tried what is described here, but with no more luck :

http://www.salesforce.com/us/developer/docs/pages/Content/pages_comp_cust_elements_controllers.htm

 

Any help would be greatly appreciated.

 

Thanks !

Rahul_sgRahul_sg
Can you paste your VF page code as well
EguiEgui

Here it is :

 

<apex:page standardController="Contract" standardStylesheets="true" >  
    <c:Component attribute="Sample text" />
</apex:page>

 

crop1645crop1645

I hope this is just a typo but your Component refers to 'Custom Controlleur' (French) but the actual posted controller is 'CustomController'

 

I have also noted that in V27.0, the attribute name= and assignto= value may not be the same literal; that is use:

<apex:attribute name="attribute' assignTo='attr'/>

EguiEgui

You're right, this is just a messing up with the language.

 

Just done another test with the following :

 

Component :

<apex:component controller="customController"> 
    <apex:attribute name="attr" description="" assignTo="{!attribute}" type="String"/>
</apex:component>

 Controller :

public class customController {
    
    public String  attribute { get; set; }

    public customController() {
        system.debug('&&& attribute ' + attribute );
    }
}

 and Page :

<apex:page standardController="Contract" standardStylesheets="true" >  
    <c:Component attr="Sample text" />
</apex:page>

 but still :

22:57:12.068 (68023000)|USER_DEBUG|[6]|DEBUG|&&& attribute null

 

Bhawani SharmaBhawani Sharma
In case of component, getter setter get executed later the constructor run. You won't get this value in constructor. You will get this value in your setter, like

Change your attribute variable to following and check the debug log:
public String attribute {
get;
set {
System.debug('Attribute is : ' + value);
attribute = value;
}
}