Struts 1.3 with COBOL Stored Procedure Implementation with searching, Pagination, Export to Excel and Multilingual
Hi Reader,
I am continuing from my previous blog. In this blog we will be discussed about searching,export to excel,pagination and multilingual.
Searching :
Here we will use struts logic:iterate tag in the JSP page for searching. Mainly we will discuss <logic:equal>,<logic:greaterThan> and <logic:greaterEqual>.
We are using the same searchReasonCodesForm from the previous blog.
<logic:equal name="searchReasonCodesForm" property="defectslno" value="511">
displaying sl no 511.data.
</logic:equal>
<logic:greaterThan name="searchReasonCodesForm" property="defectslno" value="511">
displaying data greater than sl no 511.
</logic:greaterThan>
<logic:greaterEqual name="searchReasonCodesForm" property="defectsslno" value="511">
displaying data greater than equal to sl no 511.
</logic:greaterEqual>
Export to Excel :
We are using the same <logic:iterate> tag to display data in the JSP page. We are using same form(searchReasonCodesForm) and id holds the instance of the data present in the form.
Here we are using the content type as contentType="application/vnd.ms-excel" for exporting data as excel format in the JSP page.
Export Excel JSP Page :
<%@page contentType="application/vnd.ms-excel" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html>
<head>
<title>User Details</title>
</head>
<body>
<table cellpadding="3" cellspacing="3" border="1">
<tr>
<th>
DefectSLNo
</th>
<th>
Description
</th>
</tr>
<logic:iterate id="data" name="searchReasonCodesForm" scope="session">
<tr>
<td>
<bean:write name="data" property="defectslno" />
</td>
<td>
<bean:write name="data" property="description" />
</td>
</tr>
</logic:iterate>
</table>
</body>
</html>
Multilingual :
Multilingual is used for displaying content specific to the local based on their language and formatting.
We can do multilingual in two ways by setting org.apache.struts.action.LOCAL to the corresponding language and other way by setting the language preference in the browser.
Resource Bundle is the file that contains the key/value pairs for the default language. The naming format of the Application Resource file is of type
bundlename_language_country_variant.properties
We need to link the resource Bundle with the Application using <message-resources> tag in the struts-config configuration file.
<message-resources parameter="com/satya/ApplicationResource"/>
Here we are going to create four Application Resource properties file.
1. ApplicationResource_en_US_WIN.properties.
2. ApplicationResource_en_FR_WIN.properties.
3. ApplicationResource_en_GR_WIN.properties.
4. ApplicationResource_en_IT_WIN.properties.
We need to put all the ApplicationResource.properties file in the struts.config.xml file.
<message-resources parameter="com/satya/ApplicationResource_en_US_WIN.properties"/>
<message-resources parameter="com/satya/ApplicationResource_en_FR_WIN.properties"/>
<message-resources parameter="com/satya/ApplicationResource_en_GR_WIN.properties"/>
<message-resources parameter="com/satya/ApplicationResource_en_IT_WIN.properties"/>
Application Resource Properties
1. ApplicationResource_en_US_WIN.properties.
label.welcome = Welcome.
2. ApplicationResource_en_FR_WIN.properties.
label.welcome = J'aime Struts
3. ApplicationResource_en_GR_WIN.properties.
label.welcome = Ich liebe Struts
4. ApplicationResource_en_IT_WIN.properties.
label.welcome = ti amo Struts
We need to use the Dispatch Action depending upon the language selected by the user the corresponding method in the LocalAction is called.
LocalAction :
Multilingual is used for displaying content specific to the local based on their language and formatting.
We can do multilingual in two ways by setting org.apache.struts.action.LOCAL to the corresponding language and other way by setting the language preference in the browser.
Resource Bundle is the file that contains the key/value pairs for the default language. The naming format of the Application Resource file is of type
bundlename_language_country_variant.properties
We need to link the resource Bundle with the Application using <message-resources> tag in the struts-config configuration file.
<message-resources parameter="com/satya/ApplicationResource"/>
Here we are going to create four Application Resource properties file.
1. ApplicationResource_en_US_WIN.properties.
2. ApplicationResource_en_FR_WIN.properties.
3. ApplicationResource_en_GR_WIN.properties.
4. ApplicationResource_en_IT_WIN.properties.
We need to put all the ApplicationResource.properties file in the struts.config.xml file.
<message-resources parameter="com/satya/ApplicationResource_en_US_WIN.properties"/>
<message-resources parameter="com/satya/ApplicationResource_en_FR_WIN.properties"/>
<message-resources parameter="com/satya/ApplicationResource_en_GR_WIN.properties"/>
<message-resources parameter="com/satya/ApplicationResource_en_IT_WIN.properties"/>
Application Resource Properties
1. ApplicationResource_en_US_WIN.properties.
label.welcome = Welcome.
2. ApplicationResource_en_FR_WIN.properties.
label.welcome = J'aime Struts
3. ApplicationResource_en_GR_WIN.properties.
label.welcome = Ich liebe Struts
4. ApplicationResource_en_IT_WIN.properties.
label.welcome = ti amo Struts
We need to use the Dispatch Action depending upon the language selected by the user the corresponding method in the LocalAction is called.
LocalAction :
public class LocaleAction extends DispatchAction {
private final static String SUCCESS = "success";
public ActionForward english(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session = request.getSession();
session.setAttribute("org.apache.struts.action.LOCALE", Locale.ENGLISH);
return mapping.findForward(SUCCESS);
}
public ActionForward french(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session = request.getSession();
session.setAttribute("org.apache.struts.action.LOCALE", Locale.FRENCH);
return mapping.findForward(SUCCESS);
}
public ActionForward german(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session = request.getSession();
session.setAttribute("org.apache.struts.action.LOCALE", Locale.GERMAN);
return mapping.findForward(SUCCESS);
}
public ActionForward italian(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession session = request.getSession();
session.setAttribute("org.apache.struts.action.LOCALE", Locale.ITALIAN);
return mapping.findForward(SUCCESS);
}
}
Based on the value set in the org.apache.struts.action.Local variable the corresponding Application Resource properties file will be used to display the appropriate data.
I will continue pagination in my next blog..........
No comments:
Post a Comment