小编今天带大家了解OAF开发中LOV相关技巧有哪些,文中知识点介绍的非常详细。觉得有帮助的朋友可以跟着小编一起浏览文章的内容,希望能够帮助更多想解决这个问题的朋友找到问题的答案,下面跟着小编一起深入学习“OAF开发中LOV相关技巧有哪些”的知识吧。

在OAF开发中,LOV的使用频率是很高的,它由两部分构成一是页面上的LOV输入框(如OAMessageLovInputBean),二是弹出的LOV模式窗口(OAListOfValueBean)。用户选择LOV的按钮就会弹出LOV窗口,用户在LOV窗口查询并选择了值,可以返回到页面上的LOV输入框。在这里就不赘述如何创建LOV,只说一些平时会碰到的应用:

1.控制LOV的查询结果
2.LOV相关事件
3.动态LOV
4.LOV Choice
一,控制LOV的查询结果

1,使用Criteria

很多种情况下都会用到用某一个Item或者某几个Item来控制LOV的结果,例如页面上有一个Item的LOV和一个Organization,因为Item是有库存组织的,所以就有这样的需求,我选择了某一个库存组织的时候,Item的LOV只显示该库存组织下面的Item。

要实现这个功能,首先需要将Organization放入LOV查询语句作为结果集(LOV的VO中加入Oraganization_Id这一列),然后在Item的LOV中新建一个Mapping,Mapping中LOV Region Item选择OrganizationId(LOV中的),而Criteria选择页面上的OrganizationId,注意,这两个不是同一个Organization。一个是LOV中的,一个是页面上的。

Criteria设置了相应的Item时,在弹出LOV窗口时,会作为验证字段带入LOV窗口,LOV视图对象会自动绑定该值作为查询条件。因为这个自动绑定是对查询的结果集再进行一次条件查询,所以需要将Organization_Id作为查询结果集。

2,Passive Criteria

LOV的Criteria Item也可以手动绑定,也就是在主页面上的作为Criteria Item的字段在传入LOV Region后并不和LOV的查询自动绑定,而是由开发员动态去绑定。这种方法我认为是为了一些高级的查询所设的,例如需要根据传入的一个Flag字段,在查询条件中加入exists…这样的查询条件。

使用Passive Criteria,和LOV的普通Criteria Mapping一样,选择LOV Region Item以及Criteria Item,然后将Programmatic Query选择为True,这样,LOV就不会动态绑定查询条件了。之后,我们在LOV的Region上创建一个CO,在proce***equest中得到验证字段:

publicvoidproce***equest(OAPageContextpageContext,OAWebBeanwebBean)

{

super.proce***equest(pageContext,webBean);

OAApplicationModuleam=pageContext.getApplicationModule(webBean);

DictionarypassiveCriteria=pageContext.getLovCriteriaItems();

//此处的LookupType指的是Mapping中的LovRegionItem的ID

StringlovCriteria=(String)passiveCriteria.get("LookupType");


OAViewObjectlovVO=(OAViewObject)am.findViewObject("FndLookupTypeLovVO1");

//根据得到的验证字段限定查询结果

lovVO.setWhereClause("");

lovVO.executeQuery();

}

二、LOV事件

对于MessageTextInput,CheckBox等,可以使用Client Action来触发事件,假如一个CheckBox,可以为它做一个fireAction来控制比如打勾了以后改变某一个字段的值或者一些类似的控制。这些事件可以在页面CO中的processFormRequest中使用pageContext.getParameter(EVENT_PARAM)获得。但是MessageLovInput是没有fireAction事件的,实际上Lov操作的时候已经存在了一些事件,不需要我们去定义的,可以直接通过pageContext.getParameter(EVENT_PARAM)得到LOV事件。

LOV事件有三种,lovPrepare、lovUpdate、lovValidate(由pageContext.getParameter(EVENT_PARAM)返回),它们都是在页面CO的processFormRequest中触发的。当点了Lov上的手电筒时,会触发事件lovPrepare。当选中了某一个Lov返回到本页面是,会在formRequest中触发事件lovUpdate。当在Lov输入框中输入一个唯一的值时,此时会触发Lov验证,这里需要注意的是如果在输入框中输入一个不唯一的值,那么验证会自动的打开Lov窗口让你进行选择,此时在formRequest中是不会触发lovValidate事件的。当在选择了LOV选择的值进行相应的页面处理(例如控制其他字段是否显示等),就可以在processFormRequest中通过对Lov事件的判断并做相应处理。

/**Item版本控制,当选择了有版本控制的Item,该行版本字段可修改,如果没有版本控制,该Item版本字段为默认**/

super.processFormRequest(pageContext,webBean);

OAApplicationModuleam=pageContext.getApplicationModule(webBean);

if("ItemCode".equals(pageContext.getLovInputSourceId()))

{


/**lovUpdate是在LovRegion选择了Item,lovValidate是在LovMessageInput控件中输入后触发,在此事件中判断Item是否具有版本控制**/

if("lovUpdate".equals(pageContext.getParameter(EVENT_PARAM))

||"lovValidate".equals(pageContext.getParameter(EVENT_PARAM)))

{

/**对Revision字段进行控制**/

am.invokeMethod("controlRevSwitcher",newSerializable[]

{pageContext.getParameter(SOURCE_PARAM),

pageContext.getParameter("OrganizationIdFV")});



/**controlRevSwitcher方法是对版本控件的ReadOnly进行控制,但是页面上不能马上反应,需要使用局部刷新**/

OAAdvancedTableBeantableBean=

(OAAdvancedTableBean)webBean.findChildRecursive("VenTrxLinesAdvTbl");

tableBean.queryData(pageContext);

}

}

在上例的例子中,由于LOV字段是基于VO的,所以得到所选的LOV的值可以在VO中得到。但是对于不基于VO的LOV,如果需要在页面事件发生的时候就得到选择得到的LOV值,需要用以下方法来获取:

//Formwassubmittedbecausetheuserselected

//avaluefromtheLOVmodalwindow,

//orbecausetheusertabbedoutoftheLOVinput.

//FindoutwhichLOVinputtriggeredtheevent.

StringlovInputSourceId=pageContext.getParameter(SOURCE_PARAM);

//FindouttheresultvaluesoftheLOV.

HashtablelovResults=

pageContext.getLovResultsFromSession(lovInputSourceId);

if(lovResults!=null)

{

System.out.println("lovResults"+lovResults);

//Updatethepagedependingonthevaluechosenbytheuser.

}

三、动态LOV

动态LOV的应用一般很少。在之前沈辉写的一个文档中,是通过先创建一个LOV后,然后在页面事件发生时动态的去改变LOV的SQL实现的。而我的方法是用直接动态创建VO去和LOV Region中的Item进行关联来实现的。

LOV是通过页面调用我们创建好的Region来实现的,所以这个LOV Region是LOV最为关键的部分,所以实际上,在LOV VO还不存在的时候,只要有Region,我们的LOV就可以创建起来。所以我们可以先创建一个空壳Region,然后在主页面打开的时候再动态的创建LOV VO,最后将VO与Region中的Table关联。

首先,需要创建一个LOV Region,这个Region并不和任何VO关联,在我的例子中,我创建了5个MessageStyledText,5个FormValue。这些字段字段此时只是设置了Prompt属性,其他属性都是默认,包括Data Type。

接下来,在主页面的Proce***equest创建LOV Bean(当然也可以在其他页面动作的时候创建LOV)。并且创建LOV VO。

importjava.io.Serializable;


importjava.util.ArrayList;

importjava.util.Hashtable;


importoracle.apps.fnd.common.VersionInfo;

importoracle.apps.fnd.framework.OAApplicationModule;

importoracle.apps.fnd.framework.webui.OAControllerImpl;

importoracle.apps.fnd.framework.webui.OAPageContext;

importoracle.apps.fnd.framework.webui.beans.OAWebBean;

importoracle.apps.fnd.framework.webui.beans.layout.OAHeaderBean;

importoracle.apps.fnd.framework.webui.beans.message.OAMessageLovInputBean;


publicvoidproce***equest(OAPageContextpageContext,OAWebBeanwebBean)

{

super.proce***equest(pageContext,webBean);

OAApplicationModuleam=pageContext.getApplicationModule(webBean);


/*--------------------------------------------------创建LOVBean----------------------------------------------------*/


OAHeaderBeanheaderBean=(OAHeaderBean)webBean.findChildRecursive("TestHdRN");

OAMessageLovInputBeanlovInput=(OAMessageLovInputBean)createWebBean(pageContext,LOV_TEXT,null,"InputTest");


headerBean.addIndexedChild(lovInput);


//Specifythepathtothebasepage.

lovInput.setAttributeValue(REGION_CODE,"/alther/oracle/apps/cux/checkboxtest/webui/CheckBoxTestPG");

//Specifytheapplicationidofthebasepage.

lovInput.setAttributeValue(REGION_APPLICATION_ID,newInteger(30001));


//此处的Region就是刚才创建的Region

lovInput.setLovRegion("/alther/oracle/apps/cux/lov/webui/CommonLovRN",);


lovInput.setUnvalidated(false);

lovInput.setPrompt("DynamicLov");


//增加Mapping关系,由于LOV的Mapping在主页面初始化时就会使用到,所以必须创建一些空的Item来做Mapping,否则会报错

lovInput.addLovRelations(pageContext,"InputTest",//basepageitem

"DisplayItem1",//lovitem

LOV_RESULT,//direction

LOV_REQUIRED_NO);

lovInput.addLovRelations(pageContext,"InputTest",//basepageitem

"DisplayItem1",//lovitem

LOV_CRITERIA,//direction

LOV_REQUIRED_NO);


lovInput.addLovRelations(pageContext,"TestItem",//basepageitem

"DisplayItem2",//lovitem

LOV_PASSIVE_CRITERIA,//direction

LOV_REQUIRED_NO);


/*--------------------------------------------------创建LOVVO------------------------------------------------------*/

ArrayListparamList=newArrayList();

StringvoName="FndUserLovVO2";

Stringsql="SELECTfu.user_id,"+

"fu.user_name,"+

"fu.start_date"+

"FROMfnd_userfu";


//paramList是用来创建LOV并在关联时都会用到的每个Item的Attribute

paramList.add(newString[]{"UserId","USER_ID","oracle.jbo.domain.Number",null,"Hide",null});

paramList.add(newString[]{"UserName","USER_NAME","java.lang.String","100","Display","SearchAllow"});

paramList.add(newString[]{"StartDate","START_DATE","oracle.jbo.domain.Date",null,"Display",null});

//调用AM方法创建VO

am.invokeMethod("createVO",newSerializable[]{voName,sql,paramList},

newClass[]{String.class,String.class,paramList.getClass()});


am.getOADBTransaction().putTransientValue("LovVOInstance",voName);

am.getOADBTransaction().putTransientValue("LovAttribute",paramList);


}

这是AM中创建VO的方法:

importjava.sql.Types;


importjava.util.ArrayList;


importoracle.apps.fnd.framework.server.OAApplicationModuleImpl;

importoracle.apps.fnd.framework.server.OADBTransaction;

importoracle.apps.fnd.framework.server.OAViewDef;


importoracle.jbo.AttributeDef;


publicvoidcreateVO(StringvoName,Stringsql,ArrayListlist){

OADBTransactiondbtx=getOADBTransaction();

String[]attribute=newString[6];

inttypes=-9999;

OAViewDefviewDef=dbtx.createViewDef();


viewDef.setSql(sql);

viewDef.setExpertMode(true);

viewDef.setViewObjectClass("oracle.apps.fnd.framework.server.OAViewObjectImpl");

viewDef.setViewRowClass("oracle.apps.fnd.framework.server.OAViewRowImpl");


for(inti=;i<list.size();i++){

attribute=(String[])list.get(i);

if("java.lang.String".equals(attribute[2])){

types=Types.VARCHAR;

}

elseif("oracle.jbo.domain.Number".equals(attribute[2])){

types=Types.NUMERIC;

}

elseif("oracle.jbo.domain.Date".equals(attribute[2])){

types=Types.DATE;

}


if("java.lang.String".equals(attribute[2])){

viewDef.addSqlDerivedAttrDef(attribute[],

attribute[1],

attribute[2],

types,

false,

true,

AttributeDef.UPDATEABLE,

Integer.parseInt(attribute[3]));

}

else{

viewDef.addSqlDerivedAttrDef(attribute[],

attribute[1],

attribute[2],

types,

false,

true,

AttributeDef.UPDATEABLE);}

}


if(findViewObject(voName)!=null){

findViewObject(voName).remove();

}


createViewObject(voName,viewDef);

}

最后,在LOV Region的CO中,加入关联的代码。这里需要注意一点,由于我们的LOV VO是创建在主页面的AM下的,所以LOV Region的AM必须和主页面的AM一致。否则,在主页面的变量就无法传到LOV Region中。

publicvoidproce***equest(OAPageContextpageContext,OAWebBeanwebBean)

{

super.proce***equest(pageContext,webBean);

OAApplicationModuleam=pageContext.getApplicationModule(webBean);


StringvoInstance=(String)am.getOADBTransaction().getTransientValue("LovVOInstance");

ArrayListparamList=(ArrayList)am.getOADBTransaction().getTransientValue("LovAttribute");

String[]attribute=newString[6];

intdispalyIndex=1;

inthideIndex=1;


//关联VO

((OAListOfValuesBean)webBean).setViewUsageName(voInstance);


//将Region中的MessageStyledText都设置为不显示

for(inti=1;i<=5;i++){

OAMessageStyledTextBeandisplayItem=

(OAMessageStyledTextBean)webBean.findChildRecursive("DisplayItem"+i);

displayItem.setRendered(false);

}


//将Region中的FormValue都设置为不显示

for(inti=1;i<=5;i++){

OAFormValueBeanhideItem=

(OAFormValueBean)webBean.findChildRecursive("FormVal"+i);

hideItem.setRendered(false);

}


for(inti=;i<paramList.size();i++){

attribute=(String[])paramList.get(i);

if(attribute[4]!=null&&"Display".equals(attribute[4])){

OAMessageStyledTextBeandisplayItem=

(OAMessageStyledTextBean)webBean.findChildRecursive("DisplayItem"+dispalyIndex);


//关联ViewAttribute

displayItem.setViewAttributeName(attribute[]);


//设置DataType

if("java.lang.String".equals(attribute[2])){

displayItem.setDataType("VARCHAR2");

}

elseif("oracle.jbo.domain.Number".equals(attribute[2])){

displayItem.setDataType("NUMBER");

}

elseif("oracle.jbo.domain.Date".equals(attribute[2])){

displayItem.setDataType("DATE");

}

//设置显示

displayItem.setRendered(true);


//是否可查询

if(attribute[5]!=null&&"SearchAllow".equals(attribute[5])){

displayItem.setQueryable(true);

}


dispalyIndex++;

}

elseif(attribute[4]!=null&&"Hide".equals(attribute[4])){

OAFormValueBeanhideItem=

(OAFormValueBean)webBean.findChildRecursive("FormVal"+hideIndex);


//hideItem.setViewUsageName("FndUserLovVO2");

hideItem.setViewAttributeName(attribute[]);


if("java.lang.String".equals(attribute[2])){

hideItem.setDataType("VARCHAR2");

}

elseif("oracle.jbo.domain.Number".equals(attribute[2])){

hideItem.setDataType("NUMBER");

}

elseif("oracle.jbo.domain.Date".equals(attribute[2])){

hideItem.setDataType("DATE");

}


hideItem.setRendered(true);


hideIndex++;

}

}

}

<p style="margin-top:0px;margin-bottom:18px;padding:0px;font-family:'-apple-system', 'SF UI Text', Arial, 'PingFang SC', 'Hi

感谢大家的阅读,以上就是“OAF开发中LOV相关技巧有哪些”的全部内容了,学会的朋友赶紧操作起来吧。相信亿速云小编一定会给大家带来更优质的文章。谢谢大家对亿速云网站的支持!