KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > action > testimonials > ListTestimonialsAction


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.webapp.action.testimonials;
17
18 import com.blandware.atleap.common.TestimonialModuleConstants;
19 import com.blandware.atleap.common.util.QueryInfo;
20 import com.blandware.atleap.model.testimonials.Testimonial;
21 import com.blandware.atleap.service.testimonials.TestimonialManager;
22 import com.blandware.atleap.webapp.action.core.grid.BaseGridAction;
23 import com.blandware.atleap.webapp.taglib.core.grid.util.Grid;
24 import com.blandware.atleap.webapp.taglib.core.grid.util.SortField;
25 import com.blandware.atleap.webapp.util.core.WebappConstants;
26 import com.blandware.atleap.webapp.util.core.WebappUtil;
27 import com.blandware.atleap.webapp.util.testimonials.TestimonialModuleWebConstants;
28 import org.apache.struts.Globals;
29 import org.apache.struts.action.ActionForm;
30 import org.apache.struts.action.ActionForward;
31 import org.apache.struts.action.ActionMapping;
32
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
35 import java.util.HashMap JavaDoc;
36 import java.util.List JavaDoc;
37 import java.util.ListIterator JavaDoc;
38 import java.util.Locale JavaDoc;
39 import java.util.Map JavaDoc;
40
41 /**
42  * <p>Forward to the page with list of testimonials
43  * </p>
44  * <p><a HREF="ListTestimonialsAction.java.htm"><i>View Source</i></a></p>
45  * <p/>
46  *
47  * @author Andrey Grebnev <a HREF="mailto:andrey.grebnev@blandware.com">&lt;andrey.grebnev@blandware.com&gt;</a>
48  * @version $Revision: 1.4 $ $Date: 2006/03/10 17:10:33 $
49  * @struts.action path="/testimonials/list"
50  * name="testimonialForm"
51  * validate="false"
52  * roles="testimonials-item-list"
53  * @struts.action-forward name="listTestimonials"
54  * path=".testimonials.listTestimonials"
55  */

56 public final class ListTestimonialsAction extends BaseGridAction {
57     /**
58      * @param mapping The ActionMapping used to select this instance
59      * @param form The optional ActionForm bean for this request (if any)
60      * @param request The HTTP request we are proceeding
61      * @param response The HTTP response we are creating
62      * @return an ActionForward instance describing where and how
63      * control should be forwarded, or null if response
64      * has already been completed
65      */

66     public ActionForward execute(ActionMapping mapping, ActionForm form,
67                                  HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Exception JavaDoc {
68
69
70         Grid testimonialGrid = getGridByName(TestimonialModuleWebConstants.TESTIMONIALS_GRID, request.getSession());
71         if ( testimonialGrid == null ) {
72             testimonialGrid = new Grid(TestimonialModuleWebConstants.TESTIMONIALS_GRID);
73         }
74
75         // catch parameters related to sorting
76
String JavaDoc sortFieldName = request.getParameter("sortField");
77         String JavaDoc orderByClause = new String JavaDoc();
78         if ( TestimonialModuleWebConstants.TESTIMONIALS_GRID.equals(request.getParameter("gridName")) && sortFieldName != null && sortFieldName.length() > 0 ) {
79             SortField sortField = testimonialGrid.getSortFieldByFieldName(sortFieldName);
80             if ( sortField == null ) {
81                 sortField = new SortField(sortFieldName);
82                 testimonialGrid.addSortField(sortField);
83             } else {
84                 sortField.reverseOrder();
85                 testimonialGrid.addSortField(sortField);
86             }
87             orderByClause = testimonialGrid.getOrderByClause();
88             testimonialGrid.getSortFieldByFieldName(sortFieldName).reverseOrder();
89         }
90
91         saveGrid(testimonialGrid, request.getSession());
92
93         QueryInfo queryInfo = new QueryInfo();
94         queryInfo.setWhereClause(testimonialGrid.getWhereClause());
95         queryInfo.setOrderByClause(orderByClause);
96
97         Map JavaDoc queryParameters = new HashMap JavaDoc();
98         Locale JavaDoc locale = (Locale JavaDoc) request.getSession().getAttribute(Globals.LOCALE_KEY);
99         queryParameters.put("localeIdentifier", locale.getLanguage());
100         queryInfo.setQueryParameters(queryParameters);
101
102         TestimonialManager testimonialManager = (TestimonialManager) getBean(TestimonialModuleConstants.TESTIMONIAL_MANAGER_BEAN);
103         List JavaDoc testimonials = testimonialManager.listTestimonials(queryInfo).asList();
104
105         for ( ListIterator JavaDoc i = testimonials.listIterator(); i.hasNext(); ) {
106             Testimonial testimonial = (Testimonial) i.next();
107             Testimonial tmp = new Testimonial();
108             WebappUtil.copyProperties(tmp, testimonial, request);
109             tmp.setUri(WebappUtil.getActionMappingURL(testimonial.getUri(), null, request, WebappConstants.URL_TYPE_CONTEXT_RELATIVE));
110             i.set(tmp);
111         }
112
113         request.setAttribute(TestimonialModuleWebConstants.TESTIMONIALS_COLLECTION_KEY, testimonials);
114
115         // save transaction token in request
116
saveToken(request);
117         return mapping.findForward("listTestimonials");
118     }
119 }
Popular Tags