Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

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

User Guide
  - Korean
  - Chinese

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

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
Main
TextFormattingRules
WhatIsWiki




JSPWiki v2.2.33

[RSS]


Hide Menu

SandBox


Difference between version 318 and version 289:

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()) {
i++;
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 {
MockContextFactory.setAsInitial();
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();
mc.deploy(dd);
onSetUp();
}
At line 23 changed 1 line.
This is how I see how a DOB (for example) date 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 25 changed 2 lines.
In the POJO, your date is likely to be a java.util.Date or java.sql.Timestamp... you
have a method called getDOB() which returns a java.util.Date (for example) in your POJO....
protected void onSetUp() throws Exception {}
At line 28 changed 14 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;
}
}}}
and
{{{
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 43 removed 1 line.
}}}
At line 45 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 51 changed 1 line.
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)... (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)...
[CreateDAO_zh]
[CreateDAO_sp]
At line 53 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:
[CreateManager_es]
At line 55 changed 9 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.
[QuickStart Guide_es]
At line 65 changed 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) {
[SpringControllerUnitTest]
At line 71 removed 11 lines.
StringBuffer dateTime = new StringBuffer();
dateTime.append(getDateOfOffenceString());
dateTime.append(" ");
dateTime.append(getHourOfOffenceString());
dateTime.append(":");
dateTime.append(getMinuteOfOffenceString());
return dateTime.toString();
}
return null;
}
}}}
At line 83 changed 11 lines.
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?</P>
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:
log4j.logger.org.apache.commons.beanutils=DEBUG
[δΈ­ζ–‡ζŒ‡ε—|Articles_zh]

Back to SandBox, or to the Page History.