Saturday, 22 September 2012

How to get EnvironmentSpecificParam value from xml in JSP and Controller

 //Make the Entry in applicationContext.xml

<context:property-placeholder properties-ref="environmentSpecificParam" />

<util:properties id="environmentSpecificParam">

<prop key="datasourceJNDI">Something</prop>
        <prop key="tablePrefix">Something.</prop>
        <prop key="schema">Something</prop>
        <prop key="encryptionKey">Something</prop>
        <prop key="databaseUserId">Something</prop>
        <prop key="databasePassword">Something</prop>
       
        <!-- Industry Potential DataSource Details -->
        <prop key="indPotentialDatasourceJNDI">Something</prop>
        <prop key="tablePrefix">Something.</prop>
        <prop key="indPotentail_schema">Something</prop>
       
       
        <!-- ScoreCard DataSource Details -->
        <prop key="scoreCardDatasourceJNDI">Something</prop>
        <prop key="scoreCardTablePrefix">Something.</prop>
        <prop key="scoreCardSchema">Something</prop>
        <prop key="scoreCardDatabaseUserId">Something</prop>
        <prop key="scoreCardDatabasePassword">Something</prop>
       
        <prop key="SomeURL">https://some.js</prop>

        <!--Added by BM54284 -->
        <prop key="logout">https://abc.com/servlet/LogOutServlet</prop>


</util:properties>



//Get this in Controller like

@Value("#{environmentSpecificParam.logout}")
    private String logout;
@Value("#{environmentSpecificParam.gscURL}")
    private String SomeURL;

//Add like this to get in JSP
model.addAttribute("someURL", SomeURL);


//Get this in JSP like
<script type="text/javascript" src="${SomeURL}"></script>

Disable the content and uncheck the check boxes on load of the body

//Call  this function on load of the body 

function disableAndUncheckOnLoad(){
$('.wrap').attr('disabled', 'disabled');
$('input').attr('disabled', 'disabled');
$('input[type=checkbox]').each(function(){
  this.checked = false;
});


Friday, 21 September 2012

Date Validation in JavaScript

/**
 * End Date Validation
 * @returns {Boolean}
 */
function endDateCheck(){
    var startDatechk = $('#datepickerStart').val();
    var enddatechk = $('#datepickerEnd').val();
    if(startDatechk != ''){
        if(Date.parse(enddatechk) > new Date() || Date.parse(enddatechk) < Date.parse(startDatechk)){
            alert("End date should be in between the start date and current date");
            $('#datepickerEnd').val('');
            return false;
        }
    }else if(Date.parse(enddatechk) > new Date() ){
        alert("End date should be in between the start date and current date");
        $('#datepickerEnd').val('');
        return false;
    }
    $('#datepickerEnd').datepicker("hide");
    return false;
}

/**
 * Start Date Validation
 * @returns {Boolean}
 */
function startDateCheck(){
    var startDatechk = $('#datepickerStart').val();
    var enddatechk = $('#datepickerEnd').val();
    if(Date.parse(startDatechk) > new Date() || Date.parse(enddatechk) < Date.parse(startDatechk)){
        alert("Start date should be bofore current date and end date");
        $('#datepickerStart').val('');
        return false;
    }
    $('#datepickerStart').datepicker("hide");
    return false;
}



//Call this onLoad of the body

$(document).ready(function() {
var startYear = new Date().getFullYear() - 3;
var dateRange = startYear+":"+new Date().getFullYear();
 $('#datepickerStart').datepicker({
         yearRange: dateRange,
        changeMonth: true,
        changeYear: true,
        showOn : 'button',
        buttonImage : '/dlrmap/images/icons/calendar.gif',
        buttonImageOnly : true
    });
   
    $('#datepickerEnd').datepicker({
           yearRange: dateRange,
        changeMonth: true,
        changeYear: true,
        showOn : 'button',
        buttonImage : '/dlrmap/images/icons/calendar.gif',
        buttonImageOnly : true
    });
});


//Use <script src='${pageContext.request.contextPath}/resources/jquery-ui-1.8.17.custom.min.js'></script>

Method to add checkboxes dynamically

//Method to add checkboxes dynamically


function appendchk(checkbox,id,id){
   var cb = document.createElement( "input" );
   cb.type = "checkbox";
   cb.name= "chk_groups[]";
   cb.id = id;
   cb.value = id;
   cb.checked = false;
   var text = document.createTextNode( id );
   document.getElementById( 'prodCategories' ).appendChild(cb);
   document.getElementById( 'prodCategories' ).appendChild(text);
 document.getElementById( 'prodCategories' ).appendChild(document.createElement( "br" ));
 
}

//Call to this function

appendchk(prodEval ,prodEval.name , prodEval.name);

How to check array contains element or not

/**
 * This method to check array contains element or not
 * @param array
 * @param element
 * @returns {Boolean}
 */

function contains(array, element) {
    for ( var indx = 0; indx < array.length; indx++) {
        if (array[indx] == element) {
            return true;
        }
    }
    return false;
}

Jquery Confirmation Dialog


//JavaScript method for showing the dialog box

<script type="text/javascript">
function disclaimerDialogBox() {
var x = $('#disclaimer').dialog({
autoOpen : true,
modal : true,
width : 550,
height : 240,
resizable : false,
zIndex: 5000,
  beforeClose: function(event, ui) {
           if(event.keyCode === 27){
             return false;
           }
        }
});
x.dialog({
buttons : {
"I Accept" : function() {
$(this).dialog('close');
}
}
});
$(".ui-dialog-titlebar").hide();
x.dialog('open');
return true;
}
</script>


//CSS for Dialog and button


<style type="text/css">
        .ui-dialog .ui-dialog-buttonpane {
   text-align: center;
}
.ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset {
   float: none;
}
.ui-button-text {
   font-size: 13px; /* Or whatever smaller value works for you. */
}
</style>

//Check for 1st time to show the disclaimer box .


<c:if test="${user.disclaimer}">
<div id="disclaimer" style="display: none;">
<font size="2">
CONFIDENTIALITY NOTICE - GOES HERE
</font>
</div>
</c:if>


//Call the  disclaimerDialogBox() method onLoad of the body

<body onload="uncheckCheckBox();disclaimerDialogBox();">




Difference between class level and object locking and static object lock

1) Class level locking will lock entire class, so no other thread can access any of other synchronized blocks. 2) Object locking will lo...