2011-05-23 52 views

回答

4

你傳遞對象到組件?對象是通過引用傳遞的,所以如果你的組件有一個接受對象的屬性並對它做了一些事情,你的外部頁面控制器將能夠訪問更改後的值。

如果您要傳遞一個shell對象,即。如果你的用戶界面允許用戶選擇一個帳戶。

Class SelectedAccount 
{ 
    public Account theAccount {get;set;} 
} 

組件:

<apex:component controller="ComponentController"> 
    <apex:attribute type="SelectedAccount" name="userSelectedAccount" description="Selected Account" assignTo="{!selectedAccount}" 
</apex:component> 

組件控制器:

public class ComponentController 
{ 
    public selectedAccount; 

    public void ComponentController(){} 

    public PageReference selectAccountFromUI(Account selected) 
    { 
    selectedAccount.theAccount = selected; 

    return null; 
    } 
} 

頁使用的組件:

<c:MyAccountComponent userSelectedAccount="{!instanceOfSelectedAccount}"/> 

這將讓你的用戶選擇帳戶分配到例由外部控制器擁有的包裝器對象。您可以參考:

instanceOfSelectedAccount.theAccount 

從您的主Visualforce頁面控制器。

+0

如果你是一個重複循環,這並不工作,以及內。 我很好奇,如果有一種方法可以將整個對象從頁面傳遞到組件中,那麼組件可以編輯它(認爲模式對話框),並且更改顯示在頁面上。 – tggagne 2012-03-13 18:49:14

1

1 - 聲明在外面類的靜態變量(可以是VF頁面控制器)
喜歡的東西:
public static apexType myRecordOutside;
2 - 當您從記錄的自定義組件控制器
內做出選擇的方法 做這樣的事情:
OutsideClass.myRecordOutside = chosenRecord; //notice that when its static you can access it without instantiating the outside class.
3-接下來,聲明在Visual力
<c:myCustomComponent userSelectedAccount = {!myRecordOutside}></c:myCustomComponent>
這將讓myRecordOutside不會從組件控制器類,但FR OM外類

如果您對我的答案的一部分,任何問題,讓我知道:)