Monday, July 21, 2008

How to generalize and use the same variable across different jsp pages for the same functionality.

Here we had generalized the email getting part from the contact name search pop-up window in
Request and Notification Letter pages.


Request JSP Page

<input type="hidden" name="lookupField" value="" />

<html:textarea name="RequestForm" property="approvalNoticeCopyTo" cols="35" rows="2"/>
<input type="button" class="secondaryButton" value="<bean:message key="request.btn.LookUp" bundle="gtem"/>" onClick="document.all('lookupField').value='approvalNoticeCopyTo';window.open('searchContactName.do','searchContact','resizable=1,width=710,height=625,status=1,scrollbars=1');" />

Notification Letter JSP Page

<input type="hidden" name="lookupField" value="" />

<html:text name="EMailForm" property="to" size="55" styleClass="rmt-formTxtInput"/>
<input type="button" class="secondaryButton" value="<bean:message key="request.btn.LookUp" bundle="gtem"/>" onClick="document.all('lookupField').value='to';window.open('searchContactName.do','searchContact','resizable=1,width=710,height=625,status=1,scrollbars=1');" />

Common.js

function setContactName(TABLE_NAME)
{
var lookupFieldName = window.opener.document.getElementById("lookupField");
var lookupField = window.opener.document.getElementById(lookupFieldName.value);
var tbl = document.getElementById(TABLE_NAME);
for (var i=0; i<tbl.tBodies[0].rows.length; i++)
{
if (tbl.tBodies[0].rows[i].className.indexOf("rmt-rowClick") != -1)
{
var rowElem = tbl.tBodies[0].rows[i];
var cell = rowElem.getElementsByTagName("td")[7];
if ((document.forms[0].countEmailIDAdded.value != 0) (lookupField.value != ""))
{
lookupField.value = lookupField.value+";"+cell.childNodes[0].data;
}
else
{
lookupField.value = lookupField.value + cell.childNodes[0].data;
}
document.forms[0].countEmailIDAdded.value = 1;
}
}
window.close();
}

0 Comments:

Post a Comment

<< Home