Call Struts Validation Using Javascript

29 08 2007

if(validateNameOfForm(document.forms[0])) {
document.forms[0].submit();
}





Remove TimeStamp From Date Datatype

25 08 2007

warghhhh..why are date datatypes such a headache?! :(

Tis was the easiest way i could think off without using some gungho algorithm :D Date -> String -> Date

// format current date (without time) and convert to string
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
String todayDate = formatter.format(new Date());
Date formattedDate = null;
try {
// convert date string back to Date datatype
formattedDate = formatter.parse(todayDate);
} catch (ParseException e) {
log.error("Parse today date error");
}





Change Mouse Cursor

20 08 2007

<span style="cursor: default">default</span>

default crosshair
pointer wait
move e-resize
n-resize ne-resize
w-resize s-resize
nw-resize se-resize
sw-resize




Europa & Red Hat Struting Their Stuff

16 08 2007

Eclipse Europa + Red Hat Developer Studio (Exadel included) ROCKS big time for Struts projects!

Much MUCH more stable then the previous versions of Eclipse + Exadel setup.

still waiting for SVN plugin :(





2 Decimal Floats

16 08 2007

var regex = new RegExp(‘^[0-9]+(\.[0-9]{0,2})?$’);





Format Numbers – Thousand Separator

14 08 2007

DecimalFormat formatter = new DecimalFormat(#,###);
out.print(formatter.format('1000'));





replaceAll String

14 08 2007

replace all commas with whitespace

var firstName ="John, Doe";
var formattedName= firstName.replace(/,/g,' ');





DynaBean Soup

13 08 2007

Java Struts.. now where do I start?

EXACTLY how I felt going thru the abundant (but mostly repetitive) tutorial available online. The model-view-controller stuff is enough to put ur head in a whirl spin.

So let’s start with an IDE:

  • Notepad: Ha! Good luck with that!
  • NetBeans: resource eating monster!
  • Eclipse: we have a winner!

Eclipse is pretty awesome for struts (thanks to the Exadel plugin). Problem is on a bad day, it’ll hang a zillion times but on a good day, u can go on struting ur stuff till kingdom comes :D

One thing about struts is it’s flexibility. You can’t do stuff like

<html:link href="user.do?edit=<%=editFlag%>">Edit User</html:link>

instead you’ll have to place the entire link into editURL variable

<html:link href="<%=editURL%>">Edit User</html:link>

which i suppose is much “safer”.

Another thing about a struts application, your jsp pages can end up containing html, struts tags, Javascript, Java or all of the above coz when a struts tag don’t work the way i want it to (blardy <html:checkbox>) i end up using the good ol reliable html tags which leaves me wondering why on earth am i using struts then?!

Why?

for 1, the auto form validation saves u a ton of code! that is.. if u get it to work and u’re dealing with simple validation.

2. displaying a populated listbox has never been so easy!
<html:select property="favColour" value='<%= request.getParameter("favColour")%>'">
<html:options collection="colours" property="value" labelProperty="description"/>
</html:select>

3. DynaBeans – Oh How I Love Thee!! i call it the recyclable classes. don’t have to create and write new .java classes, just set as many properties as u like.

DynaBean userBean = new LazyDynaBean();
userBean.set("First Name", "John");
userBean.set("Last Name", "Doe");

4. <bean:define> can save ur coding arse all because u can declare it’s type. Yes my friends.. ALL data types! including java.util.ArrayList and java.lang.String[]

so end of the day project, am pretty sure there’s more tricks and what-nots that makes struts coders life easier.. i just haven’t found it yet and tis why i started this blog :P

Happy Coding Amigos