Author: abelevich
Date: 2007-07-19 15:38:37 -0400 (Thu, 19 Jul 2007)
New Revision: 1711
Added:
trunk/sandbox/ui/message/src/main/resources/org/
trunk/sandbox/ui/message/src/main/resources/org/richfaces/
trunk/sandbox/ui/message/src/main/resources/org/richfaces/renderkit/
trunk/sandbox/ui/message/src/main/resources/org/richfaces/renderkit/html/
trunk/sandbox/ui/message/src/main/resources/org/richfaces/renderkit/html/css/
trunk/sandbox/ui/message/src/main/resources/org/richfaces/renderkit/html/css/msg.css
Modified:
trunk/sandbox/ui/message/src/main/config/component/message.xml
trunk/sandbox/ui/message/src/main/java/org/richfaces/renderkit/html/RichMessageBaseRenderer.java
trunk/sandbox/ui/message/src/main/templates/org/richfaces/message.jspx
Log:
first impl of message component
Modified: trunk/sandbox/ui/message/src/main/config/component/message.xml
===================================================================
--- trunk/sandbox/ui/message/src/main/config/component/message.xml 2007-07-19 19:37:26 UTC
(rev 1710)
+++ trunk/sandbox/ui/message/src/main/config/component/message.xml 2007-07-19 19:38:37 UTC
(rev 1711)
@@ -39,6 +39,7 @@
<property attachedstate="true">
<name>passedLabel</name>
<classname>java.lang.String</classname>
+ <defaultvalue>"passed"</defaultvalue>
<description>
Attribute should define the label to be displayed when no message appears
</description>
@@ -81,7 +82,7 @@
<property>
<name>tooltip</name>
- <classname>java.lang.String</classname>
+ <classname>boolean</classname>
</property>
<property>
@@ -103,8 +104,12 @@
<name>styleClass</name>
<classname>java.lang.String</classname>
</property>
-
+
<property>
+ <name>style</name>
+ <classname>java.lang.String</classname>
+ </property>
+ <property>
<name>warnClass</name>
<classname>java.lang.String</classname>
</property>
Modified:
trunk/sandbox/ui/message/src/main/java/org/richfaces/renderkit/html/RichMessageBaseRenderer.java
===================================================================
---
trunk/sandbox/ui/message/src/main/java/org/richfaces/renderkit/html/RichMessageBaseRenderer.java 2007-07-19
19:37:26 UTC (rev 1710)
+++
trunk/sandbox/ui/message/src/main/java/org/richfaces/renderkit/html/RichMessageBaseRenderer.java 2007-07-19
19:38:37 UTC (rev 1711)
@@ -10,9 +10,14 @@
import javax.faces.component.NamingContainer;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.renderkit.ComponentVariables;
+import org.ajax4jsf.renderkit.ComponentsVariableResolver;
+import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
import org.ajax4jsf.renderkit.RendererBase;
+import org.ajax4jsf.renderkit.RendererUtils.HTML;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.richfaces.component.UIRichMessage;
@@ -22,17 +27,18 @@
* @author Anton Belevich
*
*/
-public class RichMessageBaseRenderer extends RendererBase{
+public class RichMessageBaseRenderer extends HeaderResourcesRendererBase{
private static final Log log = LogFactory.getLog(RichMessageBaseRenderer.class);
public static final String NULL_PARAMETER_ERROR_MESSAGE = "null parameter
ERROR";
- public static final String COMPONENT_NOT_FOUND_IN_VIEW = "component not found in
view";
+ public static final String COMPONENT_NOT_FOUND_IN_VIEW_WARN_MESSAGE = "component
not found in the view WARNING";
+ private RendererBase messageTemplate = null;
- public void encodeEnd(FacesContext context, UIComponent component)
- throws IOException {
+
+ public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
Iterator msgIter = null;
@@ -40,14 +46,14 @@
throw new NullPointerException(NULL_PARAMETER_ERROR_MESSAGE);
}
- if (log.isTraceEnabled()) {
- log.trace("begin encoding component " + component.getId());
+ if(log.isTraceEnabled()){
+ log.trace("begin encoding component: " + component.getId());
}
- if (!component.isRendered()) {
- if (log.isTraceEnabled()) {
+ if (!component.isRendered()){
+ if(log.isTraceEnabled()){
log.trace("stop encoding component: "
- + component.getId() + " rendered attribute is set to
false");
+ + component.getId() + " 'rendered' attribute is set to
false");
}
return;
}
@@ -63,15 +69,14 @@
}
msgIter = getMessageIterator(context, forClientId, msgComponent);
-
if(!msgIter.hasNext()){
return;
}
FacesMessage message = (FacesMessage)msgIter.next();
- //TODO rendering here
-
+ encodingUIContent(msgComponent, context, message);
+
AjaxContext ajaxContext = AjaxContext.getCurrentInstance(context);
Set ajaxRenderedAreas = ajaxContext.getAjaxRenderedAreas();
@@ -80,6 +85,157 @@
}
}
+ protected void encodingUIContent(UIRichMessage uiMsg, FacesContext context, FacesMessage
facesMsg) throws IOException{
+
+ boolean showSummary = uiMsg.isShowSummary();
+
+ boolean showDetail = uiMsg.isShowDetail();
+
+ Object tooltip = uiMsg.getAttributes().get("tooltip");
+ boolean isTooltip = false;
+
+ if(tooltip instanceof Boolean){
+ isTooltip = ((Boolean)tooltip).booleanValue();
+ }
+
+ String divClass = null;
+ String divStyle = null;
+
+ String markerClass = null;
+ String markerStyle = null;
+
+ String labelClass = null;
+ String labelStyle = null;
+
+ UIComponent markerFacet = null;
+
+
+ if(facesMsg.getSeverity() == FacesMessage.SEVERITY_ERROR){
+
+ divClass = (String)uiMsg.getAttributes().get("errorClass");
+ divStyle = (String)uiMsg.getAttributes().get("errorStyle");
+
+ markerClass = (String)uiMsg.getAttributes().get("errorMarkerClass");
+ markerStyle = (String)uiMsg.getAttributes().get("errorMarkerStyle");
+
+ labelClass = (String)uiMsg.getAttributes().get("errorLabelClass");
+ labelStyle = (String)uiMsg.getAttributes().get("errorLabelStyle");
+
+ markerFacet = uiMsg.getFacet("errorMarker");
+
+ }else if(facesMsg.getSeverity() == FacesMessage.SEVERITY_FATAL){
+
+ divClass = (String)uiMsg.getAttributes().get("fatalClass");
+ divStyle = (String)uiMsg.getAttributes().get("fatalStyle");
+
+ markerClass = (String)uiMsg.getAttributes().get("fatalMarkerClass");
+ markerStyle = (String)uiMsg.getAttributes().get("fatalMarkerStyle");
+
+ labelClass = (String)uiMsg.getAttributes().get("fatalLabelClass");
+ labelStyle = (String)uiMsg.getAttributes().get("fatalLabelStyle");
+
+ markerFacet = uiMsg.getFacet("fatalMarker");
+
+ }else if(facesMsg.getSeverity() == FacesMessage.SEVERITY_WARN){
+
+ divClass = (String)uiMsg.getAttributes().get("warnClass");
+ divStyle = (String)uiMsg.getAttributes().get("warnStyle");
+
+ markerClass = (String)uiMsg.getAttributes().get("warnMarkerClass");
+ markerStyle = (String)uiMsg.getAttributes().get("warnMarkerStyle");
+
+ labelClass = (String)uiMsg.getAttributes().get("warnLabelClass");
+ labelStyle = (String)uiMsg.getAttributes().get("warnLabelStyle");
+
+ markerFacet = uiMsg.getFacet("warnMarker");
+
+ }else if(facesMsg.getSeverity() == FacesMessage.SEVERITY_INFO){
+
+ divClass = (String)uiMsg.getAttributes().get("infoClass");
+ divStyle = (String)uiMsg.getAttributes().get("infoStyle");
+
+ markerClass = (String)uiMsg.getAttributes().get("infoMarkerClass");
+ markerStyle = (String)uiMsg.getAttributes().get("infoMarkerStyle");
+
+ labelClass = (String)uiMsg.getAttributes().get("infoLabelClass");
+ labelStyle = (String)uiMsg.getAttributes().get("infoLabelStyle");
+
+ markerFacet = uiMsg.getFacet("infoMarker");
+ }
+
+ String markerLocation = uiMsg.getMarkerLocation();
+ markerLocation = markerLocation.toLowerCase();
+
+ ResponseWriter writer = context.getResponseWriter();
+
+ messageTemplate = getMessageTemplate();
+
+ ComponentVariables variables = ComponentsVariableResolver.getVariables(messageTemplate,
uiMsg);
+ variables.setVariable("divClass", divClass);
+ variables.setVariable("divStyle", divStyle);
+
+
+
+ if(markerLocation.equals(uiMsg.MARKER_LOCATION_LEFT)){
+ renderMarkerFacet(uiMsg,markerFacet,context, writer, markerClass, markerStyle);
+ renderLabel(uiMsg, facesMsg, context, writer, labelClass,
+ labelStyle, isTooltip, showDetail,showSummary);
+ }else if(markerLocation.equals(uiMsg.MARKER_LOCATION_RIGHT)){
+ renderLabel(uiMsg, facesMsg, context, writer, labelClass,
+ labelStyle, isTooltip, showDetail, showSummary);
+ renderMarkerFacet(uiMsg,markerFacet,context, writer, markerClass, markerStyle);
+ }
+
+ doEncodeEnd(writer, context, uiMsg);
+ }
+
+ protected void renderMarkerFacet(UIRichMessage uiMsg, UIComponent marker, FacesContext
context, ResponseWriter writer, String markerClass, String markerStyle) throws
IOException{
+
+ if(marker == null){
+ return;
+ }
+
+ writer.startElement(HTML.SPAN_ELEM, uiMsg);
+
+ String classes = markerClass == null ? "rich-message-marker" :
"rich-message-marker " + markerClass;
+
+ getUtils().writeAttribute(writer, HTML.class_ATTRIBUTE, classes);
+ getUtils().writeAttribute(writer, HTML.style_ATTRIBUTE, markerStyle);
+ renderChild(context, marker);
+ writer.endElement(HTML.SPAN_ELEM);
+
+ }
+
+ protected void renderLabel(UIRichMessage uiMsg, FacesMessage msg, FacesContext context,
+ ResponseWriter writer, String labelClass, String labelStyle,
+ boolean isTooltip, boolean showDetail, boolean showSummary) throws
IOException{
+
+ String summary = (null != (summary = msg.getSummary())) ? summary : "";
+ String detail = (null != (detail = msg.getDetail())) ? detail : "";
+
+ String classes = labelClass == null ? "rich-message-label" :
"rich-message-label " + labelClass;
+
+ writer.startElement(HTML.SPAN_ELEM, uiMsg);
+ getUtils().writeAttribute(writer, HTML.class_ATTRIBUTE,classes);
+ getUtils().writeAttribute(writer, HTML.style_ATTRIBUTE, labelStyle);
+
+ if(isTooltip){
+ getUtils().writeAttribute(writer, HTML.title_ATTRIBUTE, summary);
+ }
+
+ if(showDetail){
+ writer.writeText(detail, null);
+ writer.writeText("\t", null);
+ }
+
+ if(showSummary){
+ writer.writeText(summary, null);
+ writer.writeText("\t", null);
+ }
+
+ writer.endElement(HTML.SPAN_ELEM);
+ }
+
protected Iterator getMessageIterator(FacesContext context, String forClientId,
UIComponent component){
Iterator msgIter = null;
@@ -90,7 +246,6 @@
msgIter = context.getMessages(null);
}else{
UIComponent result = findForComponent(context, forClientId,component);
-
if (result == null) {
msgIter = Collections.EMPTY_LIST.iterator();
} else {
@@ -104,17 +259,17 @@
return msgIter;
}
- protected UIComponent findForComponent(FacesContext context, String forClientId,
UIComponent component) {
+ protected UIComponent findForComponent(FacesContext context, String forClientId,
UIComponent component){
- if(null == forClientId || forClientId.length() == 0) {
+ if(null == forClientId || forClientId.length() == 0){
return null;
}
UIComponent result = null;
UIComponent parent = component;
- try {
- while(parent != null) {
+ try{
+ while(parent != null){
result = parent.findComponent(forClientId);
if(result != null){
@@ -123,17 +278,17 @@
parent = parent.getParent();
}
- if(result == null) {
+ if(result == null){
result = findComponentBelow(context.getViewRoot(), forClientId);
}
- } catch(Throwable t) {
- throw new RuntimeException(COMPONENT_NOT_FOUND_IN_VIEW + ":"+
forClientId);
+ } catch(Throwable t){
+ throw new RuntimeException(COMPONENT_NOT_FOUND_IN_VIEW_WARN_MESSAGE + ":"+
forClientId);
}
- if(result == null) {
- if(log.isWarnEnabled()) {
- log.warn(COMPONENT_NOT_FOUND_IN_VIEW + ":"+ forClientId);
+ if(result == null){
+ if(log.isWarnEnabled()){
+ log.warn(COMPONENT_NOT_FOUND_IN_VIEW_WARN_MESSAGE + ":"+ forClientId);
}
}
@@ -165,7 +320,26 @@
return retComp;
};
- protected Class getComponentClass() {
+ private RendererBase getMessageTemplate(){
+
+ if (messageTemplate == null) {
+ try {
+
+ messageTemplate =
(RendererBase)Class.forName("org.richfaces.renderkit.html.RichMessageRenderer").newInstance();
+
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+
+ return messageTemplate;
+ }
+
+ protected Class getComponentClass(){
return getClass();
}
}
Added:
trunk/sandbox/ui/message/src/main/resources/org/richfaces/renderkit/html/css/msg.css
===================================================================
--- trunk/sandbox/ui/message/src/main/resources/org/richfaces/renderkit/html/css/msg.css
(rev 0)
+++
trunk/sandbox/ui/message/src/main/resources/org/richfaces/renderkit/html/css/msg.css 2007-07-19
19:38:37 UTC (rev 1711)
@@ -0,0 +1,18 @@
+.rich-message-marker{
+ background-image : url(1.GIF);
+ background-repeat: no-repeat;
+ background-position: left center;
+}
+
+.rich-message{
+
+}
+
+.rich-message-label{
+
+
+}
+
+.dr-msg-img{
+ vertical-align: text-bottom;
+}
\ No newline at end of file
Modified: trunk/sandbox/ui/message/src/main/templates/org/richfaces/message.jspx
===================================================================
--- trunk/sandbox/ui/message/src/main/templates/org/richfaces/message.jspx 2007-07-19
19:37:26 UTC (rev 1710)
+++ trunk/sandbox/ui/message/src/main/templates/org/richfaces/message.jspx 2007-07-19
19:38:37 UTC (rev 1711)
@@ -10,13 +10,17 @@
class="org.richfaces.renderkit.html.RichMessageRenderer"
baseclass="org.richfaces.renderkit.html.RichMessageBaseRenderer"
component="org.richfaces.component.UIRichMessage"
- >
- <f:clientId var="clientId" />
+ >
+ <h:styles>
+ /org/richfaces/renderkit/html/css/msg.css
+ </h:styles>
+
+ <f:clientId var="clientId" />
- <div id="#{clientId}:m">
- <span>
- <vcp:body/>
- </span>
- </div>
+ <div id="#{clientId}" class="rich-message #{divClass}"
style="#{component.attributes['style']} #{divStyle}">
+ <span class="dr-msg-img">
+ <vcp:body/>
+ </span>
+ </div>
</f:root>
\ No newline at end of file