Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Internationalization issue with special French characters

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi we are trying to implement the internationalization in struts. For this we created a new ApplicationResource_fr.properties file for FRENCH language.
Here the issue we are facing is for one of the submit button name we given the name as 'En attendant Préparation Pour la BRS' in french related property file and the value for this in english is 'Pending For BRS Preparation'. So after click on the submit button we are getting error message ' missing resource 'En attendant Pr├⌐paration Pour la BRS' in key method map'
Since the special character é is internally transforming to ├⌐ so there is a mismatch happening and it is throwing the error after clicking the submit button.

Note: But in the view tier the what ever the name we are specified in the fr properties file it is showing the same name. But during the submission of the form it is giving the exception.
In the jsp file we set the below lines

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

and even in the struts-config.xml file <controller> element we also set the contentType="UTF-8"%"

So could you please let us know how to fix this issue. If the peroperties are not having the special characters it is working fine. We also tried by putting the asii code as

\u00e8 related to 'e grave' ie., but still we are facing the same issue but in both the cases view tier is displaying the correct values but after sumision of the form causes the errors.
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you provide,

button code which you have used..??

what is your action method name?
 
Ranch Hand
Posts: 329
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Srinivasa,
As Guru said post the relevant code snippet being used. Additionally, in the first place, verify what is the necessity to submit the button name while you are submitting the form.
 
Srinivasa Rao Ammina
Greenhorn
Posts: 20
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Button code:

<html:submit property="button" styleClass="ppm_btn" style="width:180px" styleId="hsia">
<bean:message key="login.hnipendingforApprove"/>
</html:submit>

2. Action method

protected Map getKeyMethodMap(){

map.put("login.hnipendingforApprove","hnipendingforApprove");
.
.
return map;
}

3. public ActionForward hnipendingforApprove(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {


business logic..

}

4. ApplicationResource_fr.properties

login.hnipendingforApprove = En attendant Préparation Pour la BRS
 
Srinivasa Rao Ammina
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guru, as per your previous post attached the code could you please check and let us know the issue please?
 
Vicky Vijay
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

In case of Multilingual application,

the main problem occurs in two case,

1. Regarding the Handling the Form submission and hanlding the action part

2. Reg the data retrieval from JSP, Processing and Persistence/retrieval to DB



To solve your case,

Please find my suggestioin below,


1. Create a property in FORM

property: "swicthElement"

Generate Getters and Setters

2. Onclick has been used



<html:submit styleClass="ppm_btn" style="width:180px" styleId="hsia"
onclick="document.getElementById('swicthElement').value='hnipendingToApprove';">
<bean:message key="login.hnipendingforApprove"/>
</html:submit>


<html:hidden property="swicthElement"/>

in this case, the hidden property will be available for the form,

You can set manually the corresponding value to the swicthElement

The form gets submitted and contains

switchElement with value "hnipendingToApprove"



3.

Use the action method as below,

dispatch the method by the condition check as below


public class UserAction extends Action {

public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {

UserForm form1 = (UserForm) form;

if (form1.getSwicthElement().equals("hnipendingforApprove")) {
hnipendingforApprove(mapping, form, request, response);
}

return (mapping.findForward("success"));

}


public ActionForward hnipendingforApprove(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
...
...
...
..
}
}


Provide your reply if this resolves the problem
 
Srinivasa Rao Ammina
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the alternative solution provided. But the application is very huge and having lot of Form, Action beans. So this solution would affect a lot w.r.t to code perspective.
Will there be any alternate solution to handle this issue? Why because if another language is not supporting some other characters we need to handle such cases also.
So if there is any generic solution to handle all the cases it would be good.
 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Srinivasa, Your code looks fine, there is no issue. Just try changing the 'key' in your properties file from to 'hnipendingforApprove' to something else other than the method name in your action class and try once again and see if it works. Hope it does. If it does not work out then post the JSP being used in this scenario.
 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As i mentioned earlier, There is no need to submit a value of I18N key while submitting the request from the client(your server has the key value pair). But it looks like your request is doing that, it is submitting the value for you. Looking into the JSP code snippet you do not intend to do that, but the request is submitting that. Maybe you have a hidden parameter with the same name as 'hnipendingforApprove' in your JSP and the request info is considering that. If you have this hidden variable, also try changing the name of it and try the same again. Hope this should solve the silly problem.
 
Vicky Vijay
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi srinivas,

which version of struts you are using.. ?

I have the checked your case in Struts 1.3 version and found the below,

The parameter which has been passed to
getMethodName() in LookupDispatchAction
are as below,

for "method" parameter, the value obtained was


En attendant Préparation Pour la BRS ----> (KeyA)


but where as the value from the lookupHashMap as below,




CONDITION:

If KeyA should match with the KeyB, then the result page will be retrieved as you have provided in the property file ---> (KeyB)


Here

KeyA != KeyB

so the exception as occured


I hope this would give you an insight about the problem





 
Srinivasa Rao Ammina
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make a note that Application is working fine in english language and only issue is with the french language.

Please find code in all the components

1. JSP

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<html:form method="post" action="CouponDepositTypeMenu" >

<head>
<title>Menu</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"">
<link href="<%=contextRoot%>/webapp/css/style.css" rel="stylesheet" type="text/css">
<link href="<%=contextRoot%>/webapp/css/tablestyle.css" rel="stylesheet" type="text/css">
</head>


<td id="approve"><html:submit property="button" styleClass="ppm_btn" style="width:180px" styleId="hsia">
<bean:message key="login.hnipendingforApprove"/>
</html:submit></td>

<td id="approve"><html:submit property="button" styleClass="ppm_btn" style="width:180px" styleId="hsia">
<bean:message key="login.hniRejectedFromCBG"/>
</html:submit></td>

</html:form>


Note: here we are not using any hidden variables.


2.

public class CouponDepositTypeMenuAction extends PPMLookupDispatchAction
{

public ActionForward hnipendingforApprove(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {

final String STR_CLASS_NAME = "CouponDepositTypeMenuAction";
final String STR_METHOD_NAME = "hnipendingforApprove";
String strSeqId = "";
String forwardName = "hniPending";//by harsha on 9 may 2011
System.out.println("enetered into approve action");

HttpSession session = request.getSession();

LoginForm loginForm = (LoginForm) session.getAttribute("LoginForm");
String username = loginForm.getUsername();
System.out.println("user name -->" + username);

if(null != session.getAttribute("reqidlist")){
session.removeAttribute("reqidlist");
}
String button=(String)request.getParameter("button");
//System.out.println("which button::::::::::::::::naveen"+button);
String strBU = (String)session.getAttribute("strBU");
int roleId = DBAccess.getRoleId(username);
HniConfigForm ebswlformObj = new HniConfigForm();
List reqIdList = null;
List bpIdList = new ArrayList();
int Status=0;
if(roleId == 13){

if("Pending For ReqID Approval".equals(button)){
//System.out.println("33333333"+Status);
Status=3;
}
else if("Pending For UAT".equals(button)){
//System.out.println("55555555"+Status);
Status=5;
}else if("Pending For Production".equals(button)){
//System.out.println("777777777777"+Status);
Status=7;
forwardName="hniPendingProd";// by harsha on 9 may 2011
}// AUTO COCC12075 start
else if("Tarid-ReqId Release".equals(button)){
System.out.println("----->TARID<-------->REQID<-------"+Status);
Status=11;
forwardName="hniPendingProd";
}// AUTO COCC12075 end


reqIdList = HniEntityReleaseBusiness.getHniReqIdListForCbd(roleId,Status);
}else if(roleId == 120){
if("Pending For ReqID Approval".equals(button)){
//System.out.println("33333333"+Status);
Status=2;
}
else if("Pending For UAT".equals(button)){
//System.out.println("55555555"+Status);
Status=6;
}
reqIdList = HniEntityReleaseBusiness.getHniReqIdListForCbd(roleId,Status);
}
else
{
reqIdList = HniEntityReleaseBusiness.getHniReqIdList(roleId,strBU);
}

ebswlformObj.setReqIdList(reqIdList);
ebswlformObj.setBpIdList(bpIdList);
ebswlformObj.setStrUserName(username);
ebswlformObj.setStrRoleId(loginForm.getRoleid());
session.setAttribute("reqidlist", reqIdList);
session.setAttribute("bpIdList", bpIdList);
session.setAttribute("HniConfigForm", ebswlformObj);
return mapping.findForward(forwardName);
}





protected Map getKeyMethodMap(){
Map map = new HashMap();
map.put("deposit.button.couponDepositType","depsoitType");
map.put("deposit.button.PostPaid","postPaid");
map.put("deposit.button.couponPackageHeader","packageType");
map.put("rules.button.ppmrules","rules");
map.put("login.userManager","userManager");
map.put("login.field","fieldSales");
map.put("login.urs","urs");
map.put("login.brs","brs");
map.put("login.postpaid","postpaid");
map.put("button.ChangePassword","ChangePassword");
map.put("login.EBSWireline","EBSWireline");
map.put("login.hniebswl","HniEbsWLine");
map.put("login.hniebsws","HniEbsWLess");
map.put("login.approve","approve");
map.put("login.reinstate","reinstate");
map.put("login.reports","reports");
map.put("login.outputreports","outputreports");
map.put("login.draftdata","draftdata");
map.put("login.hniebsvdata","hniebsvdata");
map.put("login.hsia","hsia");
map.put("login.advancedreports","advancedreports");//COCC11278
map.put("button.Offerability","Offerability");//COFI11391

map.put("login.hniwl","HniWLine");
map.put("login.hniws","HniWLess");
map.put("login.hnivdata","hniVdata");
map.put("login.hnihsia","hniHsia");

map.put("hni.upload","uploadDocument");
map.put("login.hniConfScreen","hniConfScreen");
map.put("login.hnipendingforApprove","hnipendingforApprove");


map.put("login.hniReqIDforApprove","hnipendingforApprove");
// ADDED BY RAMARAO FOR HNI

map.put("login.hniRejectedFromCBG","hniRejectedListFromCBG");
map.put("login.hniUATRejectedFromCBG","hniRejectedListFromCBG");
// ADDED BY NAVEEN FOR HNI CONFIGURATION
map.put("login.hniReqIDforConfiguration", "hniPendingForConfiguration");

// ADDED BY NAVEEN 7-3-2011

map.put("login.hniReqIDforApproveUAT","hnipendingforApprove");
map.put("login.hniReqIDforApprovePROD","hnipendingforApprove");
map.put("login.pendingtaridReqIdList","hnipendingforApprove");
map.put("login.pendingtaridList","getPendingTarID");

return map;
}
}|


3.

public class PPMRequestProcessor extends org.apache.struts.tiles.TilesRequestProcessor
{
private static final String className="PPMRequestProcessor";
protected ActionForward
processActionPerform(HttpServletRequest request,
HttpServletResponse response,
Action action,
ActionForm form,
ActionMapping mapping)
throws IOException, ServletException
{
String methodName="processActionPerform";
try
{
LogTracer.writeTracerLog(className, methodName, "Start:::");
long start = System.currentTimeMillis();
ActionForward forward = super.processActionPerform( request, response,action,form,mapping);
long end = System.currentTimeMillis();
LogTracer.writeTracerLog(className, methodName, "Action Path:::"+mapping.getPath());
LogTracer.writeTracerLog(className, methodName, "Action Class:::"+action.getClass().getName());
LogTracer.writeTracerLog(className, methodName, "Action MethodName:"+request.getAttribute("getMethodName"));
LogTracer.writeTracerLog(className, methodName, "Action Input Page:::"+mapping.getInput());
if(forward != null)
{
LogTracer.writeTracerLog(className, methodName, "Forward Path:::"+forward.getName());
LogTracer.writeTracerLog(className, methodName, "Forward JSP Name:::"+forward.getPath());
}
else
{
processException(request, response,new Exception("Unable to find forward JSP"), form, mapping);
}
LogTracer.writeTracerLog(className, methodName, "End:::Time taken for Action::::"+((end-start)/60)+"ms");

return forward;
} catch (Exception e) {
return (processException(request, response,e, form, mapping));
}

}
protected ActionForward processException(HttpServletRequest request,
HttpServletResponse response, Exception exception, ActionForm form,
ActionMapping mapping) throws IOException, ServletException {

String methodName = "processException";
try
{
LogTracer.writeTracerLog(className, methodName, "Exception Path:::"+mapping.getPath());
LogTracer.writeTracerLog(className, methodName, "exception.getMessage()::::::::"+exception.getMessage());
ActionForward forward = super.processException(request, response, exception, form, mapping);

forward.setName("exception");
forward.setPath("/webapp/pages/exception.jsp"+exception.getMessage());
return forward;
} catch (Exception e) {
ActionForward forward = new ActionForward();
forward.setName("exception");
forward.setPath("/webapp/pages/exception.jsp?msg="+e.getMessage());
return forward;
}
}

public static void main(String[] args)
{
long l = System.currentTimeMillis();
System.out.println("s");
String s = "";
for (int i = 0; i < 10000; i++)
{
int k=i;
s = s+"ramu";
}
long e = System.currentTimeMillis();
System.out.println("End:::Time taken for Action::::"+((e-l)/60));
}
}

4.

public class PPMLookupDispatchAction extends LookupDispatchAction{

private static final String className = "PPMLookupDispatchAction";

protected Map getKeyMethodMap()
{
String methodName = "getKeyMethodMap";

return null;
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception
{
String methodName = "execute";
//LogTracer.writeTracerLog(className, methodName, "***ACTION PATH::::"+mapping.getPath());
//LogTracer.writeTracerLog(className, methodName, "***ACTION PATH::::"+mapping.getType());

return super.execute( mapping, form, request, response);
}
protected String getMethodName(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response, String parameter)
throws Exception
{
String methodName = "getMethodName";
response.setContentType("charset=UTF-8");
System.out.println("request.contentType : " + request.getContentType() );
String name = super.getMethodName(mapping,form,request,response, parameter);
LogTracer.writeTracerLog(className, methodName, "**********ACTION METHOD NAME::::"+name);
request.setAttribute("getMethodName", name);
return name;
}

}



5.
struts-config.xml setting



<controller processorClass="com.tcs.telecom.struts.action.PPMRequestProcessor"/>

<action path="/CouponDepositTypeMenu" parameter="button" scope="session" type="com.tcs.telecom.ppm.actions.CouponDepositTypeMenuAction" name="packageDepositMenuForm" input="/webapp/pages/coupon.jsp">
<forward name="deposit" path="/webapp/pages/couponDepositType.jsp" />
<forward name="package" path="/webapp/pages/couponPackageDetails.jsp"/>
<forward name="postpaid" path="/webapp/pages/cr.jsp" />
<forward name="rules" path="/webapp/pages/Rule.jsp" />
<forward name="returntomenu" path="/webapp/pages/Menu.jsp"/>
<forward name="usermanagement" path="/webapp/pages/UserManagement.jsp"/>
<forward name="salesmain" path="/webapp/pages/salesmain.jsp"/>
<forward name="brsmain" path="/webapp/pages/brsmain.jsp"/>
<forward name="changePassword" path="/webapp/pages/ChangePassword.jsp"/>
<forward name="approveURS" path="/webapp/pages/ApproveURS.jsp"/>
<forward name="hniebsws" path="/webapp/pages/hniEbsWS.jsp"/>
<forward name="hniebswl" path="/webapp/pages/hniEbsWL.jsp"/>
<forward name="approve" path="/webapp/pages/approve.jsp"/>
<forward name="reports" path="/webapp/pages/reports.jsp"/>
<forward name="outputreports" path="/webapp/pages/OutputReports.jsp"/>
<forward name="reinstate" path="/webapp/pages/ReInstate.jsp"/>
<forward name="hniebsvdata" path="/webapp/pages/hniEbsVdata.jsp"/>
<forward name="advancedreports" path="/webapp/pages/advancedreports.jsp"/>

<forward name="hniebshsia" path="/webapp/pages/hniEbsHsia.jsp"/>
<forward name="draftdata" path="/webapp/pages/Draftinfo.jsp"/>
<forward name="nodraftdetails" path="/webapp/pages/Nodraftinfo.jsp"/>
<forward name="offerability" path="/webapp/pages/segmentation.jsp"/>
<forward name="hnivdata" path="/webapp/pages/hniVdata.jsp"/>
<forward name="hnihsia" path="/webapp/pages/hniHsia.jsp"/>
<forward name="hniws" path="/webapp/pages/hniWS.jsp"/>
<forward name="hniwl" path="/webapp/pages/hniWL.jsp"/>

<forward name="uploadDocument" path="/webapp/pages/uploadDocument.jsp"/>
<forward name="newMenu" path="/webapp/pages/newMenu.jsp"/>
<forward name="hniPending" path="/webapp/pages/hnipendingforapprove.jsp"/>
<!-- added by ramarao for HNI on 26Nov2010 -->
<forward name="hniReject" path="/webapp/pages/hniReject/hniRejectedListforapprove.jsp"/>
<!-- added by naveen -->
<forward name="hniConfigure" path="/webapp/pages/hniPPMpackages/hniRejectedListforConfigure.jsp"/>
<forward name="pendingTarid" path="/webapp/pages/hniPendingTarIDList.jsp"/>

<!-- end -->
<forward name="newMenuGSM" path="/webapp/pages/newMenuGSM.jsp"/>
<!-- added by harsha for HNI on 09May2011 -->
<forward name="hniPendingProd" path="/webapp/pages/hnipendingforprod.jsp"/>
</action>


<form-bean name="packageDepositMenuForm" type="com.tcs.telecom.ppm.form.CouponDepositMenuForm"/>


Here we are getting the exception in

PPMLookupDispatchAction.java @

String name = super.getMethodName(mapping,form,request,response, parameter); line

Actual exception is:

Action[/CouponDepositTypeMenu] missing resource 'En attendant Préparation Pour la BRS' in key method map

Please let us know do you need any other information.
 
Srinivasa Rao Ammina
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi we are using struts 1.2 version .
 
Srinivasa Rao Ammina
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Got the solution

The following lines in the jsp pags causes the issues

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

If we remove these line it is working fine.

Thank for all your support on this.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i was found the exact answer please refer this link http://candidjava.com/struts-1x-i18n-internationalization-tutorial-with-example-programusing-link
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!