ALTERNATE OF <logic:equal> OR ANY OTHER LOGIC TAG IN STRUTS
----------------------------------------------------------------------------------------
We need to write very much <logic:equal name> if there are lot of if conditions in you page...so how we use native if condition in struts. I have faced the same problem and find the solution. the solution is in listed below code.
============================== =========================
Using <logic:equal name>
<logic:notEmpty name="myProductList" scope="request">
<table>
<logic:iterate id="prodIterateId" name="myProductList">
<tr>
<logic:equal name="prodIterateId" property="catId" value="1">
<td align="center"><html:text name="prodIterateId" property="catId" value="DESKTOP COMPUTER"/></td>
</logic:equal>
<logic:equal name="prodIterateId" property="catId" value="2">
<td align="center"><html:text name="prodIterateId" property="catId" value="LAPTOP"/></td>
</logic:equal>
<logic:equal name="prodIterateId" property="catId" value="3">
<td align="center"><html:text name="prodIterateId" property="catId" value="PAMTOP"/></td>
</logic:equal>
<logic:equal name="prodIterateId" property="catId" value="4">
<td align="center"><html:text name="prodIterateId" property="catId" value="PAD"/></td>
</logic:equal>
<td align="center"><html:text name="prodIterateId" property="productName" readonly="true" size="33"/></td>
<td align="center"><html:text name="prodIterateId" property="productPrice" readonly="true" size="33"/></td>
<td align="center"><html:text name="prodIterateId" property="productCode" readonly="true" size="33"/></td>
</tr>
</logic:iterate>
</table>
</logic:notEmpty>
============================== ==============================
Using native IF condition
<logic:notEmpty name="myProductList" scope="request">
<table>
<logic:iterate id="prodIterateId" name="myProductList">
<tr>
<bean:define id="catId_Value" name="prodIterateId" property="catId" type="java.lang.Integer" />
<%
int c_id=catId_Value.intValue();
String cat_Name="";
if(c_id==1) {cat_Name="DESKTOP COMPUTER";}
if(c_id==2) {cat_Name="LAPTOP"; }
if(c_id==3) {cat_Name="PAMTOP"; }
if(c_id==4) {cat_Name="PAD"; }
%>
<td align="center"><html:text name="prodIterateId" property="catId" value="<%=cat_Name%>"/></td>
<td align="center"><html:text name="prodIterateId" property="productName" readonly="true" size="33"/></td>
<td align="center"><html:text name="prodIterateId" property="productPrice" readonly="true" size="33"/></td>
<td align="center"><html:text name="prodIterateId" property="productCode" readonly="true" size="33"/></td>
</tr>
</logic:iterate>
</table>
</logic:notEmpty>
----------------------------------------------------------------------------------------
We need to write very much <logic:equal name> if there are lot of if conditions in you page...so how we use native if condition in struts. I have faced the same problem and find the solution. the solution is in listed below code.
==============================
Using <logic:equal name>
<logic:notEmpty name="myProductList" scope="request">
<table>
<logic:iterate id="prodIterateId" name="myProductList">
<tr>
<logic:equal name="prodIterateId" property="catId" value="1">
<td align="center"><html:text name="prodIterateId" property="catId" value="DESKTOP COMPUTER"/></td>
</logic:equal>
<logic:equal name="prodIterateId" property="catId" value="2">
<td align="center"><html:text name="prodIterateId" property="catId" value="LAPTOP"/></td>
</logic:equal>
<logic:equal name="prodIterateId" property="catId" value="3">
<td align="center"><html:text name="prodIterateId" property="catId" value="PAMTOP"/></td>
</logic:equal>
<logic:equal name="prodIterateId" property="catId" value="4">
<td align="center"><html:text name="prodIterateId" property="catId" value="PAD"/></td>
</logic:equal>
<td align="center"><html:text name="prodIterateId" property="productName" readonly="true" size="33"/></td>
<td align="center"><html:text name="prodIterateId" property="productPrice" readonly="true" size="33"/></td>
<td align="center"><html:text name="prodIterateId" property="productCode" readonly="true" size="33"/></td>
</tr>
</logic:iterate>
</table>
</logic:notEmpty>
==============================
Using native IF condition
<logic:notEmpty name="myProductList" scope="request">
<table>
<logic:iterate id="prodIterateId" name="myProductList">
<tr>
<bean:define id="catId_Value" name="prodIterateId" property="catId" type="java.lang.Integer" />
<%
int c_id=catId_Value.intValue();
String cat_Name="";
if(c_id==1) {cat_Name="DESKTOP COMPUTER";}
if(c_id==2) {cat_Name="LAPTOP"; }
if(c_id==3) {cat_Name="PAMTOP"; }
if(c_id==4) {cat_Name="PAD"; }
%>
<td align="center"><html:text name="prodIterateId" property="catId" value="<%=cat_Name%>"/></td>
<td align="center"><html:text name="prodIterateId" property="productName" readonly="true" size="33"/></td>
<td align="center"><html:text name="prodIterateId" property="productPrice" readonly="true" size="33"/></td>
<td align="center"><html:text name="prodIterateId" property="productCode" readonly="true" size="33"/></td>
</tr>
</logic:iterate>
</table>
</logic:notEmpty>