01: /**********************************************************************************
02: * $URL: https://source.sakaiproject.org/svn/sections/tags/sakai_2-4-1/sections-app/src/java/org/sakaiproject/tool/section/jsf/DivMessageRenderer.java $
03: * $Id: DivMessageRenderer.java 9245 2006-05-10 17:48:20Z jholtzman@berkeley.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Regents of the University of California and The Regents of the University of Michigan
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.sakaiproject.tool.section.jsf;
21:
22: import java.io.IOException;
23: import java.util.Iterator;
24:
25: import javax.faces.application.FacesMessage;
26: import javax.faces.component.UIComponent;
27: import javax.faces.component.UIMessage;
28: import javax.faces.context.FacesContext;
29:
30: import org.apache.commons.logging.Log;
31: import org.apache.commons.logging.LogFactory;
32:
33: /**
34: * Put the message in a "div" instead of a "span", allowing for much more
35: * positioning control.
36: */
37:
38: public class DivMessageRenderer extends DivMessageRendererBase {
39: private static final Log logger = LogFactory
40: .getLog(DivMessageRenderer.class);
41:
42: public void encodeEnd(FacesContext context, UIComponent component)
43: throws IOException {
44: // Note our complete disregard for class cast and null exceptions....
45: UIMessage uiMessage = (UIMessage) component;
46: String clientId = uiMessage.findComponent(uiMessage.getFor())
47: .getClientId(context);
48:
49: Iterator iter = context.getMessages(clientId);
50: if (iter.hasNext()) {
51: // Just do the first one.
52: FacesMessage message = (FacesMessage) iter.next();
53: renderMessage(context, component, message);
54: }
55: }
56: }
|