1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.myfaces.custom.ppr;
20
21 import java.util.ArrayList;
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.Map;
25
26 import javax.faces.component.UIComponent;
27 import javax.faces.component.UIComponentBase;
28 import javax.faces.context.FacesContext;
29 import javax.faces.event.FacesEvent;
30
31 import org.apache.commons.lang.StringUtils;
32
33 /**
34 * PPRSubmitTag can be attached to command components, enabling PPR-request inside UIData components
35 *
36 * @JSFComponent
37 * name = "s:pprSubmit"
38 * class = "org.apache.myfaces.custom.ppr.PPRSubmit"
39 * tagClass = "org.apache.myfaces.custom.ppr.PPRSubmitTag"
40 *
41 * @author Thomas Spiegl
42 */
43 public abstract class AbstractPPRSubmit extends UIComponentBase
44 {
45 public static final String COMPONENT_TYPE = "org.apache.myfaces.PPRSubmit";
46
47 public static final String COMPONENT_FAMILY = "org.apache.myfaces.PPRSubmit";
48
49 public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.PPRSubmit";
50
51 /**
52 * comma separated List of component ids to process. As usual the whole form will be transmitted and
53 * rerendered, but only for the components configured validation and update-model will happen.
54 *
55 * @JSFProperty
56 */
57 public abstract String getProcessComponentIds();
58
59 /**
60 * intercept the event placed by any child component
61 * <br />
62 * if such an event happens PPRSubmit will gather all components and store their client-ids in
63 * a request scoped list for further processing by the {@link PPRViewRootWrapper}
64 */
65 public void queueEvent(FacesEvent event)
66 {
67 super.queueEvent(event);
68
69 FacesContext context = FacesContext.getCurrentInstance();
70
71 String processComponentIdsString = getProcessComponentIds();
72 if (!StringUtils.isEmpty(processComponentIdsString))
73 {
74 Map requestMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
75 List allProcessComponents = (List) requestMap.get(PPRSupport.PROCESS_COMPONENTS);
76
77 List processComponents = PPRSupport.getComponentsByCommaSeparatedIdList(
78 context,
79 this,
80 processComponentIdsString,
81 null
82 );
83
84 Iterator iterComponents = processComponents.iterator();
85 while (iterComponents.hasNext())
86 {
87 UIComponent component = (UIComponent) iterComponents.next();
88 String clientId = component.getClientId(context);
89
90 if (allProcessComponents == null)
91 {
92 allProcessComponents = new ArrayList();
93 requestMap.put(PPRSupport.PROCESS_COMPONENTS, allProcessComponents);
94 }
95
96 allProcessComponents.add(clientId);
97 }
98 }
99 }
100 }