Raible's Wiki

Raible Designs
Wiki Home
Recent Changes


  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in

Referenced by

JSPWiki v2.2.33


Hide Menu


Difference between version 318 and version 290:

At line 5 removed 1 line.
At line 8 changed 8 lines.
SqlRowSet rset = getJdbcTemplate().queryForRowSet(
"select id, name from mytest where id > ? and name < ?",
new Object[] {new Long(1), "Z"});
int i = 0;
while (rset.next()) {
System.out.println("Row" + i + " " + rset.getString(2));
import javax.naming.Context;
import javax.naming.InitialContext;
At line 17 changed 1 line.
import junit.framework.TestCase;
At line 12 added 5 lines.
import org.mockejb.MockContainer;
import org.mockejb.SessionBeanDescriptor;
import org.mockejb.jndi.MockContextFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
At line 18 added 7 lines.
* Parent TestCase class for testing EJBs using MockEJB
* @author mraible
public abstract class MockEJBTestCase extends TestCase {
At line 26 added 8 lines.
* This method sets up a MockContainer and allows you to deploy an EJB to
* it. Override <code>onSetUp()</code> to add custom set-up behavior.
* @see #onSetUp()
protected final void setUp() throws Exception {
At line 35 added 11 lines.
Context ctx = new InitialContext();
ApplicationContext appCtx =
new ClassPathXmlApplicationContext(getConfigLocations());
ctx.bind("java:comp/env/jdbc/appDS", appCtx.getBean("dataSource"));
MockContainer mc = new MockContainer(ctx);
SessionBeanDescriptor dd = getDeploymentDescriptor();
At line 23 changed 2 lines.
This is how you could implement date handling using Struts / AppFuse. The example
uses a DOB where we want the user to enter a time in hours, minutes, and seconds:
protected String[] getConfigLocations() {
return new String[] { "classpath:/applicationContext.xml" };
At line 26 changed 2 lines.
In the POJO, your date is likely to be a java.util.Date or java.sql.Timestamp...
so you have a method called getDOB() which returns a java.util.Date (for this example).
protected void onSetUp() throws Exception {}
At line 29 changed 16 lines.
When, in your action, you convert your POJO to the form, the converters
(statically initialised in the BaseAction), are setup to convert the Date(s)
to Strings in your form.
So in your form you have getDOB() which returns a string....
public MyPOJO {
java.util.Date dob;
public MyForm {
java.lang.String dob; - the bridge between the dob java.util.Date in your POJO and the form.
protected abstract SessionBeanDescriptor getDeploymentDescriptor();
At line 46 removed 1 line.
At line 48 changed 5 lines.
The reason the dates are of type java.lang.String rather than java.util.Date in your
form is that if you apply the struts datePattern dd/MM/yyy validator to the user input
field, struts does not convert the string entered to a proper java.util.Date (that is
my belief anyhow - please correct me if this is wrong).... struts only seems to be able
to set the date property as a java.lang.String...
At line 54 changed 4 lines.
Also note: the datePattern does not work if you try and apply dd/MM/yyyy HH:mm -
this is not so much of a problem, as it is not particularly user friendly to make
the user input this long string freetext anyhow... so it is best to allow the user
to enter hours and minutes using drop downs (populated from the StartupListener)...
At line 59 changed 2 lines.
(BTW - a datePattern of just HH:mm does not seem to work either, so freetext entry of hours
and minutes is awkward unless someone writes a custom validator)...
At line 62 changed 1 line.
So we, we need to create 4 fields on our form, to capture the user inputting the dobStr, hour, minute, and second. So now our form looks like this:
[QuickStart Guide_es]
At line 64 changed 11 lines.
public MyForm {
private String dob; - the bridge between the dob java.util.Date in your POJO and the form.
java.lang.String hour;
java.lang.String minute;
java.lang.String second;
java.lang.String dobStr;
So you have applied the datePattern to the user input field (dateStr), and a String is
set on your form (in your chosen dateFormat), and the hours, minutes and seconds are set
from the drop downs.
At line 76 removed 5 lines.
We now need to do a bit of work in the getDob() method of the form:
public String getDob() {
if (getDateOfOffenceString()!=null && getHourOfOffenceString()!=null &&
getMinuteOfOffenceString()!=null) {
At line 82 changed 23 lines.
StringBuffer dateTime = new StringBuffer();
dateTime.append(" ");
return dateTime.toString();
return null;
Now, when you convert the form back to a POJO, the DateConverter (utils), will
convert the string back to a Date object (you need to check the DateConverter is applying the
correct datePattern in the SimpleDateFormat to map to your datePattern)
Q) What happens if you have 2 dates in your form, and they have different datePatterns?
A) I guess you would have to dynamically assign the correct converter (unregister DateConverter?)
Tip: If you are having problems with the Converter(s), put this in your log4j config:

Back to SandBox, or to the Page History.