如何从自定义组件控制器中获取Visualforce页面控制器中的值? [英] How to get in a Visualforce page controller a value from a custom component controller?

查看:99
本文介绍了如何从自定义组件控制器中获取Visualforce页面控制器中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个visualforce自定义组件,它是一个实体选择器.该自定义组件显示一个UI,可帮助浏览某些记录.可以选择一条记录,我想从组件或其控制器外部获取它.

I'm trying do develop a visualforce custom component which is an entity chooser. This custom component displays a UI which helps browsing some records. It's possible to select one record, and I'd like to get it from outside the component or its controller.

我已经查看了带有salesTo的标准Salesforce绑定,它不是双向的...

I've looked at the standard salesforce binding with assignTo bug it's not bidirectional...

希望有人可以帮助我.. 谢谢

Hope someone can help me.. Thanks

推荐答案

您是否正在将对象传递给组件?对象是通过引用传递的,因此,如果您的组件具有接受对象并对其执行操作的属性,则外部页面控制器将能够访问更改的值.

Are you passing an object into the component? Objects are passed by reference, so if your component has an attribute that takes an object and does something to it, your outer page controller will be able to access the changed values.

如果要传递外壳对象,即.如果您的用户界面允许用户选择一个帐户.

If you were to pass in a shell object, ie. if your UI is allowing a user to select an Account.

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}"/>

这将允许您将用户选择的帐户分配给外部控制器拥有的包装对象的实例.然后,您可以参考:

This would allow you to assign the user selected account into the instance of wrapper object which is owned by the outer controller. You can then reference:

instanceOfSelectedAccount.theAccount

从Visualforce Pages主控制器中获取.

from your main Visualforce Pages controller.

这篇关于如何从自定义组件控制器中获取Visualforce页面控制器中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆