Skip to content

Commit 49406c1

Browse files
committed
add custom date converter
1 parent b7a4a5d commit 49406c1

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/main/java/com/DateConverter.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com;
2+
3+
import java.util.Map;
4+
5+
import org.apache.struts2.util.StrutsTypeConverter;
6+
7+
import com.opensymphony.xwork2.LocalizedTextProvider;
8+
import com.opensymphony.xwork2.inject.Inject;
9+
10+
public class DateConverter extends StrutsTypeConverter {
11+
12+
private LocalizedTextProvider localizedTextProvider;
13+
14+
@Inject
15+
public void setLocalizedTextProvider(LocalizedTextProvider localizedTextProvider) {
16+
this.localizedTextProvider = localizedTextProvider;
17+
}
18+
19+
public DateConverter() {
20+
System.out.println("DateConverter.DateConverter()");
21+
}
22+
23+
@Override
24+
public Object convertFromString(Map context, String[] values, Class toClass) {
25+
System.out.println("DateConverter.convertFromString() localizedTextProvider=" +
26+
localizedTextProvider);
27+
return null;
28+
}
29+
30+
@Override
31+
public String convertToString(Map context, Object obj) {
32+
System.out.println("DateConverter.convertToString() localizedTextProvider=" +
33+
localizedTextProvider);
34+
return "";
35+
}
36+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
java.util.Date=com.DateConverter

src/main/webapp/WEB-INF/example/HelloWorld.jsp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@
2323
<s:a href="%{url}">Espanol</s:a>
2424
</li>
2525
</ul>
26+
27+
<s:bean var="d" name="java.util.Date" />
28+
<s:property value="#d" />
29+
2630
</body>
2731
</html>

0 commit comments

Comments
 (0)