Archive for January 2nd, 2008

Sort a bean

Sort a bean

java.util.Comparator
java.util.TreeSet
org.apache.cocoon.i18n.XMLResourceBundle
org.apache.cocoon.i18n.XMLResourceBundleFactory
 
ListTravelerType = hs.createQuery("FROM Utypes WHERE isdefault = 1 ORDER BY type ASC").list();
 
try {
	XMLResourceBundle translationBundle = null;
	XMLResourceBundleFactory bf = (XMLResourceBundleFactory)manager.lookup(XMLResourceBundleFactory.ROLE);
	translationBundle = (XMLResourceBundle)bf.select("/opt/tomcat/webapps/project/translations", "travelertypes", );
 
	for(Iterator i = ListTravelerType.iterator(); i.hasNext();) {
		Utypes elt = (Utypes)i.next();
		hs.evict(elt);
		elt.setType(translationBundle.getString(elt.getType()));
	}
} catch (Exception cme) {
	logger.error("Could not look up the PersistenceManager", cme);
}
 
Set sortedTravelerType = new TreeSet(new Comparator() {
	public int compare(Object o1, Object o2) {
		if(o1 instanceof Utypes && o2 instanceof Utypes) {
			Utypes utype1 = (Utypes)o1;
			Utypes utype2 = (Utypes)o2;
			return utype1.getType().compareTo(utype2.getType());
		}
		return 1;
	}
});
 
sortedTravelerType.addAll(ListTravelerType);

Cocoon translations in XSP

Cocoon translations in XSP – java

 
XMLResourceBundle translationBundle = null; 
XMLResourceBundleFactory bf = (XMLResourceBundleFactory)manager.lookup(XMLResourceBundleFactory.ROLE);
 
translationBundle = (XMLResourceBundle)bf.select("/opt/tomcat/webapps/project/translations", "translations", <util:get-sitemap-parameter name="locale"/>);
String translated = translationBundle.getString("Go get the String");

Sorted elements

Include jQuery !!

地図上で目的地を選択

<p class="tv-check-item">
        <input id="added_utype_6" class="checkIterator" type="checkbox" name="added_utype_6" value="Plubs" checked="true"/>
        <label for="added_utype_6">  Plubs</label>
</p>
<p class="tv-check-item">
        <input id="added_utype_1" class="checkIterator" type="checkbox" name="added_utype_1" value="Allotum" checked="true"/>
        <label for="added_utype_1">  Allotum</label>
</p>
<p class="tv-check-item">
        <input id="added_utype_0" class="checkIterator" type="checkbox" name="added_utype_0" value="Anotum" checked="true"/>
        <label for="added_utype_0">  Anotum</label>
</p>
for (t = 0; t &lt; $("p[@class='tv-check-item']").length; t++) {
        compareElement = $("p[@class='tv-check-item']").get(t);
        compareValue = $(compareElement).children("input").get(0);
        compareValue = $(compareValue).val();
        $("p[@class='tv-check-item']:gt("+t+")").each(function(i){
                toBeCompared = $(this).children("input").get(0);
                toBeCompared = $(toBeCompared).val();
                if (toBeCompared.toLowerCase() &lt; compareValue.toLowerCase()) {
                        $(compareElement).before(this);
                        compareElement = this;
                        compareValue = $(compareElement).children("input").get(0);
                        compareValue = $(compareValue).val();
                }
        });
}