[Oracle ADF] ROW
Get Current Row
public Row getCurrentRow(String iterator) {
DCBindingContainer bindings = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding dcItteratorBindings = bindings.findIteratorBinding(iterator);
ViewObject vo = dcItteratorBindings.getViewObject();
return vo.getCurrentRow();
}
Получить из VO где всего 1 запись
Строку
Делал в AppModuelImpl
public String getUserLocale() {
String userLocaleAttribute = "Language";
String voName = "UserLocale";
ViewObjectImpl vo = (ViewObjectImpl) findViewObject(voName);
Row row = vo.first();
return (String) row.getAttribute(userLocaleAttribute);
}
Дату типа timestamp
В аттрибутах поставил тип Date
import java.util.Date;
public static Date getMyBusitessDate(){
ViewObject vo = VOUtils.getViewObjectByName(CONSTANTS_VO.MY_DATE_VO);
Row curRow = vo.first();
oracle.jbo.domain.Date businessDate = (oracle.jbo.domain.Date)curRow.getAttribute("myBusinessDate");
return businessDate.getValue();
}
Получить из VO где всего 1 запись дату. Дата timestamp
import java.time.LocalDate;
import static java.time.format.DateTimeFormatter.ISO_LOCAL_DATE;
public String getMyBusitessDate() {
Row row = ADFUtils.findIterator("BusinessDateViewIterator").getCurrentRow();
if (row != null) {
Object myDate = row.getAttribute("MyDate");
if (myDate instanceof Timestamp) {
Timestamp timestamp = (Timestamp) myDate;
LocalDate localDate = timestamp.toLocalDateTime().toLocalDate();
return localDate.format(ISO_LOCAL_DATE);
}
}
return "";
}
Найти значение поля во ViewObject по аттрибуту
Приходит текст в valueChangeEvent. Нужно получить id.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public void onSomethingChanged (ValueChangeEvent valueChangeEvent) {
if (null != valueChangeEvent.getNewValue()){
String selectedDescription = valueChangeEvent.getNewValue().toString();
ViewObject voItems = VOUtils.getViewObjectByName(CONSTANTS_VO.MY_VO);
String selectedId = "";
for (Row rw : voItems.getAllRowsInRange()) {
if ((rw.getAttribute("Description")).equals(selectedDescription)){
selectedId = (String)rw.getAttribute("Id");
}
}
System.out.println();
System.out.println("selectedDescription " + selectedDescription);
System.out.println("selectedId " + selectedId);
}
}
id и Description - поля в базе.
CreateRow
(скопировано где-то)
Row custRow = vo.first();
if (custRow == null) {
custRow = vo.createRow();
ViewObject voNextId = am.findViewObject("MyVO");
voNextId.executeQuery();
custRow.setAttribute("MyAttribute1", voNextId.first().getAttribute("Newid"));
custRow.setAttribute("MyAttribute2", row.getAttribute("UiId"));
Object user = AdfFacesContext.getCurrentInstance()
.getPageFlowScope()
.get("p_user");
custRow.setAttribute("UserId", user);
vo.insertRow(custRow);
DBTransaction txn = am.getDBTransaction();
txn.postChanges();
vo.executeQuery();
custRow = vo.first();
}
Еще 1 пример:
Row curRow = ADFUtils.findIterator("IteratorName").getCurrentRow();
curRow.setAttribute("Status", "A");
DCBindingContainer bindings = (DCBindingContainer) BindingContext.getCurrent().getCurrentBindingsEntry();
OperationBinding operationBinding = bindings.getOperationBinding("Commit");
System.out.println("Execute Commit");
operationBinding.execute();
Еще 1 пример:
// Tree
JUCtrlHierBinding res2 = (JUCtrlHierBinding) bindings.get("bindingName");
for (Row r : res2.getAllRowsInRange()) {
System.out.println(r.getAttribute("attributeId") + " " + r.getAttribute("attributeName"));
}
Мой примерчик:
private void updateSettingsInDB(){
// Получить значение из VO
ViewObject vo = VOUtils.getViewObjectByName(CONSTANTS_VO.SYSTEM_OPTIONS);
Row curRow = vo.first();
String OrgName = (String)curRow.getAttribute(ORG_NAME);
String Datasource = (String)curRow.getAttribute(DATA_SOURCE);
// Удалить VO
vo.first().remove();
ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl").getTransaction().postChanges();
vo.executeQuery();
Row row = vo.createRow();
row.setAttribute("SoId", 1L);
ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl").getTransaction().postChanges();
vo.executeQuery();
ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl").getTransaction().commit();
// Установить новые значения для VO
Row curRow1 = vo.first();
curRow1.setAttribute(ORG_NAME, OrgName);
curRow1.setAttribute(DATA_SOURCE, Datasource);
ADFUtils.getApplicationModuleForDataControl("AppModuleDataControl").getTransaction().commit();
}
Пока последний
public void createDepartmentRecord(Integer deptId) {
ViewObject deptVo = this.getDepartmentsVO1();
Row newRow=deptVo.createRow();
newRow.setAttribute("DepartmentId", deptId);
deptVo.insertRow(newRow);
}
http://www.awasthiashish.com/2015/07/adf-basics-how-to-invoke-model-layer.html
А нет, не последний.
public void createNewRecord(Integer deptId) {
ViewObjectImpl myVO = this.getItemSuppCountryDim1();
Row newRow = myVO.createRow();
newRow.setAttribute("myAttr1", value1);
newRow.setAttribute("myAttr2", value2);
myVO.insertRow(newRow);
}
Если какая-то беда с обновлением таблицы в которую добавляется строка, можно попробовать сделать следующее:
-- после
myVO.insertRow(newRow);
-- выполнить еще
Row[] rows = new Row[]{newRow};
myVO.refreshCollection(rows, true, true);
хз что это значит и почему, но сказали, что работает. Поэтому и записываю.