Wednesday, September 19, 2012

show/hide html component using java script


HTML Code: 

<TD>
<s:select id="dateTargetWriteOffComparitor" 
onchange="showHide('dateTargetWriteOffComparitor','toDateOfTarget')"
value="searchDateCriteriaOperators[0]"
list="searchDateCriteriaOperators"
name="dateTargetWriteOffComparitor" />
</TD>

<TD height="23" width="91"> 
    <sj:datepicker name="dateOfTarget" displayFormat="mm-dd-yy" style="width: 80px;" />

<div id="toDateOfTarget" style="display: none;">
   <sj:datepicker name="toDateOfTarget" displayFormat="mm-dd-yy" style="width: 80px; " />
</div>


Java Script Code: 


function showHide(htmlComp,target){
var listValue=document.getElementById(htmlComp).value;  
if(listValue=='Between'){
document.getElementById(target).style.display = 'block';
}else{
document.getElementById(target).style.display = 'none';
}
}

Friday, August 24, 2012

Clear Form with jQuery

<html>

<head>
<script language="JavaScript" type="text/JavaScript" src="Script/jquery-1.8.0.min.js"></script>
</head>

<body>

<form id="frm">
          <input type="button"  value="Clear" onclick="resetForm('frm')" />
</form>

<script>
/**
* This function clears all input fields value except button, submit, reset, hidden fields
* */
function resetForm(formid) {
                  $(':input','#'+formid) .not(':button, :submit, :reset, :hidden') .val('') .removeAttr('checked').removeAttr('selected');
 
}

</script>

</body>
</html>

Thursday, August 16, 2012

scrollable div


To make the div scroll-able in vertical direction:  


<div  style="height: 300px; overflow-y: scroll">

</div>

How to view List inside list using

if you have a list inside another list, for example you want to iterate over students list and students courses 
and you want to view it in the jsp page, you can use the <s:iterator>  as follows: 

<s:iterator value="studentsList" >

        <s:property value="studentName"/>

       <s:iterator value="%{courses}" >

                      <s:property value="courseName"/>

       </s:iterator> 

</s:iterator> 


This example read the studentsList from struts action. 

Friday, August 10, 2012

How to get fields from different tables in hibernate ?



StringWriter queryS = new StringWriter(200);
Query query;

queryS.append("SELECT A.dateBilling,B.currencyCode " );
queryS.append(" from AImpl A,BImpl B ");
queryS.append("where B.id = A.id  " );


query = this.getSession().createQuery(queryS.toString());
//The values in this array are:
//dateBilling     = results[0]
//currencyCode = results[1]
Object[] results = (Object[]) query.list().get(0);

return results;

Friday, August 3, 2012

Toggles the visibility of a div by clicking on an expand/collapse image


/**
 * Toggles the visibility of a div by clicking on an expand/collapse image.
 * The obj parameter is the image link and the "id" is the id of the div to
 * toggle.
 * @param obj
 * @param id
 */
function toggle(obj,id) {
    var state = document.getElementById(id).style.display;
        if (state == 'block') {
            document.getElementById(id).style.display = 'none';
            obj.src = 'Images/Expand.png';
            obj.title = 'Click to Expand';
        } else {
            document.getElementById(id).style.display = 'block';
            obj.src = 'Images/Collapse.png';
            obj.title = 'Click to Collapse';
        }
}


// In JSP file add the following:


<img id="invoiceListImg" src="Images/Collapse.png" alt="Collapse"  title="Click to Collapse"
onclick="toggle(this,'divName');"/>

Friday, July 27, 2012

s:checkbox design make a problem in the table design

If you have a table and you notice that the <s:checkbox> change the expected design, the solution is simple, add the following property to the tag, and it will be in line with other fields in the table:

<s:checkbox name="persistentBeanKey" theme="simple"
fieldValue="%{#attr.row.sequenceNumberN15}" id="persistentBeanKey"/>