gpt4 book ai didi

java - 获取选定的LOV值并在其他字段中显示相应的数据

转载 作者:行者123 更新时间:2023-11-30 05:54:59 25 4
gpt4 key购买 nike

表:项目

列:

  ItemNumber,
Description

transient 属性1: 项目

在显示项目编号的项目上创建 LOV

transient 属性2:

 ItemsDescription-This should display Description of above item selected.Added following code on Attribute 2:


if(ItemNumber!=null)
{ oracle.jbo.Key keyVal=new oracle.jbo.Key(ItemNumber);
return ItemVO1.findByKey(keyVal,1)[0].getAttribute("Description");
}
else
{
return null; }

需要在属性2列上显示描述

最佳答案

据我了解,您的要求是:

您需要根据 ADF 中 LOV 中的项目编号选择来显示项目描述。

项目描述和项目编号都是 transient 字段。

我使用的是 ADF 11g。

我没有任何与项目相关的表格。所以我对 Emp 表本身使用了 2 个 VO。

   - One is base EmpVO
- Second is LOV VO (empObjVO)

表:员工

    - emp_id
- emp_name
- item_emp_id ( Transient variable - LOV - based on emp_id)
- item_emp_desc (Output Transient variable - Output text - On selection of LOV)

empObjVO - 包含

     - emp_id ( This column is list for item_emp_id)
- emp_name (This column will be description for selection of emp_id)

EmpVo

     - item_emp_id has LOV of empObjVO1 with List Attribute and UI display attribute both.
( As you told item number is displayed in LOV. consider emp_id as item_number here).

List type is choice list.

完成上述配置后,将item_emp_id和item_emp_desc放置在jsff页面中,分别作为选择一项和输出文本。

页面中的item_emp_id定义:

       <af:selectOneChoice value="#{bindings.item_emp_id.inputValue}"
label="#{bindings.item_emp_id.label}"
required="#{bindings.item_emp_id.hints.mandatory}"
shortDesc="#{bindings.item_emp_id.hints.tooltip}"
id="soc3" autoSubmit="true"
valueChangeListener="#{bean1.changeVal}">
<f:selectItems value="#{bindings.item_emp_id.items}" id="si3"/>
</af:selectOneChoice>

为其设置autosubmit=true

创建 ValueChangeEventListner 并在 bean 中创建一个方法,以在 LOV 中的值发生更改时触发。item_emp_desc 定义是:

    <af:outputText value="#{bindings.item_emp_desc.inputValue}" id="ot1"
partialTriggers="soc3"/>

使用部分触发器作为soc3,因为它依赖于soc3。

public void changeVal(ValueChangeEvent vce) {
// Add event code here...
Integer selectedCode=null;
//As we get indexes not value of LOV so need to map selected index with value.

if (vce.getNewValue() != null) {
this.setvalueToExpression("#{bindings.item_emp_id.inputValue}",
vce.getNewValue()); //Updating Model Values
selectedCode =
Integer.parseInt(this.getValueFrmExpression("#{bindings.item_emp_id.attributeValue}").toString());

System.out.println("******** Selected Value in List***** " +
selectedCode);
System.out.println("*******Display Value in List ****" +
getValueFrmExpression("#{bindings.item_emp_id.selectedValue.attributeValues[1]}"));
}

String e_id=selectedCode.toString(); //It will contain selected item_emp_id
DCBindingContainer bindings =
(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding dcIteratorBindings =
bindings.findIteratorBinding("EmpView1Iterator"); // Base table Emp VO iterator
DCIteratorBinding dcIteratorBindings1 =
bindings.findIteratorBinding("empViewObj1Iterator"); // LOV table Emp Vo iterator
ViewObject vo = dcIteratorBindings.getViewObject();
ViewObject vo1 = dcIteratorBindings1.getViewObject();
Row r1 = vo.getCurrentRow(); // get current row of base table VO


vo1.setWhereClause("e_id = " + e_id); // set where clause to get the description from LOV in VO1
vo1.executeQuery(); //execute it.
if(vo1.hasNext())
{
Row r=vo1.next(); // Get the row from LOV VO

if(r!=null)
{
r1.setAttribute("item_emp_desc", r.getAttribute("EmpName")); //set it to item_emp_desc which is a transient variable for output.
}
}

}


public void setvalueToExpression(String el, Object val) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
ValueExpression exp = expressionFactory.createValueExpression(elContext, el, Object.class);
exp.setValue(elContext, val);
}


public String getValueFrmExpression(String data) {
FacesContext fc = FacesContext.getCurrentInstance();
Application app = fc.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = fc.getELContext();
ValueExpression valueExp = elFactory.createValueExpression(elContext, data, Object.class);
String Message = null;
Object obj = valueExp.getValue(elContext);
if (obj != null) {
Message = obj.toString();
}
return Message;
}

为了理解索引到值的转换,我引用了

 [http://www.awasthiashish.com/2014/05/getting-selected-value-not-index-display-value-of-select-one-choice-programmatically-in-adf.html][1]

它可能对你有帮助。

关于java - 获取选定的LOV值并在其他字段中显示相应的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53332106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com