5

私はエンティティチューザーであるvisualforceカスタムコンポーネントを開発しようとしています。このカスタムコンポーネントは、一部のレコードの参照に役立つUIを表示します。1つのレコードを選択することができますが、コンポーネントまたはそのコントローラーの外部から取得したいと思います。

私はassignToバグを使用した標準のセールスフォースバインディングを見てきましたが、双方向ではありません...

誰かが私を助けてくれることを願っています..ありがとう

4

3 に答える 3

5

オブジェクトをコンポーネントに渡しますか?オブジェクトは参照によって渡されるため、コンポーネントにオブジェクトを取得して何かを実行する属性がある場合、外部ページコントローラーは変更された値にアクセスできます。

シェルオブジェクトを渡す場合、つまり。UIでユーザーがアカウントを選択できる場合。

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

メインのVisualforcePagesコントローラから。

于 2011-05-23T23:47:59.360 に答える
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-次に、次のように宣言します視覚的な力
<c:myCustomComponent userSelectedAccount = {!myRecordOutside}></c:myCustomComponent>
これは、コンポーネントのコントローラークラスからではなく、外部クラスからmyRecordOutsideを取得します

私の答えの一部について質問があれば私に知らせてください:)

于 2012-10-23T11:14:30.850 に答える
0
    /* This is an example of getting non static variable value
    from visualforce component controller variable to visualforce page controller variable */

    VF page: DisplayCountryPage
    <apex:page>

        <apex:commandButton value="display country list" action="{!displaycountryname}" />
        <apex:repeat value="{!displaycountrylistvalue}" var="item">
            <div>
                {!item}
            </div>            
        </apex:repeat> 

        <c:testvfcmp vfpageclasscontroller="{!thisPageInstance}"/>
    </apex:page>
    =====================
    DisplayCountryPage VF Page controller: vfpageclass
    public class vfpageclass{
        public List<String> displaycountrylistvalue{get;set;}
        public vfcomponentclass vfcmpobj{get;set;}
        public void methodtosetvfcomponentclass(vfcomponentclass vfcmpobj2){
            vfcmpobj = vfcmpobj2;
        }

        public void displaycountryname(){
            displaycountrylistvalue = new List<String>();
            displaycountrylistvalue = vfcmpobj.listOfCountry;
        }
        public vfpageclass thisPageInstance{
            get{
                return this;
            }
            set;
        }
    }
    ======================
    vf component: testvfcmp
    create an attribute like below:
    <apex:component controller="CSTSearchPanelController">
        <apex:attribute name="vfpageclasscontroller" 
                            type="vfpageclass" 
                            assignTo="{!vfpageobj}"                    
                            description="The controller for the page." />

        <apex:commandButton value="set country list" action="{!setCountrylist}" />

    </apex:component>
    =====================

    <testvfcmp> vf component controller: vfcomponentclass
    public class vfcomponentclass{

        public List<String> listOfCountry = new List<String>();
        public vfpageclass vfpageobj{
            get;
            set{
                vfpageobj = value;
                vfpageobj.methodtosetvfcomponentclass(this);
            }
        }   
        public void setCountrylist(){
            listOfCountry.add('India');
            listOfCountry.add('USA');
        }
    }


/* This is an example of getting static variable value
from visualforce component controller variable to visualforce page controller variable */

VF page: DisplayCountryPage
<apex:page>

    <apex:commandButton value="display country list" action="{!displaycountryname}" />
    <apex:repeat value="{!displaycountrylistvalue}" var="item">
        <div>
            {!item}
        </div>            
    </apex:repeat> 

    <c:testvfcmp vfpageclasscontroller="{!thisPageInstance}"/>
</apex:page>
=====================
DisplayCountryPage VF Page controller: vfpageclass
public class vfpageclass{
    public List<String> displaycountrylistvalue{get;set;}

    public void methodtosetvfcomponentclass(vfcomponentclass vfcmpobj2){

        if(vfcmpobj2.getStaticCountryList() !=null){
            displaycountrylistvalue = new List<String>();
            displaycountrylistvalue = vfcmpobj2.getStaticCountryList();
        }

        /* USE THIS displaycountrylistvalue VARIABLE THROUGHOUT THE CLASS ONCE YOU SET BY HITTING BUTTON <set country list>.
        DO NOT USE vfcmpobj2.getStaticCountryList() IN OTHER METHODS TO GET THE VALUE, IF DO, IT WILL RETURN NULL*/
    }

    public void displaycountryname(){

    }
    public vfpageclass thisPageInstance{
        get{
            return this;
        }
        set;
    }
}
======================
vf component: testvfcmp
create an attribute like below:
<apex:component controller="CSTSearchPanelController">
    <apex:attribute name="vfpageclasscontroller" 
                        type="vfpageclass" 
                        assignTo="{!vfpageobj}"                    
                        description="The controller for the page." />

    <apex:commandButton value="set country list" action="{!setCountrylist}" />

</apex:component>
=====================

<testvfcmp> vf component controller: vfcomponentclass
public class vfcomponentclass{

    public static List<String> listOfCountry = new List<String>();
    public vfpageclass vfpageobj{
        get;
        set{
            vfpageobj = value;
            vfpageobj.methodtosetvfcomponentclass(this);
        }
    } 

    public static void setCountrylist(){
        listOfCountry.add('India');
        listOfCountry.add('USA');
    }
    public List<String> getStaticCountryList(){
        return listOfCountry;
    }

}                   
于 2019-08-13T11:59:19.963 に答える