1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| public class DeviceAddFormController extends SimpleFormController {
private MetaDao metaDao;
private DeviceDao deviceDao;
private Set j2meSet = new HashSet();
private Set styleSet = new HashSet();
public Set getJ2meSet() {
return j2meSet;
}
public void setJ2meSet(Set j2meSet) {
this.j2meSet = j2meSet;
}
public MetaDao getMetaDao() {
return metaDao;
}
public void setMetaDao(MetaDao metaDao) {
this.metaDao = metaDao;
}
public DeviceDao getDeviceDao() {
return deviceDao;
}
public void setDeviceDao(DeviceDao deviceDao) {
this.deviceDao = deviceDao;
}
protected Map referenceData(HttpServletRequest request) throws Exception {
Map map = new HashMap();
map.put("manufacturers", this.metaDao.getManufacturers());
map.put("j2mes", this.metaDao.getJ2mes());
map.put("styles", this.metaDao.getStyles());
return map;
}
protected void initBinder(HttpServletRequest request,
ServletRequestDataBinder binder) throws Exception {
binder.registerCustomEditor(Integer.class, new IntegerCustomEditor());
}
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command,
org.springframework.validation.BindException be) throws Exception {
DevicesForm devicesForm;
devicesForm = (DevicesForm) command;
Integer deviceId = devicesForm.getDevice().getId();
String ua = devicesForm.getDevice().getUserAgent();
// Verify if the device exist ...
if (deviceDao.isDevicePresent(ua)) {
Map map = new HashMap();
map.put("warning", "global.device.exist");
return this.showForm(request, response, be, map);
}
// ... else get "Set" device informations
else {
// J2me list
String[] stJ2me = request.getParameterValues("j2me");
if (stJ2me != null && stJ2me != null && stJ2me.length != 0) {
j2meSet.clear();
for (int v = 0; v < stJ2me.length; v++) {
J2meToDevice jtd = new J2meToDevice(new J2meToDevicePK(
deviceId, stJ2me[v]));
j2meSet.add(jtd);
if (log.isDebugEnabled())
log.debug("jtd" + jtd.getComp_id().getJ2meId()
+ "************************** stJ2me[" + v
+ "] = " + stJ2me[v]);
}
}
// Style list
String[] stStyle = request.getParameterValues("style");
if (stStyle != null && stStyle.length != 0) {
styleSet.clear();
for (int v = 0; v < stStyle.length; v++) {
StyleToDevice styletd = new StyleToDevice(
new StyleToDevicePK(deviceId, stStyle[v]));
styleSet.add(styletd);
if (log.isDebugEnabled())
log.debug("stStyle[" + v + "] = "
+ styletd.getComp_id().getStyleId());
}
}
devicesForm.getDevice().setJ2meToDevices(j2meSet);
devicesForm.getDevice().setStyleToDevices(styleSet);
// Insert Device informations
deviceId = this.deviceDao.store(devicesForm.getDevice());
}
// get the property successView from devicemanager-servlet.xml
String action = getSuccessView();
return new ModelAndView(new RedirectView(action + "?id=" + deviceId));
}
} |
Partager