Saturday, June 18, 2011

How do I use my web resource bundle within my Spring controller?



Here is how I did it:



In my controller:




import org.springframework.context.ApplicationContext; ...
@Autowired private ApplicationContext context;



In the resource bundle ApplicationResources.properties


gotocode.error.notfound=Sorry {0} is not recognized as a code. 



Back in the controller




public static final String GOTOCODE_NOTFOUND_KEY = "gotocode.error.notfound";
public
static final String CODE_NOT_FOUND_MESSAGE = "Sorry the entry {0} is not recognized as a code.";
...
public ModelAndView findNextInSeries(String code,..
String errorMessage = context.getMessage(
GOTOCODE_NOTFOUND_KEY, new Object[] { code }, CODE_NOT_FOUND_MESSAGE, Locale.getDefault());   

Previously my ApplicationResources.properties was configured in the web.xml







http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_1270163143862"></web-app>

<display-name>Sample Spring Resource Bundle
<distributable>

<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext
<param-value>ApplicationResources



As well as in the Spring Application context configuration (dispatcher-servlet.xml):

Setting up Eclipse TPTP for performance monitoring of Jetty run from Maven

This is a document to help you setup Eclipse TPTP plugin for performance monitoring of J2EE application deployed to Jetty using the jetty-maven-plugin.

Open MyEclipse Configuration center and search for TPTP, download the newest version of TPTP plugin, restart your IDE after the install finishes.

Next go to the TPTP homepage and download the Agent controller for your architecture (I downloaded windows IA32).

Extract the Agent controller zip to C:\Tools\agntctrl.win_ia32-TPTP-4.7.2

Edit your system environment variables and add

RASERVER_HOME=C:\Tools\agntctrl.win_ia32-TPTP-4.7.2 PATH=C:\Tools\agntctrl.win_ia32-TPTP-4.7.2\bin;%PATH%  Open a command prompt and goto agent controller cd C:\Tools\agntctrl.win_ia32-TPTP-4.7.2\bin SetConfig.bat 

This should display the following:

C:\Tools\agntctrl.win_ia32-TPTP-4.7.2\bin>SetConfig.bat Specify the fully qualified path of "javaw.exe" (e.g. c:\jdk1.4\jre\bin\javaw.ex e):   Default>"C:\Program Files\IBM\WebSphere\AppServer\java\jre\bin\javaw.exe" (Pre ss  to accept the default value)   New value> Network access mode (ALL=allow any host, LOCAL=allow only this host, CUSTOM=list  of hosts):   Default>"LOCAL" (Press  to accept the default value)   New value>ALL Security enabled. (true/false):   Default>"FALSE" (Press  to accept the default value)   New value> 

Start the Agent Controller by launching a command console window with Administrator privledges (Run as Admni..) The change your working directory to

cd C:\Tools\agntctrl.win_ia32-TPTP-4.7.2\bin
ACServer.exe

See this link for more agent controller info http://dev.eclipse.org/viewcvs/viewvc.cgi/platform/org.eclipse.tptp.platform.agentcontroller/src-native-new/packaging_md/windows/getting_started.html?root=TPTP_Project&view=co

This is also a link with good info on TPTP http://eclipse.sys-con.com/node/508048?page=0,2

Configure piAgent and start your application with Maven by adding this to MAVEN_OPTS environment variable:

-XrunpiAgent:server=enabled 

From eclipse navigate to Run | Profile Configurations... | Attach to Agent | New

ACServer should be running on localhost port 10002, check this with netstat -a -b -n command or test button in eclipse

Jetty JVM Agent should be detected on the Agent tab. select ONLY ONE of the profile probes, CPU --or-- MEMORY etc.. do NOT select more than one, treat them as mutually exclusive radio buttons rather than check boxes.

You can then perform tasks in your application and save the data captured. Also you can create new reports from the captured data with TPTP eclipse tools.

See http://www.eclipse.org/articles/Article-TPTP-Profiling-Tool/tptpProfilingArticle.html

Why your web browser should be updated often.

I was reading a book online about 20 things people should understand about the Internet. Number 7 is about keeping your browser updated. Here are the3 simple reasons given:

First, old browsers are vulnerable to attacks

Second, the web evolves quickly. Old browsers will miss out.

Third and last, old browsers slow down innovation on the web.


I wish I had this in mind when working with a client who insisted on a dynamic Web 2.0 look to the complex application but also demanded compatibility with IE7.

Delivering on both of these requirements (latest Internet bells and whistles like AJAX as well as backward compatibility with older browser versions) increases the difficulty level and cost of the site development considerably. First you have to test on these older browser versions in addition to testing on the common browsers, which increases the development time. Next you have to pare down features and functionality so that it works consistently everywhere, so you might have had a nice dynamic form or navigation control working in IE9 and FireFox 4, but it all gets tossed out when it cannot work in IE7 (see holding up innovation reason given above). Also for some "must have" site features or functionality: developers will usually have to code around older browser version quirks, so instead of writing code in one place to perform a task, it is written one place or one way for modern browsers and another place or another way for older browsers. This causes a code maintenance issue as you now have multiple places to check to fix problems or update code for a single feature or site behavior. This is a problem for HTML, CSS, and Javascript as all three can behave differently on different browsers. Yet another problem that can arise is your performance can vary widely in different browser flavors and versions, for example IE7 javascript benchmarks are miserably slow when compared with more recent versions of IE and other browsers like FireFox or Chrome. This can cause problems where failing to test on the required browser versions can really bite you. If a performance issue (or any browser version issue) is found late in the development cycle, either because the testing was not done along side development in that version or because developers only used modern browsers for their self verification and validation of the application, then the time to fix the problem is much larger and more difficult than if it had been caught earlier.
The best defense to this situation of having to develop Javascript for modern sites to be used by clunky old browser versions is to use a good library like GWT, jQuery or Dojo. These abstract away many of the browser specific cruft that would drive you mad when trying to implement your site. I am not sure of a solution for this problem as it relates to HTML/CSS however, cross browser CSS is a major pain in the you know what.



About Me

My photo
Lead Java Developer Husband and Father

Tags