In this post I write some functions you can use those functions in your ADF application.
Set Focus to component
If you want to set focus to component( as set cursor to inputText) just send component id to this function (if inputText id =it1 and you use page template with id=pt1 so the id which you have to send to this function is pt1:it1)
Expand Table DetailStamp Programmatically
Get Viewobject attribute datatype
programmatic
This function accept 2 parameters (iterator name, attribute name) and will return the data type of this attribute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String getDataType(String iteratorName, String attributeName) | |
{ | |
BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry(); | |
DCIteratorBinding iterBind = (DCIteratorBinding) bindings.get(iteratorName); | |
ViewObject vo=iterBind.getViewObject(); | |
AttributeDefImpl attrDef = (AttributeDefImpl)vo.findAttributeDef(attributeName); | |
String datatype=attrDef.getJavaType().getName(); | |
return datatype; | |
} |
Get Viewobject attribute Database Column
Name
This function accept 2 parameters (iterator name, attribute name) and will return the database column name which map to the viewobject attribute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String getDatabaseColumnName(String Iterator, String attributeName) | |
{ | |
BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry(); | |
DCIteratorBinding iter = (DCIteratorBinding) bindings.get(Iterator); | |
ViewObject vo = iter.getViewObject(); | |
AttributeDefImpl attrDef = (AttributeDefImpl)vo.findAttributeDef(attributeName); | |
return attrDef.getColumnName(); | |
} |
Clear Table Filters
If you want to clear table filters programmatically sent table component to this function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void clearTableFilters(RichTable tableComponent) | |
{ | |
FilterableQueryDescriptor q = (FilterableQueryDescriptor) tableComponent.getFilterModel(); | |
Map<String, Object> m = q.getFilterCriteria(); | |
if (m != null) | |
{ | |
m.clear(); | |
} | |
} |
Reset af:query fields
If you want to reset af:query sent query component to this function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void resetQueryFields(RichQuery queryComponent) | |
{ | |
QueryModel queryModel = queryComponent.getModel(); | |
QueryDescriptor queryDescriptor = queryComponent.getValue(); | |
queryModel.reset(queryDescriptor); | |
} |
Invoke af:query Search Action programmatically
1- Bind the af:query in the back bean like:
2- Add af:commandButton and in it's action write this code
Show error message on adf component
1- Bind the af:query in the back bean like:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<af:query binding="#{mybean.richQuery}" ... > |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String runQuerySearchAction() | |
{ | |
QueryDescriptor queryDescriptor = getRichQuery().getValue(); | |
QueryEvent queryEvent = new QueryEvent(getRichQuery(), queryDescriptor); | |
queryEvent.setPhaseId(PhaseId.INVOKE_APPLICATION); | |
getRichQuery().queueEvent(queryEvent); | |
return null; | |
} |
Show error message on adf component
Sometime you need to remove required property from af:inputText because it may cause some problems and in the same time you need to display error message on the inputText component so you can use the following function just send the error message and the adf component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void showFieldErrorMessage(String msg, UIComponent component) | |
{ | |
FacesContext context = FacesContext.getCurrentInstance(); | |
FacesMessage message = new FacesMessage(msg); | |
message.setSeverity(FacesMessage.SEVERITY_ERROR); | |
context.addMessage(component.getClientId(context), message); | |
} |
Sort
Table Column Programmatically
If you want to sort column programmatic you can use the following function just send table component and attribute which you would like to sort and the boolean parameter (true for ascending sort and false for descending sort)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void sortTable(RichTable tableComponent, String attributeName, boolean ascending) | |
{ | |
List<SortCriterion> sortList = new ArrayList<SortCriterion>(); | |
SortCriterion sc = new SortCriterion(attributeName, ascending); | |
sortList.add(sc); | |
tableComponent.setSortCriteria(sortList); | |
} |
Reset Table Sort
After sorting in column and need to reset the sorting you can use the following function just send table component and the iterator name (which the table point to)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void resetTableSort(RichTable tableComponent, String iteratorName) | |
{ | |
BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry(); | |
DCIteratorBinding iter = (DCIteratorBinding) bindings.get(iteratorName); | |
tableComponent.queueEvent(new SortEvent(tableComponent, new ArrayList<SortCriterion>())); | |
Key currentRow = null; | |
Row row = iter.getCurrentRow(); | |
if (row != null) | |
{ | |
currentRow = row.getKey(); | |
} | |
SortCriteria[] sc = new SortCriteria[0]; | |
iter.applySortCriteria(sc); | |
iter.executeQuery(); | |
if (currentRow != null) | |
{ | |
iter.setCurrentRowWithKey(currentRow.toStringFormat(true)); | |
} | |
} |
Call
database sequence
When you want to get next value from database sequence you can use the following function just send database sequence name and it will return the next value of the sequence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static oracle.jbo.domain.Number getSequenceNextValue(String sequenceName) | |
{ | |
SequenceImpl seq = new SequenceImpl(sequenceName, getDBTransaction()); | |
return seq.getSequenceNumber(); | |
} |
Set Focus to component
If you want to set focus to component( as set cursor to inputText) just send component id to this function (if inputText id =it1 and you use page template with id=pt1 so the id which you have to send to this function is pt1:it1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void setFocus(String componentId) | |
{ | |
FacesContext facesContext = FacesContext.getCurrentInstance(); | |
ExtendedRenderKitService service = Service.getRenderKitService(facesContext, ExtendedRenderKitService.class); | |
service.addScript(facesContext, "comp = AdfPage.PAGE.findComponent('"+componentId+"'); comp.focus();"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String expandAction() // button or link action | |
{ | |
RichTable table = getMyTable(); // bind table component in backbean | |
RowKeySet rks = table.getDisclosedRowKeys(); | |
DCIteratorBinding tableIter = (DCIteratorBinding) BindingContext.getCurrent().getCurrentBindingsEntry().get("MyView1Iterator"); // Table itertor name (get it from pageDef.) | |
ViewObject vo = tableIter.getViewObject(); | |
Row r = vo.getCurrentRow(); | |
List keyList = Collections.singletonList(r.getKey()); | |
rks.add(keyList); | |
AdfFacesContext adfFacesContext = null; | |
adfFacesContext = AdfFacesContext.getCurrentInstance(); | |
adfFacesContext.addPartialTarget(table.getParent()); | |
return null; | |
} |