jquery - Struts 2 i18n not working on dynamic content -



jquery - Struts 2 i18n not working on dynamic content -

i want translate page changes content depending on click. i.e.

i have jsp code, main.jsp:

<%@ page contenttype="text/html; charset=utf-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!doctype html> <html> <head> <meta charset="utf-8"> <title>main</title> <script type="text/javascript" src="js/jquery-1.11.1.js"></script> </head> <body> <div id="header"> <!-- when click on link, #content load page [cars.jsp | plains.jsp | ships.jsp] --> <a id="cars" href="#"><s:text name="global.cars" /></a> <a id="plains" href="#"><s:text name="global.plains" /></a> <a id="ships" href="#"><s:text name="global.ships" /></a> </div> <div id="content"> <!-- here goes page loaded when click [cars.jsp | plains.jsp | ships.jsp] --> <!-- utilize jquery .load() function --> <!-- of course of study utilize struts-tags within cars.jsp, plains.jsp , ships.jsp --> </div> <div id="footer"> <s:url id="indexes" namespace="/" action="locale" > <s:param name="request_locale" >es</s:param> </s:url> <s:url id="indexen" namespace="/" action="locale" > <s:param name="request_locale" >en</s:param> </s:url> <!-- if click on link below, language changes in page except content of #content --> <a href="%{indexes}">spanish</a> <a href="%{indexen}">english</a> <s:text name="global.footerinfo" /> </div> <script type="text/javascript"> $(document).ready(function(){ $("#cars").on("click", function(){ $("#content").load("pages/cars.jsp#carsbox"); }); $("#plains").on("click", function(){ $("#content").load("pages/plains.jsp#plainsbox"); }); $("#ships").on("click", function(){ $("#content").load("pages/ships.jsp#shipsbox"); }); }); </script> </body> </html>

i18n_en.properties:

global.cars=cars global.plains=plains global.ships=ships global.footerinfo=this web page of cars, plains , ships global.carsinfo=cars have @ to the lowest degree 4 wheels global.plainsinfo=plains have @ to the lowest degree 2 wings global.shipsinfo=ships floating on water

i18n_es.properties:

global.cars=coches global.plains=aviones global.ships=barcos global.footerinfo=esto es una web de coches, aviones y barcos global.carsinfo=los coches tienen al menos cuatro ruedas global.plainsinfo=los aviones tienen al menos dos alas global.shipsinfo=los barcos flotan en el agua

web.xml:

<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="webapp_id" version="3.1"> <display-name>hpnetsimulator</display-name> <welcome-file-list> <welcome-file>main.jsp</welcome-file> </welcome-file-list> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>

struts.xml

<?xml version="1.0" encoding="utf-8"?> <!doctype struts public "-//apache software foundation//dtd struts configuration 2.0//en" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.devmode" value="true" /> <constant name="struts.custom.i18n.resources" value="i18n" /> <package name="default" extends="struts-default" namespace="/"> <action name="locale" class="vehicles.localeaction"> <result name="success">main.jsp</result> </action> </package> </struts>

so, knows why content of div#content not translated?

here

$("#cars").on("click", function(){ $("#content").load("pages/cars.jsp#carsbox"); });

you bypassing framework workflow, , hence losing i18n feature (together other features).

yours jsps cars.jsp should called actions (passing through whole interceptor stack, including i18n interceptor), not straight jsp.

then create simple actions pages, eg.

public class loadcarsaction extends actionsupport{ public string execute(){ homecoming success; } }

declare them in struts config:

<action name="cars" class="vehicles.loadcarsaction"> <result>pages/cars.jsp</result> </action>

and replace jsp calls action calls:

$("#cars").on("click", function(){ $("#content").load('<s:url namespace="/" action="cars" anchor="carsbox" />'); });

this should enough.

jquery jsp struts2 internationalization

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -