Inserting New Row in Table with Overflow Right

When generating a table with overflow right or below, it is not possible to generate the table with one or more empty rows that can be used to insert new rows. The reason for this limitation is that displaying the correct information in the overflow area, requires the notion of a current row in the underlying iterator binding, which is not available for new table rows.

To still allow users to insert a new row in such a table, we can generate a new button that creates a new row in the underlying iterator binding, and make this new row the current row, as shown in the screen shot below:
overflowRightNewRowImage:

To generate this, follow these steps:

  • Create a subclass of JhsCollectionModel, and add the following method to this subclass:
public String createNewRowAtBottomOfCurrentRange()
{
   DCIteratorBinding ib = getRangeBinding().getIteratorBinding();
   int rangeSize = ib.getRangeSize();
   int rowsInRange = ib.getAllRowsInRange().length;
   int insertPos = rowsInRange < rangeSize? rowsInRange: rangeSize - 1;
   Row row = ib.getRowSetIterator().createRow();
   applyModifiedAttrs(row, getDefaultValues());
   ib.getRowSetIterator().insertRowAtRangeIndex(insertPos,row);
   ib.setCurrentRowIndexInRange(insertPos);
   return null;
  }
  • Next, we create a custom template "myCollectionModelbean.vm" based on the standard default/misc/facesConfig/collectionModelBean.vm template. The only change you need to make in this custom template is the class name: set it to the name of your custom class instead of oracle.jheadstart.controller.jsf.bean.JhsCollectionModel.
  • Create a new template "newRowButton.vm" with the following content:
<af:commandButton
action="#{#COLLECTION_MODEL_BEAN().createNewRowAtBottomOfCurrentRange}"
textAndAccessKey="${JHS.nls(${JHS.current.group.displayTitleSingular},
  "NEW_BUTTON_LABEL_${JHS.current.group.name}", "NEW_BUTTON_LABEL" )}"
immediate="true"
onclick="return alertForChanges();"
id="${JHS.current.group.name}NewRowButton">
<f:actionListener
type="oracle.jheadstart.controller.jsf.listener.DoRollbackActionListener"
/>
<af:resetActionListener/>
</af:commandButton>
  • Now, we must configure the generator to use these two custom templates: select the correct group in the navigator and click the Templates tab.
  • In the templates tab, set NEW_BUTTON_NOT_IN_FORM_LAYOUT to the name of your custom button template, for example myapp/button/newRowButton.vm.
  • Set template COLLECTION_MODEL_BEAN to the name of your custom collectionModel template, for example myapp/misc/facesConfig/myCollectionModelBean.vm.
  • Run the JHeadstart Application Generator
  • Run your application.
Note that the New button now appears as a page level button. When you have detail groups displayed on the same page, the new button will appear as a group-level button, just below the table.
We could also have chosen to add the button to the table selection facet, just like the "Details" button generated for a "table-form" layout. However, the selection facet is only rendered when the table contains at least one existing row, which would make it impossible to create a new row in an empty table.

Finally, this example illustrates that custom templates are not just for layout customizations. They can also be used to specify the usage of custom subclasses of the JHeadstart Runtime classes, allowing you to change or extend the default JHeadstart runtime behaviors.
 

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Java EE Consultants - JHeadstart, ADF, JSF

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today