<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Java on weblog.masukomi.org</title>
    <link>https://weblog.masukomi.org/tags/java/</link>
    <description>Recent content in Java on weblog.masukomi.org</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <copyright>&amp;copy Kay Rhodes (masukomi.org) 2022</copyright>
    <lastBuildDate>Thu, 12 Mar 2009 00:00:00 +0000</lastBuildDate><atom:link href="https://weblog.masukomi.org/tags/java/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Localization for Struts Freemarker users</title>
      <link>https://weblog.masukomi.org/2009/03/12/localization-for-struts-freemarker-users/</link>
      <pubDate>Thu, 12 Mar 2009 00:00:00 +0000</pubDate>
      
      <guid>https://weblog.masukomi.org/2009/03/12/localization-for-struts-freemarker-users/</guid>
      <description>&lt;p&gt;Because it took me freaking forever to find instructions on how to do
this&amp;hellip;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;You do NOT need a message-resource tag in your struts configuration
files. Those are outdated instructions for old versions of
Struts.You do not need to edit ANY xml at all.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Your Action needs to implement Freemarker&amp;rsquo;s TemplateMethodModel
interface&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You need a package.properties file (the default locale) and a then
another one for each other locale / language you want to support
(ex. package_en_US.properties). These should be located in the
same package as the Struts action that will be needing them. You can
also do ClassName.properties if you want to tie some to a particular
class.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add the code snippet below to your Action. There&amp;rsquo;s a &lt;a href=&#34;http://gist.github.com/78303&#34;&gt;backup
here&lt;/a&gt; if it&amp;rsquo;s borked below.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Insert localized text into the page with a call like this
${text(&amp;ldquo;property.name&amp;rdquo;)} Struts will take care of figuring out the
default language from the user&amp;rsquo;s browser. If you have a better way
of determining this there is documentation out there on how to
programatically specify the locale you want to be used&lt;/p&gt;
&lt;p&gt;public class MyAction extends ActionSupport implements TemplateMethodModel {
/*Your functionality here */&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; /**
 * when you need to display a localized piece of text in
 * the ftl just use  ${text(&amp;quot;some.property.name&amp;quot;)}
 * there should be a package.properties or ClassName.properties
 * file in the same source package directory as the Action that
 * will be using them. There *is* a way to set a global properties file
 * but I don&#39;t know the details.
 * Obviously the text for other languages would be specified in files like
 * package_en_US.properties
 * @return an implementation of TemplateMethodModel which takes a
 * one parameter method, the parameter is the name of the localized property
 * you want to access.
 */
public TemplateMethodModel getText(){
    return this;
}
public TemplateModel exec(List args) throws TemplateModelException {
    if (args.size() != 1) {
        throw new TemplateModelException(&amp;quot;Wrong arguments&amp;quot;);
    }
    return new SimpleScalar(getText((String)args.get(0)));
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;ecgn adds the following notes about actions:&lt;br&gt;
There has to be an action class involved in the Struts/Freemarker action.&lt;/p&gt;
&lt;p&gt;Example – the following simple page view &lt;em&gt;won’t work&lt;/em&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;action name=”ShowLogin”&amp;gt;
   &amp;lt;result type=”freemarker”&amp;gt;Login.ftl&amp;lt;/result&amp;gt;
&amp;lt;/action&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To get it to work, I have to insert a “dummy” action into the process:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;action name=”ShowLogin” class=”actions.DummyAction”&amp;gt;
&amp;lt;result type=”freemarker”&amp;gt;Login.ftl&amp;lt;/result&amp;gt;
&amp;lt;/action&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Keywords / Google Food: localization, internationalization, i18n,
freemarker, struts&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>The best argument for compiled languages</title>
      <link>https://weblog.masukomi.org/2007/08/19/the-best-argument-for-compiled-languages/</link>
      <pubDate>Sun, 19 Aug 2007 00:00:00 +0000</pubDate>
      
      <guid>https://weblog.masukomi.org/2007/08/19/the-best-argument-for-compiled-languages/</guid>
      <description>&lt;p&gt;I keep thinking back to a short comment at BarCamp Manchester
in the Unit Testing talk. When asked if anyone had written an app with
100% code coverage the guy beside me raised his hand. Now I&amp;rsquo;ve been
advocating for a while now that it&amp;rsquo;s essentially wasted time to bother
testing your getters and setters, and when I mentioned something to this
effect he said, &amp;ldquo;How do you know you haven&amp;rsquo;t made a typo in a variable
name?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;hellip;&lt;/p&gt;
&lt;p&gt;My mind just kind of spun for a second on that one for a second. I guess
I&amp;rsquo;ve been in Java land for so long that the concept of having such a
thing exist for more than a few seconds just doesn&amp;rsquo;t enter my brain. I
mean first off, the IDE will bitch at you, because it can&amp;rsquo;t compile it,
and even if you&amp;rsquo;re not using an IDE the compiler will bitch at you. I
just responded that &amp;ldquo;I use a compiled language so that&amp;rsquo;s never something
I have to worry about.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;Now, as many of you know I&amp;rsquo;m still a huge fan of languages like
&lt;a href=&#34;https://weblog.masukomi.org/2007/7/31/you-treat-her-like-a-sex-toy&#34;&gt;Perl&lt;/a&gt;
and Ruby so I work in them fairly often. And I still say that it&amp;rsquo;s not
worth your time writing tests for your getters and setters even in them
because unlike Java these languages don&amp;rsquo;t have IDEs that happily spit
out a getter and setter for every variable in your class regardless of
if you need it or not. As a result, you only create the ones you need.
And if you need them, then they&amp;rsquo;re going to be used, and if they&amp;rsquo;re
used, you can pretty much guarantee that you&amp;rsquo;ll see the results of any
typos show up really quickly when you test the methods that actually do
something noteworthy, because they&amp;rsquo;ll use the getters and setters
(otherwise why did you write them?) and either blow up when the compiler
hits them or not work as expected, which is why you&amp;rsquo;re writing a test.&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
