Tuesday, August 19, 2008

Ibatis - Select

Dao function to call ibatis xml
public List getActionListString type)
{ Map m = new HashMap();
m.put("type",datatype);
return getSqlMapClientTemplate().queryForList("xmlSQL.getActionList", m);
}

xmlSQL file sql statement
<select id="getActionList" parameterClass="java.util.Map" resultClass="com.model.ListingObj">
SELECT ACTION_CODE as Code,ACTION_NAME as Description
FROM RECORD_ACTION C
WHERE TYPE = #datatype:VARCHAR#
<isNotNull prepend="AND" property="state">
STATE_CODE = #state:VARCHAR# </isNotNull> </select>


ListingObj class
public class ListingObj {
private String code;
private String description;
public String getCode() { return code; }
public void setCode(String code) { this.code = code; }
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }}

Ibatis - Transaction manual commit

public String updateCustMobile(String mobileNo, String custId)
{ Map m = new HashMap();
m.put("custId",custId);
m.put("mobileNo",mobileNo);
SqlMapClient sqlMap;
try { sqlMap = getSqlMapClientTemplate().getSqlMapClient();
sqlMap.startTransaction();
// Set commit to false for rollback if any exception
sqlMap.getCurrentConnection().setAutoCommit(false);
sqlMap.update("xmlSQL.updateCust", m);
.....
.....
sqlMap.endTransaction();
} catch(Exception e)
{
e.printStackTrace();
} finally {
if(!(sqlMap == null)) sqlMap.endTransaction();
}
return status;
}

Struts - Table

<display:table name="sessionScope.campList" id="tableReport" pagesize="${page}" requestURI="campSearch.do" class="headertable" style="width:100%;" sort="list">

<display:column paramId="campId" paramProperty="campId" titleKey="campId" headerClass="rowHeader" class="rowContent" sortable="true">

<span id="tagtip<s:property value="%{#rowCounter}"/>" style="display: none;">
<table width="300" class="tooltips"><tr><th colspan="2">Tag List
</th></tr>
<c:forEach var="tag" items="${tableReport.tags}" >
<tr><td>
<c:out value="${tag.tagId}"></c:out></td><td>
<c:out value="${tag.location}"></c:out></td></tr>
</c:forEach></table></span>
<s:div onmouseover="TagToTip('%{'tagtip' + #rowCounter}')" onmouseout="UnTip()">
<c:out value="${tableReport.campId}"></c:out>
</s:div></display:column>

<display:column property="startDate" format="{0,date,dd/MM/yyyy}" titleKey="startDate" headerClass="rowHeader" class="rowContent" sortable="true"/>

<display:column property="startTime" format="{0,date,HH:mm:ss}" titleKey="startTime" headerClass="rowHeader" class="rowContent" sortable="true"/>

<s:set name="rowCounter" value="%{#rowCounter + 1}"/>
</display:table>
***********************

tableReport.tags is a list in sessionScope.campList
tag.tagId is a variable in tags list object

Struts - Get session value in jsp

<s:hidden key="refId" id="refId" value="${SESSIONVALUE}"/>
*************
id is important if you want to get the refId value in action class upon form submittion

Struts - If

<s:if test="${isExist && status != 'FAILED'}">

<fmt:message key="psNote"/></s:if>

****************

fmt:message key is retreive from message.properties file

Struts - Pass value to javascript function

<script type="text/javascript">
displayData("<c:out value='${status}'/>", "<c:out value='${proId}'/>");
</script>

Struts - Link

<a href="search.do?customerNo=${data.customerNo}">
<fmt:message key="btn.back"/> </a>

Struts - Hidden Field

<s:hidden key="phoneNo" value ="${data.mobileNo}" />

Struts - Dropdown List

<display:table name="data.cardList" id="dataDetail" pagesize="${page}" requestURI=" style="width:100%">
<display:column headerClass="rowHeader">
<input type="radio" name="ipSelection" />
</display:column>

<display:column titleKey="de.action" headerClass="rowHeader" style="text-align:center">
<select name="action" onchange="setAction('${dataDetail.cardRef}','${dataDetail.cp}')" >
<option> Please select</option>
<c:forEach var="act" items="${actionList}">
<s:if test="${dataDetail.status==act.state}">
<option value="${act.code}"> ${act.description}</option>
</s:if> </c:forEach> </select>
</display:column>

</display:table>

**************************
- dataDetail.cardRef & dataDetail.cp should be the variables in cardList object
- act.code & act.description should be the variables in actionList object
- actionList is store in session

Js - Radio Button (Reset)

if (radioLength>0)

{ for(var i = 0; i <radioLength; i++)

{ if(document.forms[0].cardSelection[i].checked==true)

{ alert("checked is true");

document.forms[0].cardSelection[i].checked = false;

} }

}else

{ document.forms[0].cardSelection.checked = false; }

Js - Radio Button (Check)

var radioLength = document.forms[0].cardSelection.length;
var checked = false;
if (radioLength>0)
{
//if radio button more then 1
for(var i = 0; i < radioLength; i++)
{ if(document.forms[0].cardSelection[i].checked)
{ checked = true; break; }
}
}else
{ //if only have 1 radio button
if (document.forms[0].cardSelection.checked==true)
{ checked = true; }
}