Source Code Cross Referenced for LookupAction.java in  » ERP-CRM-Financial » Kuali-Financial-System » edu » iu » uis » eden » lookupable » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ERP CRM Financial » Kuali Financial System » edu.iu.uis.eden.lookupable 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005-2006 The Kuali Foundation.
003:         *
004:         *
005:         * Licensed under the Educational Community License, Version 1.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         *
009:         * http://www.opensource.org/licenses/ecl1.php
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package edu.iu.uis.eden.lookupable;
018:
019:        import java.io.IOException;
020:        import java.util.Collections;
021:        import java.util.Comparator;
022:        import java.util.HashMap;
023:        import java.util.Iterator;
024:        import java.util.List;
025:        import java.util.Map;
026:        import java.util.StringTokenizer;
027:
028:        import javax.servlet.ServletException;
029:        import javax.servlet.http.HttpServletRequest;
030:        import javax.servlet.http.HttpServletResponse;
031:
032:        import org.apache.commons.beanutils.BeanUtils;
033:        import org.apache.commons.lang.StringUtils;
034:        import org.apache.struts.action.ActionForm;
035:        import org.apache.struts.action.ActionForward;
036:        import org.apache.struts.action.ActionMapping;
037:        import org.apache.struts.action.ActionMessages;
038:        import org.displaytag.tags.TableTagParameters;
039:        import org.displaytag.util.ParamEncoder;
040:        import org.kuali.rice.resourceloader.GlobalResourceLoader;
041:
042:        import edu.iu.uis.eden.WorkflowServiceErrorException;
043:        import edu.iu.uis.eden.exception.WorkflowRuntimeException;
044:        import edu.iu.uis.eden.export.ExportDataSet;
045:        import edu.iu.uis.eden.export.ExportFormat;
046:        import edu.iu.uis.eden.export.Exportable;
047:        import edu.iu.uis.eden.plugin.attributes.WorkflowLookupable;
048:        import edu.iu.uis.eden.util.Utilities;
049:        import edu.iu.uis.eden.web.WorkflowAction;
050:
051:        /**
052:         * Struts Action for interacting with lookupables.
053:         *
054:         * @see WorkflowLookupable
055:         *
056:         * @author jhopf
057:         * @author bmcgough
058:         * @author rkirkend
059:         * @author ewestfal
060:         */
061:        public class LookupAction extends WorkflowAction {
062:
063:            private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
064:                    .getLogger(LookupAction.class);
065:
066:            /**
067:             * storeForm - When crossing quickFinders (moving from one lookupable to another), this method is called to store the data on the previous quickFinder in the UserSession object.
068:             *
069:             * @param mapping -
070:             *            action mapping.
071:             * @param form -
072:             *            LookupForm that is stored in user session and contains the values entered on the jsp form.
073:             * @param request -
074:             *            request.
075:             * @param response -
076:             *            response.
077:             * @return - where to go next.
078:             * @throws Exception
079:             */
080:            public ActionForward performLookup(ActionMapping mapping,
081:                    ActionForm form, HttpServletRequest request,
082:                    HttpServletResponse response) throws Exception {
083:                LookupForm lookupForm = (LookupForm) form;
084:                WorkflowLookupable workflowLookupable = getLookupable(request
085:                        .getParameter("lookupableImplServiceName"));//(WorkflowLookupable) SpringServiceLocator.getExtensionService().getLookupable(request.getParameter("lookupableImplServiceName"));
086:
087:                Map fieldValues = new HashMap();
088:                for (Iterator iter = workflowLookupable.getRows().iterator(); iter
089:                        .hasNext();) {
090:                    Row row = (Row) iter.next();
091:
092:                    for (Iterator iterator = row.getFields().iterator(); iterator
093:                            .hasNext();) {
094:                        Field field = (Field) iterator.next();
095:                        if (field.isHasLookupable()
096:                                && request.getParameter(
097:                                        "lookupableImplServiceName").equals(
098:                                        field.getQuickFinderClassNameImpl())) {
099:                            fieldValues.put(field.getPropertyName(), "");
100:                        } else {
101:                            fieldValues.put(field.getPropertyName(), request
102:                                    .getParameter(field.getPropertyName()));
103:                        }
104:                    }
105:                }
106:                lookupForm.setFields(fieldValues);
107:
108:                workflowLookupable.checkForAdditionalFields(fieldValues,
109:                        request);
110:                StringBuffer url = new StringBuffer(
111:                        "Lookup.do?methodToCall=quickFinder&lookupableImplServiceName=");
112:                if (request.getParameter("quickFinderLookupable") != null
113:                        && !request.getParameter("quickFinderLookupable")
114:                                .equals("")) {
115:                    url.append(request.getParameter("quickFinderLookupable"));
116:                } else {
117:                    url.append(request
118:                            .getParameter("lookupableImplServiceName"));
119:                }
120:                url.append("&docFormKey=").append(
121:                        getUserSession(request).addObject(lookupForm));
122:                url.append("&returnLocation=").append(
123:                        workflowLookupable.getReturnLocation());
124:
125:                StringBuffer conversionFields = new StringBuffer();
126:                for (Iterator iter = workflowLookupable.getRows().iterator(); iter
127:                        .hasNext();) {
128:                    Row row = (Row) iter.next();
129:
130:                    for (Iterator iterator = row.getFields().iterator(); iterator
131:                            .hasNext();) {
132:                        Field field = (Field) iterator.next();
133:                        if (!Utilities
134:                                .isEmpty(field.getDefaultLookupableName())) {
135:                            conversionFields.append(
136:                                    field.getDefaultLookupableName()).append(
137:                                    ":").append(field.getPropertyName())
138:                                    .append(",");
139:                        }
140:                    }
141:                }
142:                if (!Utilities.isEmpty(conversionFields.toString())) {
143:                    url.append("&conversionFields=").append(
144:                            conversionFields.substring(0, conversionFields
145:                                    .lastIndexOf(",")));
146:                }
147:
148:                return new ActionForward(url.toString(), true);
149:            }
150:
151:            /**
152:             * quickFinder - sets the data on the lookupForm from the previous quickFinder to the next quickFinder.
153:             *
154:             * @param mapping -
155:             *            action mapping.
156:             * @param form -
157:             *            LookupForm for the next quickFinder.
158:             * @param request -
159:             *            request.
160:             * @param response -
161:             *            response.
162:             * @return - where to go next.
163:             * @throws Exception
164:             */
165:            public ActionForward quickFinder(ActionMapping mapping,
166:                    ActionForm form, HttpServletRequest request,
167:                    HttpServletResponse response) throws Exception {
168:                LookupForm lookupForm = (LookupForm) form;
169:                if (request.getParameter("lookupableImplServiceName") != null) {
170:                    lookupForm.setLookupableImplServiceName(request
171:                            .getParameter("lookupableImplServiceName"));
172:                }
173:
174:                if (request.getParameter("docFormKey") != null) {
175:                    lookupForm.setFormKey((String) request
176:                            .getParameter("docFormKey"));
177:                }
178:                if (request.getParameter("returnLocation") != null) {
179:                    lookupForm.setBackLocation(request
180:                            .getParameter("returnLocation"));
181:                }
182:                if (request.getParameter("conversionFields") != null) {
183:                    lookupForm.setConversionFields(request
184:                            .getParameter("conversionFields"));
185:                }
186:                return mapping.findForward("basic");
187:            }
188:
189:            /**
190:             * search - sets the values of the data entered on the form on the jsp into a map and then searches for the results.
191:             *
192:             * @param mapping -
193:             *            action mapping.
194:             * @param form -
195:             *            LookupForm
196:             * @param request -
197:             *            request.
198:             * @param response -
199:             *            response.
200:             * @return - where to go next.
201:             * @throws Exception
202:             */
203:            public ActionForward search(ActionMapping mapping, ActionForm form,
204:                    HttpServletRequest request, HttpServletResponse response)
205:                    throws Exception {
206:                LookupForm lookupForm = (LookupForm) form;
207:                boolean ascending = true;
208:                String sortOrderParameter = new ParamEncoder("result")
209:                        .encodeParameterName(TableTagParameters.PARAMETER_ORDER);
210:                String sortOrder = request.getParameter(sortOrderParameter);
211:                if (sortOrder == null) {
212:                    sortOrder = "1";
213:                }
214:                if (sortOrder.equals("2")) {
215:                    ascending = false;
216:                }
217:                String sortNameParameter = new ParamEncoder("result")
218:                        .encodeParameterName(TableTagParameters.PARAMETER_SORT);
219:                WorkflowLookupable workflowLookupable = getLookupable(request
220:                        .getParameter("lookupableImplServiceName"));//(WorkflowLookupable) SpringServiceLocator.getExtensionService().getLookupable(request.getParameter("lookupableImplServiceName"));
221:                Map fieldValues = constructFieldValues(workflowLookupable,
222:                        lookupForm, request);
223:                Column sortColumn = getSortColumn(workflowLookupable, request
224:                        .getParameter(sortNameParameter));
225:                List displayList = workflowLookupable.getSearchResults(
226:                        fieldValues, lookupForm.getFieldConversions());
227:                workflowLookupable.changeIdToName(fieldValues);
228:                sortDisplayList(sortColumn, displayList, ascending);
229:                request.setAttribute("workflowLookupable", workflowLookupable);
230:                request.setAttribute("reqSearchResults", displayList);
231:                if (request.getParameter("listKey") != null) {
232:                    getUserSession(request).removeObject(
233:                            request.getParameter("listKey"));
234:                }
235:                request.setAttribute("listKey", getUserSession(request)
236:                        .addObject(displayList));
237:                return mapping.findForward("basic");
238:            }
239:
240:            private Column getSortColumn(WorkflowLookupable lookupable,
241:                    String sortName) {
242:                List columns = lookupable.getColumns();
243:                if (StringUtils.isEmpty(sortName)) {
244:                    return (Column) columns.get(0);
245:                }
246:                for (Iterator iterator = columns.iterator(); iterator.hasNext();) {
247:                    Column column = (Column) iterator.next();
248:                    if (column.getSortName().equals(sortName)) {
249:                        return column;
250:                    }
251:                }
252:                throw new WorkflowRuntimeException(
253:                        "Could not sort based on the given sort name of "
254:                                + sortName);
255:            }
256:
257:            private void sortDisplayList(Column sortColumn, List displayList,
258:                    boolean ascending) {
259:                Collections.sort(displayList, new ColumnComparator(sortColumn,
260:                        ascending));
261:            }
262:
263:            private Map constructFieldValues(
264:                    WorkflowLookupable workflowLookupable,
265:                    LookupForm lookupForm, HttpServletRequest request)
266:                    throws Exception {
267:                Map fieldValues = new HashMap();
268:                for (Iterator iter = workflowLookupable.getRows().iterator(); iter
269:                        .hasNext();) {
270:                    Row row = (Row) iter.next();
271:                    for (Iterator iterator = row.getFields().iterator(); iterator
272:                            .hasNext();) {
273:                        Field field = (Field) iterator.next();
274:                        if (field.getFieldType() != field.getQUICKFINDER()) {
275:                            fieldValues.put(field.getPropertyName(), request
276:                                    .getParameter(field.getPropertyName()));
277:                        }
278:                        if (request.getParameter(field.getPropertyName()) != null) {
279:                            field.setPropertyValue(request.getParameter(field
280:                                    .getPropertyName()));
281:                        }
282:                    }
283:                }
284:                if (workflowLookupable.checkForAdditionalFields(fieldValues,
285:                        request)) {
286:                    for (Iterator iter = workflowLookupable.getRows()
287:                            .iterator(); iter.hasNext();) {
288:                        Row row = (Row) iter.next();
289:                        for (Iterator iterator = row.getFields().iterator(); iterator
290:                                .hasNext();) {
291:                            Field field = (Field) iterator.next();
292:                            if (field.getFieldType() != field.getQUICKFINDER()) {
293:                                fieldValues.put(field.getPropertyName(),
294:                                        request.getParameter(field
295:                                                .getPropertyName()));
296:                            }
297:                            if (request.getParameter(field.getPropertyName()) != null) {
298:                                field.setPropertyValue(request
299:                                        .getParameter(field.getPropertyName()));
300:                            }
301:                        }
302:                    }
303:                }
304:                fieldValues.put("docFormKey", lookupForm.getFormKey());
305:                fieldValues.put("backLocation", lookupForm.getBackLocation());
306:                return fieldValues;
307:            }
308:
309:            public ActionForward export(ActionMapping mapping, ActionForm form,
310:                    HttpServletRequest request, HttpServletResponse response)
311:                    throws Exception {
312:                String listKey = (String) request.getParameter("listKey");
313:                List results = (List) getUserSession(request).retrieveObject(
314:                        listKey);
315:                WorkflowLookupable workflowLookupable = getLookupable(request
316:                        .getParameter("lookupableImplServiceName"));//(WorkflowLookupable) SpringServiceLocator.getExtensionService().getLookupable(request.getParameter("lookupableImplServiceName"));
317:                if (!(workflowLookupable instanceof  Exportable)) {
318:                    throw new WorkflowServiceErrorException(
319:                            "This lookup does not support export.");
320:                }
321:                Exportable exportable = (Exportable) workflowLookupable;
322:                // for now just hardcode for XML
323:                ExportDataSet dataSet = exportable.export(ExportFormat.XML,
324:                        results);
325:                return exportDataSet(request, dataSet);
326:            }
327:
328:            /**
329:             * refresh - is called when one quickFinder returns to the previous one. Sets all the values and performs the new search.
330:             *
331:             * @param mapping -
332:             *            action mapping.
333:             * @param form -
334:             *            LookupForm
335:             * @param request -
336:             *            request.
337:             * @param response -
338:             *            response.
339:             * @return - where to go next.
340:             * @throws Exception
341:             */
342:            public ActionForward refresh(ActionMapping mapping,
343:                    ActionForm form, HttpServletRequest request,
344:                    HttpServletResponse response) throws Exception {
345:                LookupForm lookupForm = (LookupForm) form;
346:                WorkflowLookupable workflowLookupable = getLookupable(lookupForm
347:                        .getLookupableImplServiceName());//(WorkflowLookupable) SpringServiceLocator.getExtensionService().getLookupable(lookupForm.getLookupableImplServiceName());
348:
349:                Map fieldValues = new HashMap();
350:                Map values = lookupForm.getFields();
351:
352:                //        StringBuffer url = new StringBuffer("Lookup.do?methodToCall=viewResults&lookupableImplServiceName=");
353:                //        url.append(lookupForm.getLookupableImplServiceName()).append("&backLocation=").append(lookupForm.getBackLocation());
354:                //        url.append("&docFormKey=").append(request.getParameter("docFormKey"));
355:                //        url.append("&formKey=").append(lookupForm.getFormKey()).append("&conversionFields=").append(lookupForm.getConversionFields());
356:
357:                for (Iterator iter = workflowLookupable.getRows().iterator(); iter
358:                        .hasNext();) {
359:                    Row row = (Row) iter.next();
360:
361:                    for (Iterator iterator = row.getFields().iterator(); iterator
362:                            .hasNext();) {
363:                        Field field = (Field) iterator.next();
364:
365:                        if (field.getPropertyName() != null
366:                                && !field.getPropertyName().equals("")) {
367:                            if (request.getParameter(field.getPropertyName()) != null) {
368:                                field.setPropertyValue(request
369:                                        .getParameter(field.getPropertyName()));
370:                            } else {
371:                                field.setPropertyValue((String) values
372:                                        .get(field.getPropertyName()));
373:                            }
374:                        }
375:                        fieldValues.put(field.getPropertyName(), field
376:                                .getPropertyValue());
377:                    }
378:                }
379:                fieldValues.put("docFormKey", lookupForm.getFormKey());
380:                fieldValues.put("backLocation", lookupForm.getBackLocation());
381:
382:                if (workflowLookupable.checkForAdditionalFields(fieldValues,
383:                        request)) {
384:                    for (Iterator iter = workflowLookupable.getRows()
385:                            .iterator(); iter.hasNext();) {
386:                        Row row = (Row) iter.next();
387:                        for (Iterator iterator = row.getFields().iterator(); iterator
388:                                .hasNext();) {
389:                            Field field = (Field) iterator.next();
390:                            if (field.getPropertyName() != null
391:                                    && !field.getPropertyName().equals("")) {
392:                                if (request.getParameter(field
393:                                        .getPropertyName()) != null) {
394:                                    field.setPropertyValue(request
395:                                            .getParameter(field
396:                                                    .getPropertyName()));
397:                                    fieldValues.put(field.getPropertyName(),
398:                                            request.getParameter(field
399:                                                    .getPropertyName()));
400:                                } else {
401:                                    if (values.get(field.getPropertyName()) != null) {
402:                                        field.setPropertyValue((String) values
403:                                                .get(field.getPropertyName()));
404:                                    }
405:                                }
406:
407:                            }
408:                        }
409:                    }
410:                }
411:                //        Collection displayList = workflowLookupable.getSearchResults(fieldValues, lookupForm.getFieldConversions());
412:                workflowLookupable.changeIdToName(fieldValues);
413:                //        for (Iterator iter = workflowLookupable.getRows().iterator(); iter.hasNext();) {
414:                //            Row row = (Row) iter.next();
415:                //
416:                //            //for (Iterator iterator = row.getFields().iterator(); iterator.hasNext();) {
417:                //            //    Field field = (Field) iterator.next();
418:                ////                url.append("&").append(field.getPropertyName()).append("=").append(field.getPropertyValue());
419:                //            //}
420:                //        }
421:                request.setAttribute("workflowLookupable", workflowLookupable);
422:                //        request.setAttribute("reqSearchResults", displayList);
423:                //        if (request.getParameter("listKey") != null) {
424:                //            getUserSession(request).removeObject(request.getParameter("listKey"));
425:                //        }
426:                //        String listKey = getUserSession(request).addObject(displayList);
427:                //        url.append("&listKey=").append(listKey);
428:                //        request.setAttribute("listKey", listKey);
429:                return mapping.findForward("basic");
430:                //        return new ActionForward(url.toString(), true);
431:            }
432:
433:            /*
434:             * (non-Javadoc)
435:             *
436:             * @see edu.iu.uis.eden.web.WorkflowAction#establishRequiredState(javax.servlet.http.HttpServletRequest)
437:             */
438:            public ActionMessages establishRequiredState(
439:                    HttpServletRequest request, ActionForm form)
440:                    throws Exception {
441:                LookupForm lookupForm = (LookupForm) form;
442:                String lookupableName = request
443:                        .getParameter("lookupableImplServiceName");
444:                if (lookupableName != null) {
445:                    try {
446:
447:                        WorkflowLookupable workflowLookupable = getLookupable(lookupableName);//SpringServiceLocator.getExtensionService().getLookupable(lookupableName);
448:                        if (workflowLookupable instanceof  Exportable) {
449:                            lookupForm
450:                                    .setSupportedExportFormats(((Exportable) workflowLookupable)
451:                                            .getSupportedExportFormats());
452:                        }
453:                        Map fieldValues = new HashMap();
454:                        for (Iterator iter = workflowLookupable.getRows()
455:                                .iterator(); iter.hasNext();) {
456:                            Row row = (Row) iter.next();
457:
458:                            for (Iterator iterator = row.getFields().iterator(); iterator
459:                                    .hasNext();) {
460:                                Field field = (Field) iterator.next();
461:                                if (request.getParameter(field
462:                                        .getPropertyName()) != null) {
463:                                    field.setPropertyValue(request
464:                                            .getParameter(field
465:                                                    .getPropertyName()));
466:                                }
467:                                fieldValues.put(field.getPropertyName(), field
468:                                        .getPropertyValue());
469:                            }
470:                        }
471:                        if (workflowLookupable.checkForAdditionalFields(
472:                                fieldValues, request)) {
473:                            for (Iterator iter = workflowLookupable.getRows()
474:                                    .iterator(); iter.hasNext();) {
475:                                Row row = (Row) iter.next();
476:
477:                                for (Iterator iterator = row.getFields()
478:                                        .iterator(); iterator.hasNext();) {
479:                                    Field field = (Field) iterator.next();
480:                                    if (request.getParameter(field
481:                                            .getPropertyName()) != null) {
482:                                        field.setPropertyValue(request
483:                                                .getParameter(field
484:                                                        .getPropertyName()));
485:                                    }
486:                                }
487:                            }
488:                        }
489:                        Map fieldConversions = new HashMap();
490:                        if (!Utilities
491:                                .isEmpty(lookupForm.getConversionFields())) {
492:                            if (lookupForm.getConversionFields().indexOf(",") > 0) {
493:                                StringTokenizer token = new StringTokenizer(
494:                                        lookupForm.getConversionFields(), ",");
495:                                while (token.hasMoreTokens()) {
496:                                    String element = token.nextToken();
497:                                    fieldConversions.put(element.substring(0,
498:                                            element.indexOf(":")),
499:                                            element.substring(element
500:                                                    .indexOf(":") + 1));
501:                                }
502:                            } else {
503:                                fieldConversions
504:                                        .put(
505:                                                lookupForm
506:                                                        .getConversionFields()
507:                                                        .substring(
508:                                                                0,
509:                                                                lookupForm
510:                                                                        .getConversionFields()
511:                                                                        .indexOf(
512:                                                                                ":")),
513:                                                lookupForm
514:                                                        .getConversionFields()
515:                                                        .substring(
516:                                                                lookupForm
517:                                                                        .getConversionFields()
518:                                                                        .indexOf(
519:                                                                                ":") + 1));
520:                            }
521:                        }
522:                        lookupForm.setNoReturnParams(workflowLookupable
523:                                .getNoReturnParams(fieldConversions));
524:                        lookupForm.setFieldConversions(fieldConversions);
525:
526:                        request.setAttribute("workflowLookupable",
527:                                workflowLookupable);
528:                    } catch (Exception e) {
529:                        LOG.error("error in establishRequiredState", e);
530:                    }
531:                }
532:                return null;
533:            }
534:
535:            /**
536:             * clearValues - clears the values of all the fields on the jsp.
537:             *
538:             * @param mapping -
539:             *            action mapping.
540:             * @param form -
541:             *            LookupForm
542:             * @param request -
543:             *            request.
544:             * @param response -
545:             *            response.
546:             * @return - where to go next.
547:             * @throws Exception
548:             */
549:            public ActionForward clearValues(ActionMapping mapping,
550:                    ActionForm form, HttpServletRequest request,
551:                    HttpServletResponse response) throws IOException,
552:                    ServletException {
553:                LookupForm lookupForm = (LookupForm) form;
554:                try {
555:                    WorkflowLookupable workflowLookupable = getLookupable(lookupForm
556:                            .getLookupableImplServiceName());//(WorkflowLookupable) SpringServiceLocator.getExtensionService().getLookupable(lookupForm.getLookupableImplServiceName());
557:                    for (Iterator iter = workflowLookupable.getRows()
558:                            .iterator(); iter.hasNext();) {
559:                        Row row = (Row) iter.next();
560:                        for (Iterator iterator = row.getFields().iterator(); iterator
561:                                .hasNext();) {
562:                            Field field = (Field) iterator.next();
563:                            if (!field.getFieldType().equals(Field.RADIO)) {
564:                                field.setPropertyValue("");
565:                            }
566:                        }
567:                    }
568:                    request.setAttribute("workflowLookupable",
569:                            workflowLookupable);
570:                } catch (Exception e) {
571:                    LOG.error("error clearing values", e);
572:                }
573:                return mapping.findForward("basic");
574:            }
575:
576:            /**
577:             * viewResults - gets the results out from the search out of the session for sorting and paging on the jsp.
578:             *
579:             * @param mapping -
580:             *            action mapping.
581:             * @param form -
582:             *            LookupForm
583:             * @param request -
584:             *            request.
585:             * @param response -
586:             *            response.
587:             * @return - where to go next.
588:             * @throws Exception
589:             */
590:            public ActionForward viewResults(ActionMapping mapping,
591:                    ActionForm form, HttpServletRequest request,
592:                    HttpServletResponse response) throws IOException,
593:                    ServletException {
594:                request
595:                        .setAttribute("listKey", request
596:                                .getParameter("listKey"));
597:                request.setAttribute("reqSearchResults",
598:                        getUserSession(request).retrieveObject(
599:                                request.getParameter("listKey")));
600:                return mapping.findForward("basic");
601:            }
602:
603:            /*
604:             * (non-Javadoc)
605:             *
606:             * @see edu.iu.uis.eden.web.WorkflowAction#start(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
607:             */
608:            public ActionForward start(ActionMapping mapping, ActionForm form,
609:                    HttpServletRequest request, HttpServletResponse response)
610:                    throws Exception {
611:                LookupForm lookupForm = (LookupForm) form;
612:                if (request.getParameter("lookupableImplServiceName") != null) {
613:                    lookupForm.setLookupableImplServiceName(request
614:                            .getParameter("lookupableImplServiceName"));
615:                }
616:
617:                if (request.getAttribute("docFormKey") != null) {
618:                    lookupForm.setFormKey((String) request
619:                            .getAttribute("docFormKey"));
620:                } else if (request.getParameter("docFormKey") != null) {
621:                    lookupForm.setFormKey((String) request
622:                            .getParameter("docFormKey"));
623:                }
624:
625:                if (request.getParameter("returnLocation") != null) {
626:                    lookupForm.setBackLocation(request
627:                            .getParameter("returnLocation"));
628:                }
629:                if (request.getParameter("conversionFields") != null) {
630:                    lookupForm.setConversionFields(request
631:                            .getParameter("conversionFields"));
632:                }
633:
634:                return mapping.findForward("basic");
635:            }
636:
637:            private static WorkflowLookupable getLookupable(String serviceName) {
638:                return (WorkflowLookupable) GlobalResourceLoader
639:                        .getService(serviceName);
640:            }
641:
642:            private class ColumnComparator implements  Comparator<Object> {
643:
644:                private Column column;
645:                private boolean ascending;
646:
647:                public ColumnComparator(Column column, boolean ascending) {
648:                    this .column = column;
649:                    this .ascending = ascending;
650:                }
651:
652:                public int compare(Object row1, Object row2) {
653:                    try {
654:                        Object property1 = BeanUtils.getProperty(row1, column
655:                                .getSortName());
656:                        Object property2 = BeanUtils.getProperty(row2, column
657:                                .getSortName());
658:                        String property1Value = (property1 == null ? ""
659:                                : property1.toString());
660:                        String property2Value = (property2 == null ? ""
661:                                : property2.toString());
662:                        int compare = 0;
663:                        if (Column.INTEGER.equals(column.getType())) {
664:                            Integer i1 = (StringUtils.isEmpty(property1Value) ? new Integer(
665:                                    0)
666:                                    : Integer.valueOf(property1Value));
667:                            Integer i2 = (StringUtils.isEmpty(property2Value) ? new Integer(
668:                                    0)
669:                                    : Integer.valueOf(property2Value));
670:                            compare = i1.compareTo(i2);
671:                        } else {
672:                            compare = property1Value.compareTo(property2Value);
673:                        }
674:                        if (!ascending) {
675:                            compare *= -1;
676:                        }
677:                        return compare;
678:                    } catch (Exception e) {
679:                        throw new WorkflowRuntimeException(e);
680:                    }
681:                }
682:
683:            }
684:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.