[AX]AX2012 Interaction class

Ax2012 Client的form如果属性FormTemplate设置为DetailsPage或者ListPage,则必须同时设置属性InteractionClass为相应的Interaction类,比如采购订单详细信息窗口PurchForm的InteractionClass被指定为PurchTableInteraction,它的作用是对用户在form中所做的操作面板标签切换、记录选择等做出响应,以更新操作面板中控件的状态。

Details或者List风格的Form,通常是包含一个或者多个ActionPane的,Interaction类从PageInteraction派生,其中最重要的一个方法就是tabchanged方法,在扩展类中我们重载这个方法,form中切换ActionPane的Tab时,系统会通过类InteractionService的callTabChanged方法调用重载的tabchanged方法,下面是PurchTableInteraction的tabchanged方法:

public void tabChanged(container _activeTabNames)
{
    Array tabNameArray = new Array(Types::String);
    int i;

    super(_activeTabNames);

    for (i=1;i<=conLen(_activeTabNames);i++)
    {
        tabNameArray.value(i,conPeek(_activeTabNames,i));
    }

    this.init();
    if (purchTable)
    {//Tab changed is called on form open before selection changed.
        this.enableHeaderActions(tabNameArray);
        this.enableHeaderActionsFromLine();
    }
}

它根据当前选择的采购单记录和采购行更新当前激活的ActionPane tab的控件的使能状态,当前激活的ActionPane Tab的名称从参数_activeTabNames传入,要获取当前form数据源的记录我们可以通过Page对象来获取:

    page                    = this.page();

    purchLine               = page.activeRecord(identifierStr(PurchLine));
    purchTable              = page.activeRecord(identifierStr(PurchTable));
    inventDim               = page.activeRecord(identifierStr(InventDim));

除了tabchanged方法对ActionPane Tab切换作出响应,我们还需要对用户选择了不同的数据行时更新按钮状态,这种情况我们需要用到FormDataSourceInteractionAttribute特性来标记相应的Interaction类响应方法,它的用法是这样的:

[FormDataSourceInteractionAttribute('PurchLine', 'selectionChanged')]
public void purchLine_DS_selectionChanged()
{
    this.init();

    this.enableLineActions();
}

这里把方法purchLine_DS_selectionChanged和form的PurchLine数据源联系起来,在Purchase order窗口中如果选择的采购订单行发生了变化,系统会自动通过系统类InteractionService的callEventHandler方法调用purchLine_DS_selectionChanged,这样我们就可以根据选择的记录行更新操作按钮状态,它不带任何的参数,但是我们仍然可以通过“this.page().activeActionPaneTabNames()”来获取当前激活的ActionPane 标签名称。

Page对象也提供了actionPaneControlEnabled和actionPaneControlVisible两个方法来分别使能/禁止和显示/隐藏ActionPane中的控件,用法是这样的:

this.page().actionPaneControlEnabled(formControlStr(PurchTable, buttonPurchCancel), purchTableInteractionHelper.parmbuttonPurchCancelEnabled());

this.page().actionPaneControlVisible(formControlStr(PurchTable, buttonUpdateFacture_RU), purchTableInteractionHelper.parmenableInvoiceButton());

使用Interaction类的好处是将Form UI的更新从窗口中剥离出来单独处理,使得代码更清晰,否则我们必须把更新按钮状态的代码嵌入到表单中,复杂的Form本身代码就很多,就会使得情况更加复杂,不幸的是MSDN上只有很少的关于Interaction class的内容,可能是太简单了不值一提。

 

 

 

posted @ 2013-06-21 15:59  断水流  阅读(1033)  评论(0编辑  收藏  举报