Form Parts: Creating form method callbacks
来源:互联网 发布:低周波按摩仪 知乎 编辑:程序博客网 时间:2024/05/20 07:15
http://www.exploreax.com/blog/blog/2014/12/01/form-parts-creating-form-method-callbacks/
- Create your form and form parts.
- Add your form part to your main form
- On your main form create a reference to your form part in the class declaration e.g.Object _part;
- Create a method on your main form e.g. “registerForChange(Object _part); with the following code:
public void registerForChange(Object _part)
{
part = _part;
}
This method will allow your form part to provide a reference of itself to the main form. - On your form part’s init method. Call this method register call the above method passing itself as a reference. Note: you will need to perform step #4 on all forms that will use this form part.
public void init()
{
Object caller;
caller= args.caller();
if(caller)
{
caller.registerForChange(this)
}
} - On your form part create an doRefresh method, your main form will call this method whenever a form part refresh is needed. This method can have an parameter that your would like the main form to pass through. In this example we will pass the active record from the main form E.G.
publicvoid doRefresh(Common _record)
{
//Do custom form part refresh.
} - Finally, on your main form, call the the method in #6 at the appropriate time. In this example calling “part.doRefresh(myTable);” in the myTable datasource’s active method works well. You could also do your call from a button on the main form or on any other trigger.
ListPage variation
If you are planning on using the form part as part of a list page. Youneed to make the following adjustments.
- Create a reference to your part in the list page’s ListPageInteractionClass’ ClassDeclaration e.g. Object part;
- For step #4 add the “registerForChange” to your list page’s ListPageInteractionClass
- For step #5 detect whether your part is being called from a ListPage or a normal form: E.G.
public void init()
{
Object caller;
SysSetupFormRun formRun;
super();
caller= this.args().caller();
if(caller)
{
formRun = caller;
if (formRun.pageInteraction())
{
caller = formRun.pageInteraction();
caller.registerForChange(this);
}
else
{
caller.registerForChange(this);
}
}
}
- On the relevant method in your list page interaction class call the part’s doRefresh method. For this example use the selectionChanged method
public void selectionChanged()
{
ListPage listPage = this.listPage();
if (listPage.activeRecord(“MyTable”))
{
part.doRefresh(listPage.activeRecord(“MyTable”));
}
}
Refreshing form parts
When using form parts in AX 2012, you sometimes need to explicitly refreshtheir data based on an event in the main form. It may not be completely obvioushow to do it, but it’s not too complicated in the end.
Form parts are actually forms by themselves and if you know how tomanipulate forms at runtime, you know how to work with parts too. The trickypart it getting a reference to a form part.
One of possible solutions is adding the following method toSysSetupFormRun class (so it’s available to all forms):
public FormRun getFormPartByName(str _name)
{
PartListpartList = newPartList(this);
FormRun part;
int i;
for(i= 1; i <= partList.partCount();i++)
{
part = partList.getPartById(i);
if (part.name() == _name)
{
return part;
}
}
return null;
}
As you see, it iterates all parts in the form and finds a part with thegiven name.
Then you can call it from your form to get a reference to a particularpart and do anything you like with it, such as refreshing the data:
publicvoid refreshMyFactBox()
{
SysSetupFormRunformRun = this as SysSetupFormRun;
FormRun factBox= formRun.getFormPartByName('MyInfoPart');
if (factBox)
{
factBox.dataSource().research();
}
}- Form Parts: Creating form method callbacks
- Creating a Transparent Form
- FORM SQL CREATING PACKAGE
- FORM SQL CREATING PACKAGE
- [Struts]Error creating form bean
- Form表单提交方法method
- Form表单提交方法method
- Form
- form
- form
- Form
- form
- FORM
- form
- form
- form
- form
- form
- hadoop io ObjectWritable and SerializableWritable
- C++反射
- 数据结构——哈夫曼树实现
- Educational Codeforces Round 21 A
- coreseek 安装 配置 的及详细的使用方法
- Form Parts: Creating form method callbacks
- Xutils3基本使用方法1
- 如何刷pat(想要在pat甲级拿80到90分)
- mysql之视图
- EMR集群上capacity_scheduler的ACL实现 http://click.aliyun.com/m/20978/
- Git和SVN共存的方法
- 康拓展开+康拓展开的逆运算
- PIMPL实现String(pointer to implementation)
- CF803C:Maximal GCD(思维 & 构造)