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

查看:27
本文介绍了如何从自定义组件控制器中获取 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.

我查看了带有assignTo错误的标准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.

如果你要传入一个 shell 对象,即.如果您的用户界面允许用户选择帐户.

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天全站免登陆