Monday, April 30, 2012

ADF: Default cursor/focus to input field using javascript


Sometimes when default properties won't work, we can use JS to set initial focus.
  • jquery is required & can be downloaded from (http://jquery.com/).
  • A dummy <af:clientAttribute> is added for field on which initial focus is required.
  • A <af:clientListener> method is added on "load" type.
<f:view>
    <af:document id="d1">
      <f:facet name="metaContainer">
        <af:resource type="javascript" source="/jquery-1.7.min.js"/>
        <af:resource type="javascript">
          function onLoadFocus() {
              $('input[type="text"]').each(function () {
                  if (isDefaultFocusField(this.name) == 'Y') {
                      this.focus();
                  }
              });
          }

          function isDefaultFocusField(compId) {
              try {
                  var adfComp = AdfPage.PAGE.findComponentByAbsoluteId(compId);
                  return adfComp.getProperty("defaultFocusField");
              }
              catch (err) {
              }
          }
        </af:resource>
      </f:facet>
      <af:form id="f1">
        <af:panelStretchLayout id="psl1">
          <f:facet name="center">
            <af:panelGroupLayout layout="scroll" id="pgl1">
              <af:inputText label="Label 1" id="it1">
                <af:clientAttribute name="defaultFocusField" value="Y"/>
              </af:inputText>
              <af:inputText label="Label 2" id="it2"/>
            </af:panelGroupLayout>
            <!-- id="af_one_column_stretched"   -->
          </f:facet>
        </af:panelStretchLayout>
      </af:form>
      <af:clientListener type="load" method="onLoadFocus"/>
    </af:document>
  </f:view>
Note: http://lspatil25.blogspot.in/2012/05/adf-make-findcomponentbyabsoluteid-js.html

ADF: Default cursor/focus to input field & default button of JSF page


For setting initial cursor/focus to input field:
  • The property named "initialFocusId" should be set of <af:document>.
  • The property named " clientComponent" should be set to "true" for that input field.

For setting default button for the form:
  • The property named "defaultCommand" of "<af:form>" should be set. By setting this property, we can press "Enter" & the button's action will be invoked.
    <af:document id="d1" initialFocusId="it1">
      <af:form id="f1" defaultCommand="cb1">
        <af:panelStretchLayout id="psl1">
          <f:facet name="center">
            <af:panelGroupLayout layout="scroll" id="pgl1">
              <af:inputText label="Label 1" id="it1" clientComponent="true"/>
              <af:inputText label="Label 2" id="it2"/>
              <af:commandButton text="commandButton 1" id="cb1"/>
            </af:panelGroupLayout>
            <!-- id="af_one_column_stretched"   -->
          </f:facet>
        </af:panelStretchLayout>
      </af:form>
    </af:document>
Note: For jsff pages, we can use <af:subform>.
<af:subform defaultcommand="cb1" id="s1" />

ADF: Including javascript/JS or CSS on JSF pages


How to include javascript or CSS on JSF page:
Drag and drop "resource" from operation pallet to page & select JS/CSS accordingly. "source" is optional, so you can either specify location or include js/css directly on page.
Note: you can include resource anywhere on page, but the more appropriate location will be inside "metaContainer" facet of <af:document >.
<f:facet name="metaContainer">
  <af:resource type="javascript" source="/js/custom.css" />
  <af:resource type="javascript">
    function lsp(){
      alert('hi');
    }
  </af:resource>
  <af:resource type="css">
    .text-label{
      color: #cdcdcd;
      font-weight: bold;
    }
  </af:resource>
</f:facet>
On page, wherever you want to call method from JS; just use <af:clientListener >.
 <af:commandbutton id="cb1" text="commandButton 1">
     <af:clientlistener method="lsp" type="action" />
  </af:commandbutton>

Saturday, April 28, 2012

ADF: IE9 Browser Issues


Sometimes when we use nested components i.e. Links, CommandMenu dropdown buttons etc. under Tree/Table component, then we encountered issues on IE9 like links are not clickable, dropdown is not opening etc.

Solution:
For Tree/Table component, we should assign "contentDelivery" property to "immediate"; so as to enable working of nested components in IE9.

Properties file outside EAR


If properties file is placed outside EAR, then there won't be any need to build ear everytime.

Steps:
1. Place the properties file/files at any location on server.
2. Include the location of properties file in classpath.
e.g. If weblogic server is used, you can make entry in server startup script.
set CLASSPATH=(PATH of .properties file without braces);%CLASSPATH%
We can then change properties file & even without building ear, new properties file will be used.

Note: If the logic is to load properties file only once, in that case server restart is needed.

Finally, simple java method to load properties file can be used:
    public static void loadPropertiesBundle(){
        Properties propertiesBundle = new Properties();
        InputStream stream = Thread.currentThread().getContextClassLoader()
                                   .getResourceAsStream("PropertiesFileName.properties");
        try {
            propertiesBundle.load(stream);
        } catch (IOException e) {
            adfLogger.log(ADFLogger.ERROR, "Error getting Property file :" + e.getStackTrace());
        }
    }

Friday, April 27, 2012

Identifying "Type" of ADF "Set Property Listener"



Sometimes we often wonder, which type to select from "Set Property Listener" after inserting it into common components.
The best way to find is, look into the property inspector of component for all available listeners.

e.g. If on <af:commandButton> component, we are adding "Set Property Listener".
Then from property inspector we can know - action, launch & return are supported types.

Similarly, for <af:inputText> component the type available is only "valueChange".

Note: Improper use can result into: javax.faces.FacesException: javax.servlet.ServletException: java.lang.NoSuchMethodException

Friday, April 13, 2012

Unix: Adding a new disk to VM Image


1.Execute the following command to see all the disks that are present on the machine
fdisk -l
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000ac560   

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         993     7976241   83  Linux
/dev/sda2             994        1044      409657+   5  Extended
/dev/sda5             994        1044      409626   82  Linux swap / Solaris

Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xe8768ce7
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         391     3140676   83  Linux Disk

/dev/sdc: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/sdc doesn't contain a valid partition table


2.Execute the following commands to create the partitions
fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x261e87e6.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
   p
   Partition number (1-4): 1
   First cylinder (1-1305, default 1):
   Using default value 1
   Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305):
   Using default value 1305

   Command (m for help): w
   The partition table has been altered!

   Calling ioctl() to re-read partition table.
   Syncing disks.


3.Create the file system
mkfs.ext3 /dev/sdc1

4.mount the file system
mount /dev/sdc /filepath
  

Unix: Increase system's file descriptor size


This is a common problem with DB servers with heavy transactions.
The server usually throws “too many open files” errors and no new processes could be started.

check the fd size via:
$ulimit -a   # see all the kernel parameters
$ulimit -n   #see the number of open files
$ulimit -n 9000  #  set the number open files to 9000

First, in order to set this options automatically  you have to edit the etc/security/limits.conf file.
root soft  nofile 9000
root hard  nofile 65000

Second you have to add a line in the /etc/pam.d/common-session file:
$ sudo gedit /etc/pam.d/common-session #open the file in gedit
 
Then add the line:
session required pam_limits.so

Unix: Swap Size Increase




To check memory:
free -m
Sample output:
             total       used       free     shared    buffers     cached
Mem:          8105       1292       6812          0         38        483

-/+ buffers/cache:        770       7334
Swap:         1906          0       1906

Swap size increment helps to improve system performance. Suppose we are increasing swap size by 2GB.
dd if=/dev/zero of=/swap_file bs=1M count=2048

This will create file (swapfile) of size 2GB
mkswap /swap_file

add this file to your swap pool
swapon /swap_file

free -m
Sample output:
             total       used       free     shared    buffers     cached
Mem:          8105       1292       6812          0         38        483

-/+ buffers/cache:        770       7334
Swap:         XXXX          0       1906

To make it turn on at every bootup, open up /etc/fstab:
vi /etc/fstab
/swap_file none swap sw 0 0

 

Ubuntu 3GB Ram Limitation and Solution


Ubuntu 32-Bit machine is bound to use maximum of 3 GB RAM, Below are the steps to use > 3GB RAM.
$ free -m
Sample output:
             total       used       free     shared    buffers     cached
Mem:          3291        801       2489          0         95        342

-/+ buffers/cache:        363       2927
Swap:         1906          0       1906

Open terminal and type the following command if you are using Ubuntu version Ubuntu v9.04 and earlier:
$ sudo apt-get update
$ sudo sudo apt-get install linux-headers-server linux-image-server linux-server

If you are using Ubuntu v9.10 (Karmic Koala) and above, enter:
$ sudo apt-get install linux-generic-pae linux-headers-generic-pae

Once kernel images installed, just reboot your workstation, type:
$ sudo reboot

After reboot, login into your system and type the following command to verify memory usage:
$ free -m
Sample output:
             total       used       free     shared    buffers     cached
Mem:          8105       1292       6812          0         38        483

-/+ buffers/cache:        770       7334
Swap:         1906          0       1906