01: /*
02: * $Id: SkillAction.java 476710 2006-11-19 05:05:14Z mrdon $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21: package org.apache.struts2.showcase.action;
22:
23: import org.apache.log4j.Logger;
24: import org.apache.struts2.showcase.dao.Dao;
25: import org.apache.struts2.showcase.dao.SkillDao;
26: import org.apache.struts2.showcase.model.Skill;
27:
28: import com.opensymphony.xwork2.Preparable;
29:
30: /**
31: * SkillAction.
32: *
33: */
34:
35: public class SkillAction extends AbstractCRUDAction implements
36: Preparable {
37:
38: private static final Logger log = Logger
39: .getLogger(SkillAction.class);
40:
41: private String skillName;
42: protected SkillDao skillDao;
43: private Skill currentSkill;
44:
45: public String getSkillName() {
46: return skillName;
47: }
48:
49: public void setSkillName(String skillName) {
50: this .skillName = skillName;
51: }
52:
53: protected Dao getDao() {
54: return skillDao;
55: }
56:
57: public void setSkillDao(SkillDao skillDao) {
58: if (log.isDebugEnabled()) {
59: log
60: .debug("SkillAction - [setSkillDao]: skillDao injected.");
61: }
62: this .skillDao = skillDao;
63: }
64:
65: public Skill getCurrentSkill() {
66: return currentSkill;
67: }
68:
69: public void setCurrentSkill(Skill currentSkill) {
70: this .currentSkill = currentSkill;
71: }
72:
73: /**
74: * This method is called to allow the action to prepare itself.
75: *
76: * @throws Exception thrown if a system level exception occurs.
77: */
78: public void prepare() throws Exception {
79: Skill preFetched = (Skill) fetch(getSkillName(),
80: getCurrentSkill());
81: if (preFetched != null) {
82: setCurrentSkill(preFetched);
83: }
84: }
85:
86: public String save() throws Exception {
87: if (getCurrentSkill() != null) {
88: setSkillName((String) skillDao.merge(getCurrentSkill()));
89: }
90: return SUCCESS;
91: }
92:
93: }
|