View Javadoc

1   /*
2    * Generated by MyEclipse Struts
3    * Template path: templates/java/JavaClass.vtl
4    */
5   package hu.elte.tribus.action;
6   
7   import hu.elte.tribus.form.QaForm;
8   import hu.elte.tribus.interfaces.QaDao;
9   import hu.elte.tribus.model.QA;
10  import hu.elte.tribus.model.Topic;
11  
12  import javax.servlet.http.HttpServletRequest;
13  import javax.servlet.http.HttpServletResponse;
14  
15  import org.apache.struts.action.ActionForm;
16  import org.apache.struts.action.ActionForward;
17  import org.apache.struts.action.ActionMapping;
18  import org.springframework.web.struts.ActionSupport;
19  
20  /*** 
21   * MyEclipse Struts
22   * Creation date: 11-11-2006
23   * 
24   * XDoclet definition:
25   * @struts.action validate="true"
26   */
27  public class SaveQAAction extends ActionSupport {
28  
29  	/*** 
30  	 * Method execute
31  	 * @param mapping
32  	 * @param form
33  	 * @param request
34  	 * @param response
35  	 * @return ActionForward
36  	 */
37  	public ActionForward execute(ActionMapping mapping, ActionForm form,
38  			HttpServletRequest request, HttpServletResponse response) {
39  		QaForm qaForm = (QaForm)form;
40  		QaDao qaDao = (QaDao) getWebApplicationContext().getBean("qaDao");
41  		QA qa;
42  		if(request.getParameter("id") != null)
43  		{
44  			qa =  qaDao.getQaById(Integer.parseInt(request.getParameter("id")));
45  		}
46  		else
47  		{
48  			qa = new QA();
49  		}
50  		qa.setQuestion(qaForm.getQuestion());
51  		qa.setAnswer(qaForm.getAnswer());
52  		Topic topic = qaDao.getTopicById(qaForm.getTopic());
53  		qa.setTopic(topic);
54  		qaDao.saveQa(qa);
55  		qaForm.setQuestion("");
56  		qaForm.setAnswer("");
57  		qaForm.setTopic(0);
58  		request.setAttribute("savedqa", Boolean.TRUE);
59  		request.setAttribute("qa.list", qaDao.getQaList());
60  		return mapping.findForward("ok");
61  	}
62  }