Search This Blog

Monday 22 July 2013

Miscellanies

Query examples:
===============
@NamedQuery(name="queryName",query = " from XXXX xxx  "+
    "where xxx.id in( select yyy.xxx.id from  YYY yyy
    where YYY.ZZZ.name=:Value and yyy.version=:Value) order by xxx.name")

@NamedQuery(name="queryName",query="SELECT new XXX(MONTH(xxx.v1),YEAR(xxx.v1),SUM(xxx.v2)) FROM XXX xxx " +
" WHERE xxx.var1.var2= " +
":val1 and xxx.var1 = 'V'" +
" AND MONTH(xxx.v1)=:month AND YEAR(xxx.v1)=:year"+
" AND DAY(xxx.varDate)=(SELECT DAY(max(xxx1.varDate))  FROM XXX xxx1 )" +
" AND MONTH(xxx.varDate)=(SELECT MONTH(max(xx2.varDate))  FROM XXX xxx2 )" +
" AND YEAR(xxx.varDate)=(SELECT YEAR(max(xx3.vardDate))  FROM XXX xx3 )" +
" GROUP BY MONTH(xxx.v1),YEAR(xxx.v1)"
)


@NamedQuery(name="queryName",query=    "SELECT new XXX(MONTH(xxx.v1),YEAR(xxx.v1),SUM(xxx.v2))" +
" FROM XXX xxx WHERE xxx.obj.var2= " +
":val1 and xxx.var1 = 'V' " +
" AND xxx.v1  BETWEEN :sDate AND :eDate" +
" AND DAY(xxx.varDate)=(SELECT DAY(max(xxx1.varDate))  FROM XXX xxx1 )" +
" AND MONTH(xxx.vardDate)=(SELECT MONTH(max(xxx2.varDate))  FROM XXX xxx2 )" +
" AND YEAR(xxx.varDate)=(SELECT YEAR(max(xxx3.varDate))  FROM XXX xxx3 )" +
" GROUP BY MONTH(xxx.v1),YEAR(xxx.v1)"    )

@NamedQuery(name = "queryName",
query = " SELECT new XXX(MONTH(xxx.v1),YEAR(xxx.v1),xxx.v2) " +
" FROM XXX xxx WHERE xxx.obj.id = :val1 and xxx.v3 = 'V'" +
" AND xxx.v1  BETWEEN :sDate AND :valDate" +
" AND DAY(xxx.varDate)=(SELECT DAY(max(xxx1.varDate))  FROM XXX xxx1 )" +
" AND MONTH(xxx.varDate)=(SELECT MONTH(max(xxx2.varDate))  FROM XXX xxx2 )" +
" AND YEAR(xxx.varDate)=(SELECT YEAR(max(xxx3.varDate))  FROM XXX xxx3 )" )

@NamedQuery(name = "queryName",
query = " SELECT max(xxx.cDate) from  XXX xxx where xxx.obj.val in(:values) " +
" and xxx.var1=:val and  MONTH(xxx.cDate) =:month and YEAR(xxx.cDate) =:year ")

@NamedQuery(name = "queryName", query = "select xxx FROM XXX xxx WHERE xxx.var=:val and xxx.var1 != 'P'"
+ " Order by xxx.var3")

@NamedQuery(name = "queryName", query = "select distinct xxx FROM XXX xxx WHERE xxx.obj.var=:val1 "
+ " AND xxx.var2 In (1,2) Order by xxx.var3")

@NamedQuery(name = "queryName", query = "select xxx FROM XXX xxx WHERE xxx.obj2.var1=:val1 AND xxx.yyy.var2  in "
+ "(select yyy.var3 from YYY  yyy where yyy.var4=:G and"
+ " yyy.obj.var4=:val3)")


@NamedQuery(name="queryName",query = " from XXX xxx  "+
"where xxx.id in( select yyy.xxx.id from  YYYY yyy"+
" where yyy.obj.name=:val1 and yyy.var1=:val2) order by xxx.name")

To replace all instances
======================
inputSQLQuery=inputSQLQuery.replace(new RegExp(sqlCustom,"g"),"CUSTOM");
     window.open turning into ajax request
==================================

params="?commentId="+commentId+"&commentHead="+escape(commentHead);
    var ajaxParams = "comment="+escape(comment);
    act="editComment.do";
    url=act;
    //window.open(url,'edit','scrollbars=yes,width=415,height=365')
    var windowType = "edit";
    var windowParams = "scrollbars=yes,width=415,height=365";
    xmlhttp.open("POST",url,true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", ajaxParams.length);
    xmlhttp.setRequestHeader("Connection", "close");
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) {
             window.open(url + params, windowType, windowParams); //Pop-up gets opened
        }
    }
    xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
    xmlhttp.send(ajaxParams);
   

Handling Enter keyPress event
===========================================

    It have two steps

        such as 1. should call son method on key press in jsp.
                    2.should implement corresponding java script function

    1. onKeyPress="return getValPress();"

    2. function getValPress() {
        if(window.event.keyCode == 13) {
            savedSearchCall('savedSearchDiv');
            return false;
        }
    }

select optgroup
==================================
<select name="blah" size=2 id="abc">
<optgroup label="Please select" style="font-weight:50;font-size:2px;"></optgroup>
<option value="a">A
<option value="b">B
<option disabled>C (unavailable)

<optgroup label="Fail (unavailable)" disabled>
<option>D
<option>F
</optgroup>
</select>

breaking all
=============================================
<td style="word-break:break-all" width="500">

It is for moving table above

we should specify under table tag
style="margin-top:-1.1em"

setting back ground through script


check box onClick condition
---------------------------------------------------------------

onClick="javascript:if(document.frm.checkbox.checked){aaa();}else{bbb();}"
---------------------------------------------------------------

onClick=\"window.open('abcPopup.do','mywindow','scrollbars=yes,width=695,height=245')\" width=\"20\" height=\"20\">"

--------------------------------------------------------------

document.getElementById(divId).innerHTML="";

---------------------------------------------------------------
<font size="3" color="red">
This is some text!
</font>
---------------------------------------------------------------

<td width=\"100\" style=\"word-break:break-all\">
----------------------------------------------------------------
for setting bgcolor particular to div tag
<div style="background-color: white;width:683px; height:578px;">

html code

</div>

-----------------------------------------------------------------

getting object in java script.............................................................

var abcSearch1 = document.all.abcSearch


font setting using style tag

<font style="font-size:11px;font-family:Tahoma;font-weight:bold;color:#000000;"></font>

weight values  normal,bold,bolder,lighter,100200,300,400,500,600,700,800,900

document.location="abcPopup.do?abcId="+id+"&abcDS="+ds+"&mapType="+mt+"&offset="+offset+"&add="+add;

It is used to dispose current window

onClick=window.opener.location.reload(true);window.close();

It is to open popup whithin popup:-
Jsp code
a href="#"
                    onclick="abcTemplatePopup('abcPopup.do','_self','scrollbars=yes,width=425,height=540','WORD')">
java script code
window.open(actionName + params, windowType, windowParams);

//This variable is used for get the MaximumInactiveTime
var maxInactiveInterval = getCookie("maxInactiveInterval");

//Counter for decreament the time
function decrementSessionTime(){
    var sessionMaxInactiveInterval = getCookie("sessionMaxInactiveInterval");
    sessionMaxInactiveInterval--;
    setCookie("sessionMaxInactiveInterval",sessionMaxInactiveInterval);
    setTimeout("decrementSessionTime()", 1000);
}
//To check the current total inactive time
function closeIfSessionEnded(){
    var sessionIdleTime = getCookie("sessionMaxInactiveInterval");
    var isSessionExpired = getCookie("isSessionExpired");
    if (sessionIdleTime <= 10 ){
        closeSession();
    }
    if (sessionIdleTime <= 300 && isSessionExpired == "false") {
        setCookie("isSessionExpired","true");
        window.open("abcOffPopup.do", "_blank", "menubar=0,resizable=0,width=350,height=250,status=1,scrollbars=0,left=300,top=300");
        //if(confirm("Your Session is going to expire in 5 minutes.\n Please Click 'OK' to Retain")){
        //    extendSession();
        //    retainSession();
        //}
    }
}
//Get the cookie value
function getCookie(Name) {
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        // if cookie exists
        if (offset != -1) {
            offset += search.length
            // set index of beginning of value
            end = document.cookie.indexOf(";", offset);
            // set index of end of cookie value
            if (end == -1) end = document.cookie.length;
            returnvalue=unescape(document.cookie.substring(offset, end))
        }
    }
    return returnvalue;
}
//To set the cookie value
function setCookie(variable, value){
    //store data using name/value format
    document.cookie=variable + "=" + value;
    return true;
}
//To continue the session
function extendSession(){
    setCookie("sessionMaxInactiveInterval",maxInactiveInterval);
    setCookie("isSessionExpired","false");
}
//To close the session
function closeSession(){
   setCookie("sessionMaxInactiveInterval",0);
   window.location = "logOff.do";
}

function retainSession() {
    initRequest();
    url="abcSession.do";
    //alert("--"+url);
    xmlhttp.open("POST",url,false);
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) {
             //eval(xmlhttp.responseText);
        }
    }
    xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
    xmlhttp.send();
}

<script language="javascript">
function checkSession() {
    closeIfSessionEnded();
    setTimeout("checkSession()", 1000); //1000 Means 1 second
}
checkSession();
decrementSessionTime();
</script>

<script language='javascript'>
var myClose=false;
function confirmClose(){
    if(event.clientY < -50){
        event.returnValue = 'LOGOUT ? ';
        return true;
    }
}

function handleClose() {
    if(myClose==true)
        CallBackServerMethod();
}

function CallBackServerMethod(){
    window.open('logOff.do');
}

function initValues(){
    myClose=false;
}

window.onload = function () {
    initValues();
}
window.onbeforeunload = function () {
    myClose=confirmClose();
}
window.onunload = function () {
    handleClose(myClose);
}
</script>

The following code is used to change focus of ICONS

In this sistuation every tab have to gif files, one(retrieved_select.gif) which will be created with thik color and one(hierarch_hover.gif) which will be created with dull color

 if(abceid == 'RETRIVED'){
        document.getElementById("retrivedTerms").src = "images/retrieved_select.gif";
        document.getElementById("hierarchialView").src = "images/hierarch_hover.gif";
    }else if(eid == 'HIERARCHIAL'){
        document.getElementById("retrivedTerms").src = "images/retrieved_hover.gif";
        document.getElementById("hierarchialView").src = "images/hierarch_select.gif";
    }

    <c:choose>
    <c:when test="${abcEntry.hasChild == true}">
    <a onClick="pickTreeSub('<c:out value='${abcEntry.treeCode}'/>','<c:out value='${abcEntry.modCode}'/>','<c:out value='${abcEntry.category}'/>');swapImg(this.firstChild, 0);" style="cursor: hand">
        <img src="images/icon_small_plus.gif" alt="Plus icon" width="9" height="9" name="plus" id="plus">
    </a>
    </c:when>
    <c:otherwise>
        <img src="images/icon_small_minus.gif" alt="Minus icon" width="9" height="9" name="minus" id="minus">
    </c:otherwise>
    </c:choose>


    function validateRangeExport(){

        if(document.all.exportRange && document.all.exportRange[1].checked){
            var exportStartNum=new Number(document.all.resultSetExportStart.value);
            var exportEndNum=new Number(document.all.resultSetExportEnd.value);
            var totalRecCount=new Number(document.all.totalRecCount.value);

            if( exportStartNum <= exportEndNum){

                if(exportStartNum <= 0 || exportEndNum <=0 ){
                    alert("Export range values "+exportStartNum+" - "+exportEndNum+" should be greater than zero.");
                    return false;
                }
                if(exportStartNum > totalRecCount || exportEndNum > totalRecCount){
                    alert("Export range values "+exportStartNum+" - "+exportEndNum+" exceed the total records "+totalRecCount +".");
                    return false;
                }

                hideElement('exportSelectPopup')
                window.resizeTo(425,445);
                showElement('exportPopup');
                return true;
            }else{
                alert("Please enter proper export range values.");
                return false;
            }
        }
        hideElement('exportSelectPopup')
        window.resizeTo(425,445);
        showElement('exportPopup');
        return true;
}
function onlyNumbers(evt)
{
    var e = event || evt; // for trans-browser compatibility
    var charCode = e.which || e.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}


Used to referesh opener window
 window.opener.opener.location.reload(true);


 JQuery ajax post request and sending bulk data:
 $.ajax({
        cache: false,
         async: false,
         global: false,
        type: "POST",
        url: url,
        data: parameters,
         success: function(data){   
             hideSuggestReportLayer();
         }
      });


CSS Properties To JavaScript Reference Conversion
===================================
    CSS Property                JavaScript Reference 
===================================
background                                background
background-attachment            backgroundAttachment
background-color                        backgroundColor
background-image                    backgroundImage
background-position                    backgroundPosition
background-repeat                    backgroundRepeat
border                                    border
border-bottom                            borderBottom
border-bottom-color                    borderBottomColor
border-bottom-style                    borderBottomStyle
border-bottom-width                borderBottomWidth
border-color                            borderColor
border-left                                borderLeft
border-left-color                        borderLeftColor
border-left-style                        borderLeftStyle
border-left-width                        borderLeftWidth
border-right                            borderRight
border-right-color                        borderRightColor
border-right-style                    borderRightStyle
border-right-width                    borderRightWidth
border-style                            borderStyle
border-top                                borderTop
border-top-color                        borderTopColor
border-top-style                        borderTopStyle
border-top-width                        borderTopWidth
border-width                            borderWidth
clear                                        clear
clip                                        clip
color                                        color
cursor                                    cursor
display                                    display
filter                                        filter
font                                        font
font-family                                fontFamily
font-size                                fontSize
font-variant                            fontVariant
font-weight                                fontWeight
height                                    height
left                                        left
letter-spacing                            letterSpacing
line-height                                lineHeight
list-style                                listStyle
list-style-image                        listStyleImage
list-style-position                    listStylePosition
list-style-type                            listStyleType
margin                                    margin
margin-bottom                        marginBottom
margin-left                                marginLeft
margin-right                            marginRight
margin-top                                marginTop
overflow                                    overflow
padding                                    padding
padding-bottom                        paddingBottom
padding-left                            paddingLeft
padding-right                            paddingRight
padding-top                            paddingTop
page-break-after                        pageBreakAfter
page-break-before                    pageBreakBefore
position                                    position
float                                        styleFloat
text-align                                textAlign
text-decoration                        textDecoration
text-decoration: blink                textDecorationBlink
text-decoration: line-through        textDecorationLineThrough
text-decoration: none                textDecorationNone
text-decoration: overline            textDecorationOverline
text-decoration: underline            textDecorationUnderline
text-indent                                textIndent
text-transform                            textTransform
top                                        top
vertical-align                            verticalAlign
visibility                                    visibility
width                                        width
z-index                                    zIndex

Usage
Internet Explorer
document.all.div_id.style.JS_property_reference = "new_CSS_property_value";




Older Netscape's (4.7 and earlier)
document.div_id.JS_property_reference = "new_CSS_property_value";




Netscape 6.0+ and Opera (and other Mozilla)
document.getElementById(div_id).style.JS_property_reference = "new_CSS_property_value";

Note the use of parentheses instead of square brackets in newer Mozilla's "getElementById()" reference.

Fire fox:::::::::::
if (browser=="Netscape")
var newWindow = window.open(url, '_blank');
    if (!newWindow) return false;
    var html = "";
    html += "<html><head></head><body><form id='formid' method='post' action='" + url + "'>";
    html += "<input type='hidden' name='entity_id' value='" + id + "'/>";
    html += "<input type='hidden' name='entity_type' value='" + type + "'/>";
    html += "<input type='hidden' name='chart_data' value='" + chartByteData + "'/>";
    html += "<input type='hidden' name='deal_sel_value' value='allDeals'/>";
    html += "<input type='hidden' name='i_venture_data' value='" + dataIncluded + "'/>";
    html += "<script type='text/javascript'>document.getElementById(\"formid\").submit()</script></form></body></html>";
    newWindow.document.write(html);

IE:::::::::::::::::
else
var form = document.createElement("form");
     form.setAttribute("method", "post");
     form.setAttribute("action", url);
     form.setAttribute("target", "_blank");
     var hiddenField1 = document.createElement("input");  
     hiddenField1.type = "hidden";          
     hiddenField1.setAttribute("name", "entity_id");
     hiddenField1.setAttribute("value", id);
     var hiddenField2 = document.createElement("input");  
     hiddenField2.type = "hidden";           
     hiddenField2.setAttribute("name", "entity_type");
     hiddenField2.setAttribute("value", type);
     var hiddenField3 = document.createElement("input");
     hiddenField3.type = "hidden";              
     hiddenField3.setAttribute("name", "chart_data");
     hiddenField3.setAttribute("value", chartByteData);
     var hiddenField4 = document.createElement("input");
     hiddenField4.type = "hidden";
     hiddenField4.setAttribute("name", "deal_sel_value");
     hiddenField4.setAttribute("value", selelctedValue);
     var hiddenField5 = document.createElement("input");
     hiddenField5.type = "hidden";
     hiddenField5.setAttribute("name", "i_venture_data");
     hiddenField5.setAttribute("value", dataIncluded);
     form.appendChild(hiddenField1);
     form.appendChild(hiddenField2);
     form.appendChild(hiddenField3);
     form.appendChild(hiddenField4);
     form.appendChild(hiddenField5);
     document.body.appendChild(form);
     form.submit();

Email Address validatiobn::::::::
=====================
function checkEmailAddress(addPartneringText) {
    var temp = new Array();
    var word = ' ';
    var isEmail = false;
    temp = addPartneringText.split(' ');

    if(addPartneringText.length > 0) {
        for (var indexCount = 0; indexCount< temp.length; indexCount++) {
            word = temp[indexCount];
            if ( word.indexOf('@') != -1 && word.length>0) {   
                if (isEmailAddress(word)) {
                    isEmail = true;
                    break;
                }     
            }
        }
    }
    return isEmail;       
}
/**
function to validate email address
*/
function isEmailAddress(email) {
    if (email.length == 0) {
        return true;
    }
    var emailPatern=/^(.+)@(.+)$/;
    var specialCharacters="\\(\\)<>@,;!#$`|%:\\\\\\\"\\.\\[\\]";
    var validCharacters="\[^\\s" + specialCharacters + "\]";
    var qUser="(\"[^\"]*\")";
    var ipDomainPattern=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
    var atom=validCharacters + '+';
    var word="(" + atom + "|" + qUser + ")";
    var userPattern=new RegExp("^" + word + "(\\." + word + ")*$");
    var domainPattern=new RegExp("^" + atom + "(\\." + atom + ")*$");
    var matchArr=email.match(emailPatern);
    if (matchArr == null) {
        return false;
    }
    var user=matchArr[1];
    var domain=matchArr[2];
    if (user.match(userPattern) == null) {
        return false;
    }
    var IPArray = domain.match(ipDomainPattern);
    if (IPArray != null) {
        for (var i = 1; i <= 4; i++) {
            if (IPArray[i] > 255) {
                return false;
            }
        }
        return true;
    }
    var domainArray=domain.match(domainPattern);
    if (domainArray == null) {
        return false;
    }
    var atomPattern=new RegExp(atom,"g");
    var domArr=domain.match(atomPattern);
    var len=domArr.length;
    if ((domArr[domArr.length-1].length < 2) || (domArr[domArr.length-1].length > 3)) {
        return false;
    }
    if (len < 2) {
        return false;
    }
    return true;
}

// Applies the resize and drag n drop and styles to the table. -- JQuery movable and resizable teble columns and rows
function applyTableFeatures() {
  $("table tr:nth-child(even)").addClass("even");
  $("table tr:nth-child(odd)").addClass("odd");
  showSortedColumn(document.getElementById("sortBy").value, document.getElementById("direction").value);
  t1 = new dragTable('tableResultsId');
  $("#tableResultsId").kiketable_colsizable({
        dragCells : "tr:first>*:not(:first)"
    }).end();
}

pageContext
===========
Long totalCount = (Long) pageContext.getAttribute("totalRults",
   PageContext.REQUEST_SCOPE);

image tag usage
==============
<img src='cmStr.do?abcId=<c:out value="${id}"/>&abcsource=<c:out value="${source}"/>' />

Scriptlet usage
==============
<input name="watchAdd" type="button" class="button" style="color:#000000"
  onclick="openUrl(this,'<%=dr[i][j].getId()%>','<%=dr[i][j].getSource()%>',
  '<%=request.getParameter("mapType")%>','<%=request.getParameter("offset")%>',
  'add',document.all.<%=alName%>.value,
  document.all.<%=emailName%>)"
  id="addButton" value="Add" />


<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>

c:if
====
<c:if test="${comSub[2] eq true}">
</c:if>

c:out
=====
<c:out value="${mItesms.key}" />
<c:out value="${searchCss}" escapeXml="false"/>
<input type="checkbox" name="Assllcb-<c:out value='${item.abcId}'/>" id="ALL-<c:out value='${item.abcId}'/>" onClick="selectAllDS(this)" value="<c:out value='${item.abcId}'/>"

c:choose
=========
<c:choose>
 <c:when test="${dsLengTemp > 1}">
 </c;when>
 <c:otherwise>
  <c:out value="${pageRow.content}" />
 </c:otherwise>
</c:choose>

c:forEach with index
===================
<c:forEach var="restaurant" items="${itemsForListing}" varStatus="index">
</c:forEach>

c:set
====
<c:set var="selFields" value="0" />

spring
======
web.xml entry
<taglib>
 <taglib-uri>/spring</taglib-uri>
 <taglib-location>/WEB-INF/tld/spring.tld</taglib-location>
</taglib>

<%@ taglib prefix="spring" uri="/spring"%>

c:catch
======
<c:catch var="ex">
</c:catch>
<c:if test="${ex != null}">
statement1
statement2
</c:if>

c:forTokens
===========
<c:forTokens items="${descc}" delims="~" var="descArray" varStatus="cnctDesc">
 <c:forTokens items="${decsc}" delims="~" var="descArray" varStcatus="cntDesc">
  <c:out value="${descAcrray}" /><sup>(<c:out value="${srcArcray}" />)</sup>
 </c:forTokens>
</c:forTokens>

jsp:include
==========
<jsp:include page="jspfile.jsp" flush="true" />
spring:message
=============
<spring:message code="ADMI"/>

div status
=========
<div id="prepasge1" style="display: block;font-family:arial; font-size:20;left:5px; top:85px;">
 <img src="loaddding.gif"> <font color="green" size="2"><b>Processing...</b></font>
</div>

calling multiple js functions
<a href="#" onClick="change('settigs'); getPrefTabs('settings');">

onClick="return saveComment('add');this.disabled='true';"
window.opener.location = "log.do";
 

No comments:

Post a Comment