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 java.util.List;
13  
14  import javax.servlet.http.HttpServletRequest;
15  import javax.servlet.http.HttpServletResponse;
16  
17  import org.apache.struts.action.ActionForm;
18  import org.apache.struts.action.ActionForward;
19  import org.apache.struts.action.ActionMapping;
20  import org.springframework.web.struts.ActionSupport;
21  
22  /*** 
23   * MyEclipse Struts
24   * Creation date: 11-11-2006
25   * 
26   * XDoclet definition:
27   * @struts.action validate="true"
28   */
29  public class NewQAAction extends ActionSupport {
30  
31  	/*** 
32  	 * Method execute
33  	 * @param mapping
34  	 * @param form
35  	 * @param request
36  	 * @param response
37  	 * @return ActionForward
38  	 */
39  	public ActionForward execute(ActionMapping mapping, ActionForm form,
40  			HttpServletRequest request, HttpServletResponse response) {
41  		QaDao qaDao = (QaDao) getWebApplicationContext().getBean("qaDao");
42  		List<Topic> topics = qaDao.getTopicList();
43  		if(topics.size() == 0)
44  		{
45  			request.setAttribute("notopic", Boolean.TRUE);
46  			return mapping.findForward("notopic");
47  		}
48  		else
49  		{
50  			request.setAttribute("topics", topics);
51  			if(request.getParameter("edit") != null)
52  			{
53  				QA qa = qaDao.getQaById(Integer.parseInt(request.getParameter("id")));
54  				QaForm qaForm = (QaForm)form;
55  				qaForm.setQuestion(qa.getQuestion());
56  				qaForm.setAnswer(qa.getAnswer());
57  				if(qa.getTopic() != null)
58  				{
59  					qaForm.setTopic(qa.getTopic().getId().intValue());
60  				}
61  				request.setAttribute("id", request.getParameter("id"));
62  			}
63  			return mapping.findForward("ok");
64  		}
65  	}
66  }