1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.anite.antelope.modules.actions.formSample;
19
20 import net.sf.hibernate.Session;
21 import net.sf.hibernate.Transaction;
22
23 import org.apache.turbine.modules.actions.VelocityAction;
24 import org.apache.turbine.util.RunData;
25 import org.apache.velocity.context.Context;
26
27 import com.anite.antelope.modules.screens.formSample.AnimalScreen;
28 import com.anite.antelope.om.Animal;
29 import com.anite.meercat.PersistenceLocator;
30 import com.anite.penguin.form.Field;
31 import com.anite.penguin.modules.tools.FormTool;
32
33 /***
34 * @author Ben
35 *
36 */
37 public class UpdateAnimalAction extends VelocityAction {
38
39 /***
40 * Save the updated animal fields
41 */
42 public void doPerform(RunData data, Context context) throws Exception {
43
44 FormTool form = (FormTool) context.get(FormTool.DEFAULT_TOOL_NAME);
45
46 if (form.isAllValid()) {
47
48 String age = ((Field) form.getFields().get(AnimalScreen.AGE))
49 .getValue().toString();
50 Animal animal = (Animal) data.getSession().getAttribute(
51 WhichAnimal.ANIMAL);
52 animal.setAge(Integer.parseInt(age));
53
54 Session session = PersistenceLocator.getInstance()
55 .getCurrentSession();
56 Transaction t = session.beginTransaction();
57 session.saveOrUpdate(animal);
58 t.commit();
59
60
61 data.setScreenTemplate("formSample,TheMenagerie.vm");
62 } else {
63
64
65
66
67
68 }
69 }
70 }