Tuesday, August 2, 2016

PrimeFaces fileUpload javascript properties

fileuplaod_wgt.buttonBar.find("button.cancel")
fileuplaod_wgt.buttonBar.find("button.start")
fileuplaod_wgt.buttonBar.find('input[type=file]')

upload content
upload.uploadContent'

number of uploaded files
var files = fileuplaod_wgt.uploadContent.find('.files .template-upload');

invalid files
fileuplaod_wgt.uploadContent.find("tr.ui-state-error");



reference:
http://stackoverflow.com/questions/14881131/primefaces-upload-how-to-only-allow-one-upload-in-advance-mode

Monday, June 27, 2016

How to disable Choose button in PrimeFaces fileupload component


The javascript function is to disable "Choose" button in <p:fileUpload /> component a file has been uploaded.
It is applicable to PrimeFaces 3.5

function below will find the Choose button from the passed in widgetVar when the file component onchange,
if the number of uploaded files more than 1,
disable the Choose button.


<script type="text/javascript">

    function onchangeDisableChooseBtn(upload_widget_var) {
        if(upload_widget_var.buttonBar.find('input[type=file]').get(0).type == 'file') {
            upload_widget_var.buttonBar.find('input[type=file]').change(function() {
                var files = upload_widget_var.uploadContent.find('.files tr');
                if (files.length >= 1) {
                    upload_widget_var.buttonBar.find('input[type=file]').get(0).disabled=true;
                }
                onchangeDisableChooseBtn(upload_widget);
            });
        }
    }

</script>



Done!!

Wednesday, June 22, 2016

How to hide icons in PrimeFaces fileUpload component.

PrimeFaces version: 3.5

to hide icon in choose button

  .fileupload-buttonbar .fileinput-button .ui-icon-plusthick{
         display: none !important;
 }


to hide icon in upload button

 .fileupload-buttonbar .start .ui-icon-arrowreturnthick-1-n{
         display: none !important;
 }


to hide icon in cancel button


 .fileupload-buttonbar .cancel .ui-icon-cancel{
         display: none !important;
 }




Done!!

Tuesday, June 21, 2016

Blinking Text effect


<span id="elementIdToBlink">    
   any text to blink.
</span> 

<script>
$(function(){
    // Self-executing recursive animation
    (function pulse(){
        $('#elementIdToBlink').delay(1000).fadeOut('slow').delay(50).fadeIn('slow',pulse);
    })();
});
</script>


reference:
http://stackoverflow.com/questions/7223503/jquery-pulsate-times



Done!!

Monday, June 20, 2016

Encryption/Decryption with Java

Following are the steps to encrypt/decrypt with Java
1. determine the encryption key
2. get the keyspec from the encryption key  
3. instantiate the secretkeyfactory
4. generate the secretkey from the keyfactory
5. instantiate the cipher
6. encrypt/decrypt the string into byte array
7. encode to base 64
8. return the encrypted/decrypted string

Sample Code

    public static final String key = "kianworknotes";


    public static String encrypt(String str) {
        try {            
            byte[] keyValue = key.getBytes();

            DESKeySpec desKeySpec = new DESKeySpec(keyValue);
            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
            SecretKey key = keyFactory.generateSecret(desKeySpec);

            Cipher ecipher = Cipher.getInstance("DES");
            ecipher.init(Cipher.ENCRYPT_MODE, key);

            byte[] utf8 = str.getBytes("UTF8");
            byte[] enc = ecipher.doFinal(utf8);

            enc = BASE64EncoderStream.encode(enc);
            return new String(enc);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    public static String decrypt(String str) {
        try {    
            byte[] keyValue = key.getBytes();

            DESKeySpec desKeySpec = new DESKeySpec(keyValue);
            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
            SecretKey key = keyFactory.generateSecret(desKeySpec);

            Cipher dcipher = Cipher.getInstance("DES");
            dcipher.init(Cipher.DECRYPT_MODE, key);

            byte[] dec = BASE64DecoderStream.decode(str.getBytes());
            byte[] utf8 = dcipher.doFinal(dec);

            return new String(utf8, "UTF8");

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }



Done!!

LinkWithin

Related Posts Plugin for WordPress, Blogger...