Search This Blog

Wednesday, October 23, 2013

Set Min and Max Dates For Date Field In OAF

Using following code, we can set Minimum and Maximum dates that users can select using Date filed in a OA page.

Minimum Date: Same date in Last Month
Maximum Date: Current  DB Date

Modify the query to get required date values in the Date Field.

*******************************************************
OAApplicationModule am = (OAApplicationModule)pageContext.getApplicationModule(webBean);

OAMessageDateFieldBean dtBean =  (OAMessageDateFieldBean)webBean.findChildRecursive("actualDate");


String dtSql= "Select add_months(sysdate,-1) min_date, sysdate max_date from dual";        
try {
        Connection conn = am.getOADBTransaction().getJdbcConnection();
        PreparedStatement stmt = conn.prepareStatement(dtSql);
        ResultSet rs = stmt.executeQuery(dtSql);
        while (rs.next()) {
              java.sql.Date minDate = rs.getDate("min_date");
              java.sql.Date maxDate = rs.getDate("max_date");
              System.out.println("Received Dates: " + minDate + " and " + maxDate);
              dtBean.setMinValue(minDate);
              dtBean.setMaxValue(maxDate);
          } // While
        } //try
 catch(Exception e){
    e.printStackTrace();
    } //catch

******************************************************

No comments:

Post a Comment