How to get the current system Date and Time in Java?

In order to get the current system Date and Time include the below code in you java class –

import oracle.jbo.domain.Date;

  /**
      * Get Current Date
      * @return
      */
public Date getCurrentDateTime()
    {
    return new Date(new java.sql.Timestamp(System.currentTimeMillis()));
    }

The getCurrentDateTime() method returns the system Date and Time in the format  “2011-08-08 17:02:24.0”.

Posted in Java | Tagged , , , , | 4 Comments

How to display the text-area in the Table in ADF.

Inorder to show the multiple lines of text data (generally for Description column) in the table column, you have to increase the number of rows in the <inputText> tag as shown

<af:column sortProperty=”DocumentDescr” filterable=”true”

                         sortable=”true”

                         headerText=”#{bindings.AttachmentsVO1.hints.DocumentDescr.label}”

                         id=”c1″ align=”center” width=”240″>

                <af:inputText value=”#{row.bindings.DocumentDescr.inputValue}”

                              label=”#{bindings.AttachmentsVO1.hints.DocumentDescr.label}”

                              required=”#{bindings.AttachmentsVO1.hints.DocumentDescr.mandatory}”

                              columns=”#{bindings.AttachmentsVO1.hints.DocumentDescr.displayWidth}”

                              maximumLength=”#{bindings.AttachmentsVO1.hints.DocumentDescr.precision}”

                              shortDesc=”#{bindings.AttachmentsVO1.hints.DocumentDescr.tooltip}”

                              readOnly=”#{!row.bindings.IsRemoveAttachmentEnabled.inputValue}”

                              rows=”4″

                             id=”it4″>

                  <f:validator binding=”#{row.bindings.DocumentDescr.validator}”/>

                </af:inputText>

              </af:column>

Default value for “rows” is 1. You can give any positive number. It will be displayed (‘Document Description’ field) as below –

Posted in ADF (Application Development Framework) | Tagged , , , , , , , , | 2 Comments

How to conditionally enable / disable the column contents in the ADF 11g table

Scenario: I have below contents in my table –

In the “Remove Attachment” column have Delete Icon when clicked, it will deletes the record. I want to Enable this Delete Icon based on the Condition. Then it will look as below –

Solution: To achieve the above functionality follow below steps –

Step 1: Create a Transient atribute in your View Object (VO) that is used in the table as shown

a)      Double click on the View Object.

b)      Go to Attributes section in the View Object.

c)      Click on the New Attribute option as shown  –

       d) In the “New View Object Attribute” window give the name for the Transient atribute, I have used “IsRemoveAttachmentEnabled” as Name. In the same window, under Updatable section, select the “Always” radio button. By default this option will be with “Never” and Click “OK” as shown –

          e) Now the new Transient attribute (“IsRemoveAttachmentEnabled”) will get created in the View Object as shown

Step 2: Refresh the Data Control and you can see the newly added Transient attribute under the View Object as shown –

Step 3: Now you need to add this transient attribute (“IsRemoveAttachmentEnabled”) to your Bindings in the JSPX page.

             a)  Go to your JSPX bindings section and select the iterator (AttachmentsVO1) that you were using for your table to display the records.

             b) Select the Iterator and click on the Edit icon as shown in the above screen shot and “Edit Tree Bindings” window will be displayed. “Under Available Attributes” section select the newly created Transient attribute and move it to the “Display Attributes” section as shown below. Now you will be able to access the Transient variable in your JSPX page.

Step 4: Now to include the conditional logic create a method in the Managed bean as shown below

/**

   * Set values on transient attributes, set read-only indicators, etc.  Called by View, Copy, and Reverse listeners
   * @param
   */
  public void enableRemoveAttachment() {
      try{
                BindingContext bc = BindingContext.getCurrent();
                DCBindingContainer bindings = (DCBindingContainer)bc.getCurrentBindingsEntry();
              // Get the Attachments iteraor
              DCIteratorBinding glIter = bindings.findIteratorBinding(“AttachmentsVO1“);
                if (glIter != null && glIter.getRowSetIterator().getRowCount() > 0) {
                    RowSetIterator rsi = glIter.getViewObject().createRowSetIterator(null);
                    Row glRow;
                    while (rsi.next() != null) {
                        glRow = rsi.getCurrentRow();
                        // Set “rendered” indicators
                        if (Your_Conditional_Logic){
                                    glRow.setAttribute(“IsRemoveAttachmentEnabled”, “false“);
                        }else{
                          glRow.setAttribute(“IsRemoveAttachmentEnabled”, “true“);
                        }
                    }
                    rsi.closeRowSetIterator();
                }
      }catch(Exception e){
        e.printStackTrace();
        throw new RuntimeException(e);
      }
  }

In the above method (enableRemoveAttachment()) based on your condition you are setting the values (true, false) to the Transient attribute for each row in the iterator. This Transient attribute value we will use for RENDERED parameter for the column, where we want to conditionally display the column contents in the table in JSPX page.

In my case, I have done as below –

<af:column id=”c8″ headerText=”Remove Attachment” align=”center” width=”80″>
                <af:commandImageLink id=”cil1″
                                     icon=”/resources/graphics/DeleteIcon.gif”
                                     actionListener=”#{UploadFile.confirmDelete}”
                                     text=” “
                                     disabled=”false”
                                     inlineStyle=”text-decoration:underline;”
                                     rendered=”#{row.bindings.IsRemoveAttachmentEnabled.inputValue}“>
                </af:commandImageLink>
              </af:column>

By doing this way, based on the Transient attribute values (true, false) the Command link under the “Remove Attachment” column is Rendered and the outcome is as below –

The above approach can be used for any other parameter in the ADF tags, such as “read-only” etc.

If you want to call the method “enableRemoveAttachment()” from Managed Bean before the JSPX page loads, to know how to call a method on JSPA page loads click here

Posted in ADF (Application Development Framework) | Tagged , , , , , , , | 3 Comments

How to invoke a method from Managed Bean when JSPX Page Loads in ADF

Scenario: In order to restrict the number displayed rows in the table, I have to set the View Criteria on the Iterator before the page loads.

Solution: I have created a method (fetchSourceRecords()) in the Managed bean (Attachments.java) in which I’m setting the View Criteria on the iterator. In order to call this method (fetchSourceRecords()) on Page loads

1) You have to add the below code into your Managed bean (Attachments.java).

public void beforePhase(PagePhaseEvent pagePhaseEvent) {
if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_MODEL_ID) {
onPageLoad();
}
}

public void afterPhase(PagePhaseEvent pagePhaseEvent) {
if (pagePhaseEvent.getPhaseId() == Lifecycle.PREPARE_RENDER_ID) {
// onPagePreRender();
}
}

public void onPageLoad() {
if (!AdfFacesContext.getCurrentInstance().isPostback()) {
// add your onPageLoad event here

// to set the View Criteria on the Iterator
fetchSourceRecords();
}
}

2) Your Managed bean should implements PagePhaseListener as shown below –

public class Attachments implements PagePhaseListener{ }

You have to Import “oracle.adf.controller.v2.lifecycle.PagePhaseListener;”

3) Next, in your JSPX page defination make sure you add the ControllerClass that points to the managed bean that handles the onPageLoad event.

/* PageDef file */
<pageDefinition xmlns=”http://xmlns.oracle.com/adfm/uimodel&#8221;
version=”11.1.1.51.88″ id=”SamplePageDef” Package=”com.sample.view
ControllerClass=”#{Attachments}”>

</pageDefinition>

In the Page definition file specify the package path in “Package” attribute and Managed bean class name in “ControllerClass” attribute.

By this whenever you page loads, the onPageLoad() method gets invoked which inturn invokes the fetchSourceRecords() method. You can even call multiple methods in onPageLoad() method.

Posted in ADF (Application Development Framework) | Tagged , , , , | 13 Comments

How to display the Date and Time format in ADF page

In this post you will know how to display the DATE and TIME on the JSPX page.

If you want to display the DATE format in “DD-MON-YYYY ” and Time in “Hour:Min:Sec AM/PM do as below –

12 hour format

In View Object (VO), Under Attributes, for the DATE column, the hints should have “dd-MMM-yyyy hh:mm:ss a” value.

dd-MMM-yyyy is for Date

hh:mm:ss is for Time

a is for AM/PM

This displays the value in the JSPX page as 12-Jun-2011 04:45:24 PM.

24 hour format

In View Object (VO), Under Attributes, for the DATE column, the hints should have “dd-MMM-yyyy hh:mm:ss” value.

dd-MMM-yyyy is for Date

hh:mm:ss is for Time

This displays the value in the JSPX page as 12-Jun-2011 16:45:24.

The above method works fine to display the Date and Time even in the Table in JSPX page.

Note: The above will work fine when we want to display only in the jspx page. But if we want to insert into the table for this DATE column we need to convert the format as the sysdate which will be accepted by the table.

Posted in ADF (Application Development Framework) | Tagged , , , , , , | 4 Comments

Resolution for Invalid Column Index error in ADF.

Scenario: Created an Entity object (EO) on the table and created a View object (VO) on the Entity object. Now a DATE column is added to the table. The newly added DATE column is updated into the Entity object from the table. The newly added DATE column is updated into the View Object from the Entity object. Now from the Data Controls, the newly added DATE column is drag and drop in to the JSPX page. When executed below error is displaying in the screen –

Reason: The View Object (VO) query does not contain the newly added DATE column.

Solution: We have to update the query with the newly added DATE column in the View Object (VO).

Posted in ADF (Application Development Framework) | Tagged , , , , , , , | 1 Comment

How to make a field mandatory in JSPX page in ADF

In this scenario, we need to make <inputListOfValues> field as Mandatory, which means no NULL values are accepted and User cannot enter NULL value in the Field. We need to display an Error message when ever User submits the form without any value.

This solution works well with any field which accepts “required” property attribute.

So in my case I dragged and dropped the column from the data control as a LOV then the below code is added in the JSPX page –

                           <af:inputListOfValues id=”fiscalYear1Id”
                                                      popupTitle=”Search and Select: #{bindings.FiscalYear1.hints.label}”
                                                      value=”#{pageFlowScope.Bean.fiscalYear}”
                                                      label=”#{bindings.FiscalYear1.hints.label}”
                                                      model=”#{bindings.FiscalYear1.listOfValuesModel}”
                                                      required=”#{bindings.FiscalYear1.hints.mandatory}
                                                      showRequired=”true” editMode=”input”
                                                      columns=”#{bindings.FiscalYear1.hints.displayWidth}”
                                                      shortDesc=”#{bindings.FiscalYear1.hints.tooltip}”>
                                  <f:validator binding=”#{bindings.FiscalYear1.validator}”/>
                                </af:inputListOfValues>

From the above code we have “required” attribute which is to make the field as Mandatory one. But this did not work in my case. So I have to modify the “required” attribute value from =”#{bindings.FiscalYear1.hints.mandatory}” to “true”.

                             <af:inputListOfValues id=”fiscalYear1Id”
                                                      popupTitle=”Search and Select: #{bindings.FiscalYear1.hints.label}”
                                                      value=”#{pageFlowScope.Bean.fiscalYear}”
                                                      label=”#{bindings.FiscalYear1.hints.label}”
                                                      model=”#{bindings.FiscalYear1.listOfValuesModel}”
                                                      required=”true
                                                      showRequired=”true” editMode=”input”
                                                      columns=”#{bindings.FiscalYear1.hints.displayWidth}”
                                                      shortDesc=”#{bindings.FiscalYear1.hints.tooltip}”>
                                  <f:validator binding=”#{bindings.FiscalYear1.validator}”/>
                                </af:inputListOfValues>
 

 By this the the field became as Mandatory and it shows the below error message when the user submits with NULL value.

showRequired=”true” displays the ‘*’ before the field.

 

Posted in ADF (Application Development Framework) | Tagged , , , , , , | 2 Comments

How to get the Current Date and Time in the Managed Bean?

In order to get the Current date and time in the managed bean, include the below method –

  /**
    * Get Current Date
    * @return
    */
    public Date getCurrentDateTime()
  {
  return new Date(new java.sql.Timestamp(System.currentTimeMillis()));
  }
 
 

The above method getCurrentDateTime() returns the Date value.  You can use this method anytime, where you want the current Date and Time.

Posted in ADF (Application Development Framework) | Tagged , , , | Leave a comment

How to set the label for any field remotedly (by using other tags) in ADF 11g

If we want to format the display of the label for any field, we can use the <outputLabel> tag for that, as we get more options on <outputLabel> tag. The for attribute of the <outputLabel> tag should be the ID value of the field to which we are applying the label.

The sameple code is shown below –

<af:outputLabel value=”No Internal Dual Coverage Terms :” id=”ol1″ for=”soc1“/>

 

<af:selectOneChoice value=”#{bindings.NoIntDualCovgTerms.inputValue}”
                                  required=”#{bindings.NoIntDualCovgTerms.hints.mandatory}”
                                  shortDesc=”#{bindings.NoIntDualCovgTerms.hints.tooltip}”
                                  id=”soc1“>
                <f:selectItems value=”#{bindings.NoIntDualCovgTerms.items}”
                               id=”si1″/>
              </af:selectOneChoice>

The above method to set the label remotely can be used for any Tag in JSF page, which ever accepts the For attribute.

Posted in ADF (Application Development Framework) | Tagged , , , , , | 1 Comment

How to wrap the Label before any fields (input, LOV, Checkbox, Radia button etc.) in ADF 11g

In normal the label for any field will be in a single striaght line. If we want it to wrap into two lines before the field we need to use <outputFormatted> tag as shown below –

    <af:outputFormatted id=”of1″ value=”No Internal Dual <br>Coverage Terms : </br>“>
   </af:outputFormatted>
 

 You can include the HTML tags in between the Value attribute. By doing so this will be shown as an error with warning message in the JSPX page but still it works fine when executed.

Posted in ADF (Application Development Framework) | Tagged , , , , | 1 Comment