You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2007/07/30 19:16:11 UTC

svn commit: r561048 - in /myfaces/tomahawk/trunk/sandbox: core/src/main/java/org/apache/myfaces/custom/passwordStrength/ core/src/main/resources/org/apache/myfaces/custom/passwordStrength/resource/ core/src/main/tld/ examples/src/main/webapp/

Author: mmarinschek
Date: Mon Jul 30 10:16:10 2007
New Revision: 561048

URL: http://svn.apache.org/viewvc?view=rev&rev=561048
Log:
Additional patch for: https://issues.apache.org/jira/browse/TOMAHAWK-1042. Thanks to Hazem Saleh.

Modified:
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/passwordStrength/PasswordStrengthComponent.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/passwordStrength/PasswordStrengthRenderer.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/passwordStrength/PasswordStrengthTag.java
    myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/passwordStrength/resource/passwordStrength.js
    myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
    myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/passwordStrength.jsp

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/passwordStrength/PasswordStrengthComponent.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/passwordStrength/PasswordStrengthComponent.java?view=diff&rev=561048&r1=561047&r2=561048
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/passwordStrength/PasswordStrengthComponent.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/passwordStrength/PasswordStrengthComponent.java Mon Jul 30 10:16:10 2007
@@ -32,14 +32,33 @@
 	public static String RENDERER_TYPE = "org.apache.myfaces.PasswordStrength";
 
 	private String _preferredPasswordLength;
-
 	private String _textStrengthDescriptions;
-
 	private String _prefixText;
+	private String _showDetails;
+	private String _strengthIndicatorType;	
 
 	public String getFamily() {
 		return "org.apache.myfaces.PasswordStrength";
 	}
+	
+	
+	public String getShowDetails() {
+		if (_showDetails != null)
+			return _showDetails;
+
+		ValueBinding vb = getValueBinding("showDetails");
+		return vb != null ? RendererUtils.getStringValue(getFacesContext(), vb)
+				: null;
+	}
+	
+	public String getStrengthIndicatorType() {
+		if (_strengthIndicatorType != null)
+			return _strengthIndicatorType;
+
+		ValueBinding vb = getValueBinding("strengthIndicatorType");
+		return vb != null ? RendererUtils.getStringValue(getFacesContext(), vb)
+				: null;
+	}		
 
 	public String getPreferredPasswordLength() {
 		if (_preferredPasswordLength != null)
@@ -49,11 +68,7 @@
 		return vb != null ? RendererUtils.getStringValue(getFacesContext(), vb)
 				: null;
 	}
-
-	public void setPreferredPasswordLength(String preferredPasswordLength) {
-		_preferredPasswordLength = preferredPasswordLength;
-	}
-
+	
 	public String getPrefixText() {
 		if (_prefixText != null)
 			return _prefixText;
@@ -62,11 +77,7 @@
 		return vb != null ? RendererUtils.getStringValue(getFacesContext(), vb)
 				: null;
 	}
-
-	public void setPrefixText(String prefixText) {
-		_prefixText = prefixText;
-	}
-
+	
 	public String getTextStrengthDescriptions() {
 		if (_textStrengthDescriptions != null)
 			return _textStrengthDescriptions;
@@ -74,18 +85,37 @@
 		ValueBinding vb = getValueBinding("textStrengthDescriptions");
 		return vb != null ? RendererUtils.getStringValue(getFacesContext(), vb)
 				: null;
+	}	
+
+	public void setPreferredPasswordLength(String preferredPasswordLength) {
+		_preferredPasswordLength = preferredPasswordLength;
+	}
+
+
+	public void setPrefixText(String prefixText) {
+		_prefixText = prefixText;
 	}
 
 	public void setTextStrengthDescriptions(String strengthDescriptions) {
 		_textStrengthDescriptions = strengthDescriptions;
 	}
+	
+	public void setShowDetails(String showDetails) {
+		_showDetails = showDetails;
+	}
+	
+	public void setStrengthIndicatorType(String strengthIndicatorType) {
+		_strengthIndicatorType = strengthIndicatorType;
+	}	
 
 	public Object saveState(FacesContext context) {
-		Object values[] = new Object[4];
+		Object values[] = new Object[6];
 		values[0] = super.saveState(context);
 		values[1] = _preferredPasswordLength;
 		values[2] = _prefixText;
-		values[3] = _textStrengthDescriptions;		
+		values[3] = _textStrengthDescriptions;
+		values[4] = _showDetails;	
+		values[5] = _strengthIndicatorType;			
 		return ((Object) (values));
 	}
 
@@ -94,6 +124,8 @@
 		super.restoreState(context, values[0]);
 		_preferredPasswordLength = (String) values[1];
 		_prefixText = (String) values[2];
-		_textStrengthDescriptions = (String)values[3];
+		_textStrengthDescriptions = (String) values[3];
+		_showDetails =  (String) values[4];
+		_strengthIndicatorType = (String) values[5];
 	}	
 }

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/passwordStrength/PasswordStrengthRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/passwordStrength/PasswordStrengthRenderer.java?view=diff&rev=561048&r1=561047&r2=561048
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/passwordStrength/PasswordStrengthRenderer.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/passwordStrength/PasswordStrengthRenderer.java Mon Jul 30 10:16:10 2007
@@ -29,10 +29,7 @@
 import javax.faces.render.Renderer;
 
 import org.apache.commons.lang.StringUtils;
-import org.apache.myfaces.custom.accordion.HtmlAccordionPanelRenderer;
-import org.apache.myfaces.custom.excelexport.ExcelExport;
-import org.apache.myfaces.custom.inputAjax.HtmlInputTextAjax;
-import org.apache.myfaces.custom.statechangednotifier.StateChangedNotifierRenderer;
+import org.apache.myfaces.custom.dojo.DojoUtils;
 import org.apache.myfaces.renderkit.html.util.AddResource;
 import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
 import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
@@ -43,11 +40,11 @@
 
 public class PasswordStrengthRenderer extends Renderer {
 
-	// This private method is used for including all the related resources ...
-	private void includeResources(FacesContext context, UIComponent component,
+	private void addResources(FacesContext context, UIComponent component,
 			ResponseWriter writer) throws IOException {
-		// Load the resources ...
+		PasswordStrengthComponent passwordStrength = (PasswordStrengthComponent) component;				
 		AddResource addResource = AddResourceFactory.getInstance(context);
+		
 		// Load the css style ...
 		String styleLocation = (String) component.getAttributes().get(
 				JSFAttr.STYLE_LOCATION);
@@ -58,11 +55,11 @@
 			addResource.addStyleSheet(context, AddResource.HEADER_BEGIN,
 					PasswordStrengthRenderer.class, "css/passwordStrength.css");
 		}
+		
 		// Load the JS file ...
 		String javascriptLocation = (String) component.getAttributes().get(
 				JSFAttr.JAVASCRIPT_LOCATION);
 		if (javascriptLocation != null) {
-			// add user defined javascripts
 			addResource.addJavaScriptAtPosition(context,
 					AddResource.HEADER_BEGIN, javascriptLocation
 							+ "/passwordStrength.js");
@@ -71,6 +68,41 @@
 					AddResource.HEADER_BEGIN, PasswordStrengthRenderer.class,
 					"passwordStrength.js");
 		}
+		
+		//Add Dojo stuff for progress bar ...
+		addDojoStuff(context, component);
+		
+		//Add Initialization stuff ...
+		String messageId = getMessageID(context, passwordStrength);
+		writer.write("<script type=\"text/javascript\">");	
+		String addOnStartUP = "dojo.addOnLoad(function() {"
+				+ "startUpPasswordStrength('"
+				+ messageId
+				+ "'); });";
+		writer.write( addOnStartUP );
+		writer.write("</script>");
+	}
+	
+	private String getMessageID(FacesContext context,
+			PasswordStrengthComponent passwordStrength) {
+		String clientID = passwordStrength.getClientId(context);		
+		String messageId = "";
+		if (TextIndicatorType.TEXT
+				.equalsIgnoreCase(getStrengthIndicatorTypeValue(passwordStrength))) {
+			messageId = getIndicatorMessageId(clientID);
+		} else {
+			messageId = getProgressBarContainerID(clientID);
+		}
+		return messageId;
+	}
+	
+	private void addDojoStuff(FacesContext context, UIComponent component)
+			throws IOException {
+		String javascriptLocation = (String) component.getAttributes().get(
+				JSFAttr.JAVASCRIPT_LOCATION);
+		DojoUtils.addMainInclude(context, component, javascriptLocation,
+				DojoUtils.getDjConfigInstance(context));
+		DojoUtils.addRequire(context, component, "dojo.widget.ProgressBar");
 	}
 
 	private void renderStartDiv(UIComponent component, ResponseWriter writer)
@@ -100,6 +132,10 @@
 				"org.apache.myfaces.custom.passwordStrength.DESC", null)
 				.getDetail();
 	}
+	
+	private String getDefaultShowDetails() {
+		return "true";
+	}
 
 	private String getDefaultPrefix() {
 		return MessageUtils.getMessage(BUNDLE_BASE_NAME,
@@ -107,25 +143,26 @@
 				"org.apache.myfaces.custom.passwordStrength.PREFIX", null)
 				.getDetail();
 	}
+	
+	private String getDefaultStrengthIndicatorType() {
+		return TextIndicatorType.TEXT;
+	}	
 
 	private void createTextSpan(PasswordStrengthComponent passwordStrength,
 			FacesContext context, String clientID) throws IOException {
 		ResponseWriter writer = context.getResponseWriter();
 
 		String preferredLength = passwordStrength.getPreferredPasswordLength();
-		String prefixText = passwordStrength.getPrefixText();
-		String textStrengthDescriptions = passwordStrength
-				.getTextStrengthDescriptions();
-		String txtName = "'" + clientID + "'";
-
-		// Set default values for optional attributes ...
-
-		prefixText = (prefixText == null) ? "'" + getDefaultPrefix() + "'"
-				: "'" + prefixText + "'";
-
-		textStrengthDescriptions = (textStrengthDescriptions == null) ? "'"
-				+ getDefaultTextDesc() + "'" : "'" + textStrengthDescriptions
-				+ "'";
+		String prefixText = (passwordStrength.getPrefixText() == null) ? "'" + getDefaultPrefix() + "'"
+				: "'" + passwordStrength.getPrefixText() + "'";
+		String textStrengthDescriptions = (passwordStrength
+				.getTextStrengthDescriptions() == null) ? "'"
+				+ getDefaultTextDesc() + "'" : "'"
+				+ passwordStrength.getTextStrengthDescriptions() + "'";
+		String textID = "'" + clientID + "'";
+		String showDetails = (passwordStrength.getShowDetails() == null) ? "'"
+				+ getDefaultShowDetails() + "'" : "'"
+				+ passwordStrength.getShowDetails() + "'";
 
 		writer.startElement(HTML.SPAN_ELEM, passwordStrength);
 
@@ -141,26 +178,44 @@
 		}
 		writer.writeAttribute("value", value, "value");
 
-		writer.writeAttribute("onkeyup", createOnKeyUpString(txtName,
-				preferredLength, prefixText, textStrengthDescriptions, true),
-				"onkeyup");
-		writer.writeAttribute("onblur", ON_BLUR_STRING, "onblur");
+		writer.writeAttribute("onkeyup", createOnKeyUpString(context,
+				passwordStrength, textID, preferredLength, prefixText,
+				textStrengthDescriptions, true, showDetails), "onkeyup");
+		writer.writeAttribute("onblur", getOnBlurString(context, passwordStrength), "onblur");
 
 		writer.endElement(HTML.INPUT_ELEM);
 
 		writer.endElement(HTML.SPAN_ELEM);
 	}
 
+	
+	private void createTextIndicatorMessage(UIComponent component,
+			FacesContext context, ResponseWriter writer) throws IOException {
+		String clientID = component.getClientId(context);
+		
+		writer.startElement(HTML.SPAN_ELEM, component);
+		writer.writeAttribute(HTML.ID_ATTR, getIndicatorMessageId( clientID ),
+				HTML.ID_ATTR);
+		writer.writeAttribute(HTML.CLASS_ATTR, "indicatorMessage",
+				HTML.CLASS_ATTR);
+		writer.endElement(HTML.SPAN_ELEM);		
+	}
+	
 	private void createIndicatorSpan(UIComponent component,
-			ResponseWriter writer) throws IOException {
+			FacesContext context, ResponseWriter writer) throws IOException {
+		PasswordStrengthComponent passwordStrength = (PasswordStrengthComponent) component;
+	
+		String clientID = passwordStrength.getClientId(context);
+		String strengthIndicatorType = 	getStrengthIndicatorTypeValue(passwordStrength);
+
 		writer.endElement(HTML.TD_ELEM);
 		writer.startElement(HTML.TD_ELEM, component);
 
-		writer.startElement(HTML.SPAN_ELEM, component);
-		writer.writeAttribute(HTML.ID_ATTR, "indicatorMessage", HTML.ID_ATTR);
-		writer.writeAttribute(HTML.CLASS_ATTR, "indicatorMessage",
-				HTML.CLASS_ATTR);
-		writer.endElement(HTML.SPAN_ELEM);
+		if(TextIndicatorType.TEXT.equalsIgnoreCase( strengthIndicatorType )) { //It is a text ...
+			createTextIndicatorMessage(component, context, writer);
+		} else { //It is a progressbar ... 	
+			createProgressBarSpan(component, context, writer);
+		}
 
 		writer.endElement(HTML.TD_ELEM);
 		writer.endElement("TR");
@@ -169,9 +224,41 @@
 		writer.startElement(HTML.TD_ELEM, component);
 
 		writer.startElement("div", component);
-		writer.writeAttribute("id", "leftCharsMessage", "id");
+		writer.writeAttribute("id", getleftCharsMessageId(clientID), "id");
 		writer.endElement("div");
 	}
+	
+	private String getStrengthIndicatorType(
+			PasswordStrengthComponent passwordStrength) {
+		return (passwordStrength.getStrengthIndicatorType() == null) ? "'"
+				+ getDefaultStrengthIndicatorType() + "'" : "'"
+				+ passwordStrength.getStrengthIndicatorType() + "'";
+	}
+
+	private String getStrengthIndicatorTypeValue(
+			PasswordStrengthComponent passwordStrength) {
+		return (passwordStrength.getStrengthIndicatorType() == null) ? getDefaultStrengthIndicatorType()
+				: passwordStrength.getStrengthIndicatorType();
+	}	
+	
+	private void createProgressBarSpan(UIComponent component,
+			FacesContext context, ResponseWriter writer) throws IOException {
+		String clientID = component.getClientId(context);
+
+		writer.startElement(HTML.SPAN_ELEM, component);		
+		writer.writeAttribute("id", getProgressBarContainerID(clientID), "id");	
+		
+		writer.startElement(HTML.SPAN_ELEM, component);
+		writer.writeAttribute("width", DEFAULT_PROGRESSBAR_WIDTH, "width");
+		writer.writeAttribute("height", DEFAULT_PROGRESSBAR_HEIGHT, "height");
+		writer.writeAttribute("progressValue", DEFAULT_PROGRESSBAR_VALUE, "progressValue");				
+		//writer.writeAttribute("hasText", "true", "hasText");
+		writer.writeAttribute("dojoType", "ProgressBar", "dojoType");		
+		writer.writeAttribute("id", getProgressBarID(clientID), "id");		
+		writer.endElement(HTML.SPAN_ELEM);
+		
+		writer.endElement(HTML.SPAN_ELEM);				
+	}
 
 	private void createHTMLComponents(FacesContext facesContext,
 			UIComponent component, ResponseWriter writer, String clientID)
@@ -182,7 +269,7 @@
 
 		createTextSpan(passwordStrength, facesContext, clientID);
 
-		createIndicatorSpan(component, writer);
+		createIndicatorSpan(component, facesContext, writer);
 
 		renderEndDiv(component, writer);
 	}
@@ -202,7 +289,7 @@
 
 		ResponseWriter writer = context.getResponseWriter();
 
-		includeResources(context, component, writer);
+		addResources(context, component, writer);
 
 		createHTMLComponents(context, component, writer, clientID);
 	}
@@ -231,20 +318,75 @@
 		}
 	}
 
-	private String createOnKeyUpString(String txtName, String preferredLength,
+	private String createOnKeyUpString(FacesContext context,
+			UIComponent component, String textID, String preferredLength,
 			String prefix, String textStrengthDescriptions,
-			boolean showMessageIndicator) {
+			boolean showMessageIndicator, String showDetails) {
+		PasswordStrengthComponent passwordStrength = (PasswordStrengthComponent) component;		
+		
+		String clientID = component.getClientId(context);
 		String showMessageIndicatorString = "";
-		if (showMessageIndicator == true)
-			showMessageIndicatorString = "show('indicatorMessage')";
-		return "updateStatusValue( " + txtName + "," + preferredLength + ", "
-				+ prefix + ", " + textStrengthDescriptions + ", " + "'true');"
+		String strengthIndicatorType = getStrengthIndicatorType(passwordStrength);
+		String progressBarId = "'" + getProgressBarID(clientID) + "'";
+		String indicatorMessageID = "'" + getIndicatorMessageId(clientID) + "'";
+		String leftCharsMessageID = "'" + getleftCharsMessageId(clientID) + "'";
+
+		if (showMessageIndicator == true) {
+			showMessageIndicatorString = "show('"
+					+ getMessageID(context, passwordStrength) + "');";
+		}
+		
+		return updateStatusValue(textID, preferredLength, 
+								 prefix, textStrengthDescriptions, 
+								 indicatorMessageID, leftCharsMessageID,
+								 showMessageIndicatorString, 
+								 strengthIndicatorType, progressBarId,
+								 showDetails);
+	}
+	
+	private String updateStatusValue(String textID, String preferredLength,
+									 String prefix, String textStrengthDescriptions,
+									 String indicatorMessageID, String leftCharsMessageID,									 
+									 String showMessageIndicatorString, 
+									 String strengthIndicatorType, String progressBarId, 
+									 String showDetails) {
+		return "updateStatusValue(" 
+				+ textID + "," + preferredLength + ", "
+				+ prefix + ", " + textStrengthDescriptions + ", " 
+				+ indicatorMessageID + ", " + leftCharsMessageID + ", "				
+				+ strengthIndicatorType + ", " + progressBarId + ", " 				
+				+ showDetails + ");"
 				+ showMessageIndicatorString;
 	}
-
-	// The constants ...
-	final String ON_BLUR_STRING = "hide('indicatorMessage');"
-			+ "hide('leftCharsMessage');";
+	
+	private String getIndicatorMessageId(String clientID) {	
+		return clientID + "indicatorMessage";
+	}
+	
+	private String getleftCharsMessageId(String clientID) {	
+		return clientID + "leftCharsMessage";
+	}	
+
+	private String getProgressBarID(String clientID) {	
+		return clientID + PROGRESSBAR_SUFFIX;
+	}
+	
+	private String getProgressBarContainerID(String clientID) {	
+		return getProgressBarID(clientID) + PROGRESSBAR_CONTAINER_SUFFIX;
+	}			
+	
+	private String getOnBlurString(FacesContext context, UIComponent component) {
+		PasswordStrengthComponent passwordStrength = (PasswordStrengthComponent) component;		
+		String clientID = passwordStrength.getClientId(context);		
+		
+		return "hide('" + getMessageID(context, passwordStrength) + "');" + "hide('"
+				+ getleftCharsMessageId(clientID) + "');";
+	}
 
 	final String BUNDLE_BASE_NAME = "org.apache.myfaces.custom.passwordStrength.resource.PasswordStrength";
+	final String DEFAULT_PROGRESSBAR_WIDTH = "150";
+	final String DEFAULT_PROGRESSBAR_HEIGHT = "20";	
+	final String PROGRESSBAR_SUFFIX = "_PROGRESSBAR";
+	final String PROGRESSBAR_CONTAINER_SUFFIX = "_CONTAINER";	
+	final String DEFAULT_PROGRESSBAR_VALUE = "20";
 }

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/passwordStrength/PasswordStrengthTag.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/passwordStrength/PasswordStrengthTag.java?view=diff&rev=561048&r1=561047&r2=561048
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/passwordStrength/PasswordStrengthTag.java (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/passwordStrength/PasswordStrengthTag.java Mon Jul 30 10:16:10 2007
@@ -19,9 +19,6 @@
 package org.apache.myfaces.custom.passwordStrength;
 
 import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.el.ValueBinding;
-import javax.faces.webapp.UIComponentTag;
 
 import org.apache.myfaces.taglib.html.ext.HtmlInputTextTag;
 
@@ -46,20 +43,22 @@
 	 */
 	public void release() {
 		super.release();
-		//_text = null;
 		_preferredPasswordLength = null;
 		_prefixText = null;
 		_textStrengthDescriptions = null;
+		_showDetails = null;
+		_strengthIndicatorType = null;
 	}
 
 	protected void setProperties(UIComponent component) {
 		super.setProperties(component);
-	//	setStringProperty(component, "text", _text);
 		setStringProperty(component, "preferredPasswordLength",
 				_preferredPasswordLength);
 		setStringProperty(component, "textStrengthDescriptions",
 				_textStrengthDescriptions);
 		setStringProperty(component, "prefixText", _prefixText);
+		setStringProperty(component, "showDetails", _showDetails);
+		setStringProperty(component, "strengthIndicatorType", _strengthIndicatorType);			
 	}
 
 	//Getters & Setters ...
@@ -88,8 +87,26 @@
 		_textStrengthDescriptions = strengthDescriptions;
 	}	
 	
+	public String getShowDetails() {
+		return _showDetails;
+	}
+
+	public void setShowDetails(String showDetails) {
+		this._showDetails = showDetails;
+	}
+
+	public String getStrengthIndicatorType() {
+		return _strengthIndicatorType;
+	}
+
+	public void setStrengthIndicatorType(String strengthIndicatorType) {
+		this._strengthIndicatorType = strengthIndicatorType;
+	}	
+	
 	//Attributes ...
 	private String _preferredPasswordLength;
 	private String _textStrengthDescriptions;
 	private String _prefixText;
+	private String _showDetails;
+	private String _strengthIndicatorType;
 }

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/passwordStrength/resource/passwordStrength.js
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/passwordStrength/resource/passwordStrength.js?view=diff&rev=561048&r1=561047&r2=561048
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/passwordStrength/resource/passwordStrength.js (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources/org/apache/myfaces/custom/passwordStrength/resource/passwordStrength.js Mon Jul 30 10:16:10 2007
@@ -8,58 +8,81 @@
    if (document.getElementById){ 
       obj = document.getElementById(id); 
       obj.style.display = ""; 
-   } 
+   }
 }
 
-window.onload=function() {
-	hide('indicatorMessage');
+function startUpPasswordStrength(objID) {
+	hide(objID);
+}
+
+function increaseProgressBar(progressBarID, maxValue, currentValue){
+	dojo.widget.byId(progressBarID).setMaxProgressValue(maxValue, true);
+	dojo.widget.byId(progressBarID).setProgressValue(currentValue, true);
+	dojo.widget.byId(progressBarID).render();
 }
 
 //This method is used for online updating the status of the textbox ...
-function updateStatusValue(txtName, preferredLength, prefixText, passwordDesc, showDetails) {
-    //Define the variables ...
-    var content = document.getElementById(txtName).value;
+function updateStatusValue(textID, preferredLength, 
+						   prefixText, passwordDesc, 
+						   indicatorMessageID, leftCharsMessageID, 
+						   strengthIndicatorType, progressBarId, 
+						   showDetails) {				   
+    //Get the current message content ...
+    var content = document.getElementById(textID).value;
     var currentStatus = prefixText;
-    var diff = 0;
-    //Check the contents ...
-    var tokens = passwordDesc.split(";");
-    var length = tokens.length;
-    //Calc the delta of char changes : diff = preferredLength / tokens;
-    var delta = preferredLength / length;
-    var change = delta;
-    //Segmentize it ...
-    for(i = 0; i < length; ++i) {
-       //Get the correct tokenizer ...
-       if(content.length <= delta) {
-          currentStatus +=  tokens[i];
-          break;
-       } 
-       //If we reached the last character then always display the last value ...
-       if(i == length - 1) {
-          currentStatus +=  tokens[length-1];
-          break;	  
-       }
-       delta = change * (i + 2);
+   	var diff = 0;	     
+   	   	
+    /**
+    * Check whether to display the strength indicator as a text or as bar ...
+    */
+    if(strengthIndicatorType == "text") {
+	    //Check the contents ...   
+	    var tokens = passwordDesc.split(";");
+	    var length = tokens.length;
+	    //Calc the delta of char changes : diff = preferredLength / tokens;
+	    var delta = preferredLength / length;
+	    var change = delta;
+	    //Segmentize it ...
+	    for(i = 0; i < length; ++i) {
+	       //Get the correct tokenizer ...
+	       if(content.length <= delta) {
+	          currentStatus +=  tokens[i];
+	          break;
+	       } 
+	       //If we reached the last character then always display the last value ...
+	       if(i == length - 1) {
+	          currentStatus +=  tokens[length-1];
+	          break;	  
+	       }
+	       delta = change * (i + 2);
+	    }    
+	    if(document.all){ 
+	           document.getElementById(indicatorMessageID).innerText = currentStatus;
+	    } else {
+	           document.getElementById(indicatorMessageID).textContent = currentStatus;
+	    }
+		
     }
-    //Show the result messages ...
-    if(document.all){ 
-           document.getElementById("indicatorMessage").innerText = currentStatus;
-    } else {
-           document.getElementById("indicatorMessage").textContent = currentStatus;
+    else { /*Here we are dealing with bar*/
+		increaseProgressBar(progressBarId, preferredLength, content.length);   	    
     }
+    /**
+    * Here display the left characters message part ...
+    */    
     if(content.length == 0) {
-        hide("leftCharsMessage");           
+        hide(leftCharsMessageID);           
     } else if(showDetails == "true" && content.length < preferredLength) {
-        show("leftCharsMessage");
+        show(leftCharsMessageID);
 	diff = (preferredLength - content.length);
 	var charLeft = diff + " characters are left";
       if(document.all) { 
-             document.getElementById("leftCharsMessage").innerText = charLeft;
+             document.getElementById(leftCharsMessageID).innerText = charLeft;
       } else {
-             document.getElementById("leftCharsMessage").textContent = charLeft;
+             document.getElementById(leftCharsMessageID).textContent = charLeft;
       }
     } else {
-        hide("leftCharsMessage");
-    }
+        hide(leftCharsMessageID);
+    }						   						   
 }
+
 

Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld?view=diff&rev=561048&r1=561047&r2=561048
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld Mon Jul 30 10:16:10 2007
@@ -1697,24 +1697,38 @@
 	&standard_input_text_attributes;
       <attribute> 
          <name>preferredPasswordLength</name>    
-	  <required>true</required>          
-          <rtexprvalue>true</rtexprvalue>
-	  <type>java.lang.String</type>
-	  <description>The prefered length of the password</description>         
+	     <required>true</required>          
+         <rtexprvalue>true</rtexprvalue>
+	     <type>java.lang.String</type>
+	     <description>The prefered length of the password</description>         
       </attribute>
       <attribute> 
          <name>textStrengthDescriptions</name>    
-	  <required>false</required>          
-          <rtexprvalue>true</rtexprvalue>
-	  <type>java.lang.String</type>
-	  <description>The text strength descriptions</description>         
+	     <required>false</required>          
+         <rtexprvalue>true</rtexprvalue>
+	     <type>java.lang.String</type>
+	     <description>The text strength descriptions</description>         
       </attribute>      
       <attribute> 
          <name>prefixText</name>    
-	  <required>false</required>          
-          <rtexprvalue>true</rtexprvalue>
-	  <type>java.lang.String</type>
-	  <description>The prefix of the component message</description>         
-      </attribute>                  
+	  	 <required>false</required>          
+         <rtexprvalue>true</rtexprvalue>
+	     <type>java.lang.String</type>
+	     <description>The prefix of the component message</description>         
+      </attribute>
+      <attribute> 
+         <name>showDetails</name>    
+	  	 <required>false</required>          
+         <rtexprvalue>true</rtexprvalue>
+	     <type>java.lang.String</type>
+	      <description>This flag {true | false} determines whether to show the details (left characters). default is true</description>         
+      </attribute>  
+      <attribute> 
+         <name>strengthIndicatorType</name>    
+	  	 <required>false</required>          
+         <rtexprvalue>true</rtexprvalue>
+	     <type>java.lang.String</type>
+	      <description>This flag determines the indicator type. It can be {text or bar}. Default is text</description>         
+      </attribute>                               
   </tag>
 </taglib>

Modified: myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/passwordStrength.jsp
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/passwordStrength.jsp?view=diff&rev=561048&r1=561047&r2=561048
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/passwordStrength.jsp (original)
+++ myfaces/tomahawk/trunk/sandbox/examples/src/main/webapp/passwordStrength.jsp Mon Jul 30 10:16:10 2007
@@ -32,12 +32,31 @@
 <f:view>
 
 	<h:form>
+	   
+	    <table>
+		
+		<tr><td>
 		<h:outputText
-			value="Enter your password here. the preferred length is 10" />
+			value="Enter your password" /> 
+		</td></tr>
+		
+		<tr><td>
+		<h:outputText value="Text Mode" />
+		</td><td>
+		<s:passwordStrength id="txtPwdText" preferredPasswordLength="10"
+			value="#{passwordStrengthBean.password}" prefixText="Strength : "
+			textStrengthDescriptions="Very Poor;Weak;Average;Strong;Excellent" strengthIndicatorType="text"/> 
+		</td></tr>
 
-		<s:passwordStrength id="txtName" preferredPasswordLength="10"
+		<tr><td>
+		<h:outputText value="ProgressBar Mode" />
+		</td><td>		
+		<s:passwordStrength id="txtPrgBarText" preferredPasswordLength="10"
 			value="#{passwordStrengthBean.password}" prefixText="Strength : "
-			textStrengthDescriptions="Very Poor;Weak;Average;Strong;Excellent" />
+			textStrengthDescriptions="Very Poor;Weak;Average;Strong;Excellent" strengthIndicatorType="bar"/>
+		</td></tr>			
+			
+	    </table>			
 	</h:form>
 
 	<%@include file="inc/page_footer.jsp"%>
@@ -47,4 +66,5 @@
 </body>
 
 </html>
+