[SalesForce] Unable to set controller extensions property with component attribute

I tried setting "accType" property in this extension class with "Customer – Direct".

But it is not getting set or getting set as NULL.

My VF Page

<apex:page standardcontroller="Account" extensions="AccountTypeController">
<c:SetControllerProperty from="Customer - Direct" to="{!acctype}" />
<apex:pageBlock title="Customer Type">
<apex:pageblockTable value="{!accs}" var="a">
<apex:column value="{!a.Name}" />
<apex:column value="{!a.Type}" />
</apex:pageblockTable>
</apex:pageBlock>
</apex:page>

Custom Component Code

<apex:component >
    <apex:attribute name="from" type="String" assignTo="{!to}" description="The value to set"/>
    <apex:attribute name="to" type="String" description="The controller property to set the value into"/>    
</apex:component>

My controller extension class

public with sharing class AccountTypeController {

public String acctype{get;set;}
public List<Account> accs{get;set;}

public AccountTypeController(ApexPages.StandardController stdctrl)
{

accs = [SELECT ID,Name,Type FROM Account WHERE Type = :atype ];


}


}

But when I utilized a custom controller instead of controller extension I am able to set controller property.

My Custom Controller & the modified VF (just changed from Standard Controller with extensions to Custom Controller) are shown below.

<apex:page controller="AccountTypeController">
<c:SetControllerProperty from="Customer - Direct" to="{!acctype}" />
<apex:pageBlock title="Customer Type">
<apex:pageblockTable value="{!Accounts}" var="a">
<apex:column value="{!a.Name}" />
<apex:column value="{!a.Type}" />
</apex:pageblockTable>
</apex:pageBlock>
</apex:page>


public with sharing class AccountTypeController{

public String accType{get;set;}


public List<Account> getAccounts()
{

return [SELECT ID,Name,Type FROM Account WHERE Type = :accType];

}


}

Can someone tell me why I am unable to set controller extensions property via comp attribute ?

Best Answer

Try using this link ... enter link description here

Its says : Setter methods on the attributes in a VF component appear to be called after the constructor has returned, unfortunately. Here's an alternative solution for your controller that uses a getter method to populate your list (which would be called after your CRFType member variable has been set):

May This will help u ...