001: /*
002: * Created on 6-okt-2006
003: *
004: * @author <a href="mailto:rudi.alberda@knowlogy.nl">Rudi Alberda, Knowlogy</a>
005: */
006: package nl.knowlogy.validation.jsf.renderkit;
007:
008: import java.io.IOException;
009: import java.util.Iterator;
010: import java.util.List;
011:
012: import javax.faces.component.UIComponent;
013: import javax.faces.context.FacesContext;
014: import javax.faces.context.ResponseWriter;
015:
016: /**
017: *
018: *
019: * @author <a href="mailto:rudi.alberda@knowlogy.nl">Rudi Alberda, Knowlogy</a>
020: */
021: public class FieldMessageRendererExclamation extends
022: FieldMessageRenderer {
023:
024: public void writeContent(FacesContext context,
025: UIComponent component, List errorList, boolean hasErrors)
026: throws IOException {
027:
028: ResponseWriter writer = context.getResponseWriter();
029: String errorId = component.getClientId(context) + "ErrorDiv";
030: String src;
031: if (hasErrors) {
032: src = (context.getExternalContext()
033: .encodeResourceURL(context.getApplication()
034: .getViewHandler().getResourceURL(context,
035: "/images/errorbutton.gif")));
036: } else {
037: src = (context.getExternalContext()
038: .encodeResourceURL(context.getApplication()
039: .getViewHandler().getResourceURL(context,
040: "/images/warningbutton.jpg")));
041: }
042:
043: StringBuffer errorMessages = new StringBuffer();
044: for (Iterator iter = errorList.iterator(); iter.hasNext();) {
045: String error = (String) iter.next();
046: errorMessages.append(error).append(
047: iter.hasNext() ? "<br/>" : "");
048: }
049: String errorMessage = errorMessages.toString();
050:
051: //String eindeFunctie = "remove" + errorId + "()";
052:
053: writer.startElement("img", component);
054:
055: writer.writeAttribute("id", "message_id_" + errorId, "id");
056: writer.writeAttribute("src", src, "value");
057: String onMouseOverScript = "javascript:newPopup = document.createElement(\"div\");"
058: + "newPopup.setAttribute(\"id\",\""
059: + errorId
060: + "\");"
061: +
062:
063: "newPopup.style.width=\"275\";"
064: +
065:
066: "if (document.all) {"
067: + " y = event.clientY + document.body.scrollTop - 8;"
068: + " x = event.clientX + document.body.scrollLeft + 8;"
069: + "} else {"
070: + " y = e.pageY - 8;"
071: + " x = e.pageX + 8;"
072: + "}"
073: + "if (x > document.body.offsetWidth - 290 ) { x = x - 290 }"
074: + "newPopup.style.top = y + \"px\";"
075: + "newPopup.style.left = x + \"px\";";
076:
077: if (hasErrors) {
078: onMouseOverScript += "newPopup.style.border=\"1px solid red\";"
079: + "newPopup.style.backgroundColor=\"#ffcccc\";"
080: + "newPopup.style.position=\"absolute\";"
081: // "newMutatie.style.z-index = \"20\";"+
082: + "newPopup.innerHTML=\"<span class=\'message\'>"
083: + errorMessage + "</span>\";";
084:
085: } else {
086: onMouseOverScript += "newPopup.style.border=\"1px solid blue\";"
087: + "newPopup.style.backgroundColor=\"#a9a9ff\";"
088: + "newPopup.style.position=\"absolute\";"
089: // "newMutatie.style.z-index = \"20\";"+
090: + "newPopup.innerHTML=\"<span class=\'messageWarning\'>"
091: + errorMessage + "</span>\";";
092:
093: }
094:
095: onMouseOverScript += "myDocumentElements=document.getElementsByTagName(\"body\");"
096: + "myBody=myDocumentElements.item(0);"
097: + "myBody.appendChild(newPopup); ";
098:
099: String onMouseOutScript = "javascript:"
100: + "myDocumentElements=document.getElementsByTagName(\"body\");"
101: + "popup = document.getElementById(\"" + errorId
102: + "\");"
103: + "if (popup != null) {myBody.removeChild(popup);}";
104:
105: writer.writeAttribute("onmouseover", onMouseOverScript,
106: "onmouseover");
107: writer.writeAttribute("onmouseout", onMouseOutScript,
108: "onmouseout");
109: writer.endElement("img");
110: }
111: }
|