Displaying UI attribute which holds both positive ,negative currency and displaying negative currency with brackets ex:($123.00 ) instead of -$123.00 .
Solution:
In convertNumber tag change pattern to "#,##0.00;(#,##0.00)"
Here semi-colon(;) is separating the value of the format which is secondary format for negative currency.
Middleware Techincal Issue Resolution
Middlware, Java, Oracle ADF, OpenShift and Other Web Technologies
Tuesday, October 4, 2016
Tuesday, September 20, 2016
ADF : Export to Excel Programmatically using fileDownloadActionListener tag
Another way exporting table results into excel is by using fileDownloadActionListener on button action
Drop fileDownloadActionListener tag on button , set content type to application/vnd.ms-excel and bind it to bean method.
In Bean code get desired rows append attribute value with '\t' for next cell and '\n' next line for next row in excel
private static final String LINEBREAK = "\n";
private static final String NEXTCELL = "\t";
public void exportToExcel(FacesContext facesContext, OutputStream outputStream) throws IOException {
DCBindingContainer dc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding binding = dc.findIteratorBinding("EmployeesVO1Iterator");
ViewObject vo = binding.getViewObject();
StringBuilder sb = new StringBuilder();
sb.append("First Name").append(NEXTCELL).append("last Name").append(NEXTCELL).append("Email").append(LINEBREAK);
vo.setCurrentRow(vo.first());
Row current = vo.getCurrentRow();
while (current != null) {
String firstName = (String)current.getAttribute("FirstName");
String lastName = (String)current.getAttribute("LastName");
String email = (String)current.getAttribute("Email");
sb.append(firstName).append(NEXTCELL).append(lastName).append(NEXTCELL).append(email).append(NEXTCELL).append(LINEBREAK);
current = vo.next();
}
outputStream.write(sb.toString().getBytes());
outputStream.flush();
}
Output
Employees table will show only 3 rows
Click on export results button will export data into excel ,below is result
Happy Learning !!
Wednesday, September 14, 2016
Setting table current row using custom selection listener
For implementing custom selection listener on table, update default selection listener by creating SelectionEvent bean reference
New custom table selection listener will be
selectionListener="#{pageFlowScope.SampleBean.customSelectionListener}"
Snippet code to set current row on row selection , for this sample First name is printed on row selection
public void customSelectionListener(SelectionEvent selectionEvent) {
RichTable _table = (RichTable)selectionEvent.getSource();
CollectionModel model = (CollectionModel)_table.getValue();
JUCtrlHierBinding _binding = (JUCtrlHierBinding)model.getWrappedData();
DCIteratorBinding iteratorBinding = _binding.getDCIteratorBinding();
Object _selectedRowData = _table.getSelectedRowData();
JUCtrlHierNodeBinding node = (JUCtrlHierNodeBinding)_selectedRowData;
Key rwKey = node.getRowKey();
iteratorBinding.setCurrentRowWithKey(rwKey.toStringFormat(true));
DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding itorBinding = bindings.findIteratorBinding("EmployeesVO1Iterator");
System.out.println(itorBinding.getCurrentRow().getAttribute("FirstName"));
}
Output
New custom table selection listener will be
selectionListener="#{pageFlowScope.SampleBean.customSelectionListener}"
Snippet code to set current row on row selection , for this sample First name is printed on row selection
public void customSelectionListener(SelectionEvent selectionEvent) {
RichTable _table = (RichTable)selectionEvent.getSource();
CollectionModel model = (CollectionModel)_table.getValue();
JUCtrlHierBinding _binding = (JUCtrlHierBinding)model.getWrappedData();
DCIteratorBinding iteratorBinding = _binding.getDCIteratorBinding();
Object _selectedRowData = _table.getSelectedRowData();
JUCtrlHierNodeBinding node = (JUCtrlHierNodeBinding)_selectedRowData;
Key rwKey = node.getRowKey();
iteratorBinding.setCurrentRowWithKey(rwKey.toStringFormat(true));
DCBindingContainer bindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding itorBinding = bindings.findIteratorBinding("EmployeesVO1Iterator");
System.out.println(itorBinding.getCurrentRow().getAttribute("FirstName"));
}
Output
Getting current date and time stamp in oracle.jbo.domain.Date format
To get the current system date and time stamp use below snippet code
import oracle.jbo.domain.Date;
public Date getCurrentDomainDate(){
return new Date(new java.sql.Timestamp(System.currentTimeMillis()));
}
Output format
“2016-09-14 14:47:31.0”.
import oracle.jbo.domain.Date;
public Date getCurrentDomainDate(){
return new Date(new java.sql.Timestamp(System.currentTimeMillis()));
}
Output format
“2016-09-14 14:47:31.0”.
Tuesday, September 13, 2016
Passing Parameters from Manage bean to JavaScript in af:resource tag
There are certain scenario where on button click you execute some logic and send parameter to JavaScript to perform some operation. If you ran into similar kind of scenario ,below is one of the way to implemented.
For this sample on button click JavaScript Function is invoked sending parameter to open a URL('www.google.com') in this case
//Execute some logic above
FacesContext facesContext = FacesContext.getCurrentInstance();
ExtendedRenderKitService service =
org.apache.myfaces.trinidad.util.Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);
service.addScript(facesContext, "launchURL('" + "https://www.google.com/" + "');");
On the page resource tag is added and a function which accepts a parameter inside function window.open() is called with the pararmeter send from bean
Happy Coding !!!
For this sample on button click JavaScript Function is invoked sending parameter to open a URL('www.google.com') in this case
//Execute some logic above
FacesContext facesContext = FacesContext.getCurrentInstance();
ExtendedRenderKitService service =
org.apache.myfaces.trinidad.util.Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);
service.addScript(facesContext, "launchURL('" + "https://www.google.com/" + "');");
On the page resource tag is added and a function which accepts a parameter inside function window.open() is called with the pararmeter send from bean
Happy Coding !!!
Programmatically invoking URL/TaskFlow in new window tab using JavaScript from bean
One way of invoking JavaScript call from bean and invoking a URL / TaskFlow in new window Tab
Following snippet is way to invoke JavaScript from bean, which accepts url as an input parameter
StringBuffer sb = new StringBuffer();
sb.append("var winPop = false;");
sb.append("if(winPop && !winPop.closed){ ");
sb.append(" winPop.focus(); }");
sb.append("else{ ");
sb.append("winPop = window.open(\"" + url + "\", \"winPop\"); } ");
ExtendedRenderKitService erks =
Service.getRenderKitService(FacesContext.getCurrentInstance(), ExtendedRenderKitService.class);
StringBuilder script = new StringBuilder();
script.append(sb.toString());
erks.addScript(FacesContext.getCurrentInstance(), script.toString());
As per this Sample ,on button click TaskFlow/URL will be launched in new window tab.
For invoking TaskFlow as URL following property need to be set on TaskFlow
Bean snippet to invoke TaskFlow programmatically using JavaScript on button click
Output
Button on page
Click on button ,TaskFlow opens in new window tab
Saturday, September 10, 2016
Set current row programmatically for af:table programmatically from managead bean using POJO
Set POJO table current row
One of the ways to set current row is
//Table binding
private RichTable tableBinding;
RowKeySet rowKeySet = tableBinding.getSelectedRowKeys();
rowKeySet.clear();
//Add row index in rowKeySet.add();
//rowKeySet.add();
SelectionEvent selectEvent = new SelectionEvent(tableBinding.getSelectedRowKeys(), rowKeySet, tableBinding);
selectEvent.queue();
1.Person Object is created with first name , last name and middle initials
2. Create a managed bean for af:table, this managed bean uses Person Object to add data to table ,A List with person is used to add data. I have declared first name, last name and middle initials to bind to input value .
3.Drag and drop af:table from component palette ,keep necessary columns and in Value attribute of table bind with List<Person> and change column output text values .
4. Add a button , bind input text values with bean first name, last name and middle initials references . Add action listener for button in bean.
5. In action listener we will add the values from first name, last name and middle initials to personList and set current programmatically.
As current row is set for the last added person added , that person detail row is highlighted here
Happy Coding !!!
Subscribe to:
Posts (Atom)