如何从自定义组件控制器获取 Visualforce 页面控制器的值?
我正在尝试开发一个 Visualforce 自定义组件,它是一个实体选择器。此自定义组件显示一个有助于浏览某些记录的 UI。可以选择一条记录,我想从组件或其控制器外部获取它。
我查看了标准 salesforce 与 allocateTo 的绑定 bug,它不是双向的...
希望有人可以帮助我.. 谢谢
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.
I've looked at the standard salesforce binding with assignTo bug it's not bidirectional...
Hope someone can help me..
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否将对象传递到组件中?对象是通过引用传递的,因此如果您的组件具有一个接受对象并对它执行某些操作的属性,您的外部页面控制器将能够访问更改后的值。
如果你要传入一个 shell 对象,即。如果您的 UI 允许用户选择帐户。
组件:
组件控制器:
页面使用组件:
这将允许您将用户选择的帐户分配到外部控制器拥有的包装器对象的实例中。然后,您可以
从主 Visualforce Pages 控制器引用:
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.
Component:
Component Controller:
Page Using the Component:
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:
from your main Visualforce Pages controller.
1 - 在外部类中声明一个静态变量(可以是VF页面控制器)
;
类似于:
public static apexType myRecordOutside;
2 - 当您从自定义组件控制器中的方法中的记录中进行选择时
做这样的事情:
OutsideClass.myRecordOutside = selectedRecord; //注意,当它是静态的时,您可以访问它而无需实例化外部类。
3-然后,在你的视觉力量中声明
这将不是从组件的控制器类获取 myRecordOutside,而是从外部类获取 myRecordOutside
如果您对我的答案的一部分有任何疑问,请告诉我:)
1 - Declare a static variable in the outside class (can be the VF page controller)
Something like :
public static apexType myRecordOutside;
2 -When you Make your choice from records in the method within the custom component controller
Do something like this :
OutsideClass.myRecordOutside = chosenRecord; //notice that when its static you can access it without instantiating the outside class.
3- then, declare in your Visual force
<c:myCustomComponent userSelectedAccount = {!myRecordOutside}></c:myCustomComponent>
this will get myRecordOutside not from the component's controller class, but from the outside class
If you have any question about a part of my answer let me know :)