Выбрать выбранное значение LOV и отобразить соответствующие данные в другом поле. - PullRequest
0 голосов
/ 16 ноября 2018

Таблица: Пункт

Колонки:

  ItemNumber,
  Description

Переходный атрибут1: Элементы

LOV, созданный для Предметов, который отображает Номер Предмета

Переходный атрибут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; }

Необходимо отобразить описание в столбце Attribute2

1 Ответ

0 голосов
/ 16 ноября 2018

Я понял, что ваше требование:

Вам необходимо показать описание товара на основе выбора номера товара в LOV в ADF.

Описание элемента и номер элемента оба являются переходными.

Я использовал АПД 11g.

У меня нет таблицы, связанной с элементом.Так что я использовал 2 VO для таблицы Emp непосредственно.

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

Таблица: Emp

    - 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и создайте метод в бине, чтобы вызвать изменение значения в LOV.Определение item_emp_desc:

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

Используйте partial trigger as 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]

Это может вам помочь.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...