keep below code at voimpl
import oracle.jbo.Row;
import oracle.jbo.Row;
public void insertRow(Row row){
Row lastRow = this.last();
if (lastRow != null){
int range = this.getRangeIndexOf(lastRow) +1;
this.insertRowAtRangeIndex(range, row);
this.setCurrentRow(row);
}else{
super.insertRow(row);
}
}
Creating new row on pressing “TAB” key in the last cell of Table.
There are three main steps
- First add clientListener and serverListener to last column of ADF table.<af:column sortproperty="#{bindings.EmployeesView1.hints.LastName.name}" sortable="false" headertext="#{bindings.EmployeesView1.hints.LastName.label}" id="c3"> <af:inputtext value="#{row.bindings.LastName.inputValue}" label="#{bindings.EmployeesView1.hints.LastName.label}" required="#{bindings.EmployeesView1.hints.LastName.mandatory}" columns="#{bindings.EmployeesView1.hints.LastName.displayWidth}" maximumlength="#{bindings.EmployeesView1.hints.LastName.precision}" shortdesc="#{bindings.EmployeesView1.hints.LastName.tooltip}" id="it1" autosubmit="true"> <af:clientlistener method="tabkeypressed" type="keyPress"> <af:serverlistener type="tabpress" method="#{pageFlowScope.TestBean.tabPressed}"> <f:validator binding="#{row.bindings.LastName.validator}"> </f:validator></af:serverlistener></af:clientlistener></af:inputtext> </af:column>
- Following java script method is called when user press any key on last table cell’s text field. In java script code we are identifying the TAB key, if user presses “TAB” key then managed bean method is called using server listener.
- function tabkeypressed(evt){
- var _keyCode = evt.getKeyCode();
- var comp = evt.getSource();
- if (_keyCode == AdfKeyStroke.TAB_KEY ){
- AdfCustomEvent.queue(comp, "tabpress",{}, true);
- evt.cancel();
- }
- }
- Managed bean method checks whether current row is the last row or not. If current row is last row of the table, then it will create a new row at the end of the table.
- public void tabPressed(ClientEvent clientEvent) {
- BindingContext bindingctx=BindingContext.getCurrent();
- BindingContainer binding=bindingctx.getCurrentBindingsEntry();
- DCBindingContainer bindingsImpl = (DCBindingContainer) binding;
- DCIteratorBinding dciter = bindingsImpl.findIteratorBinding("EmployeesView1Iterator");
- ViewObject vo=dciter.getViewObject();
- //Return current row index no.
- int index=vo.getCurrentRowIndex()+1;
- //get the last row no.
- long cnt=vo.getEstimatedRowCount();
- if(cnt==index)
- {
- createRow();
- AdfFacesContext.getCurrentInstance().addPartialTarget(emptab);
- }
- }
- public void createRow()
- {
- //Get ViewObject
- BindingContext bindingctx=BindingContext.getCurrent();
- BindingContainer binding=bindingctx.getCurrentBindingsEntry();
- DCBindingContainer bindingsImpl = (DCBindingContainer) binding;
- DCIteratorBinding dciter = bindingsImpl.findIteratorBinding("EmployeesView1Iterator");
- //Get current data RowSetIterator
- RowSetIterator rsi =dciter.getRowSetIterator();
- //Get last Row of current Iterator
- Row lRow = rsi.last();
- //Get index of the last row
- int lrIndex = rsi.getRangeIndexOf(lRow);
- //Create a new row
- Row nRow = rsi.createRow();
- //Initialize that row
- nRow.setNewRowState(Row.STATUS_INITIALIZED);
- //Add row in last of current rowset
- rsi.insertRowAtRangeIndex(lrIndex + 1, nRow);
- //Set newly created row as current row
- rsi.setCurrentRow(nRow);
- }
No comments:
Post a Comment