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 2005/12/20 13:32:21 UTC
svn commit: r357973 - in
/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom:
calendar/HtmlCalendarRenderer.java inputTextHelp/HtmlInputTextHelp.java
inputTextHelp/HtmlInputTextHelpTag.java
inputTextHelp/HtmlTextHelpRenderer.java
Author: mmarinschek
Date: Tue Dec 20 04:32:15 2005
New Revision: 357973
URL: http://svn.apache.org/viewcvs?rev=357973&view=rev
Log:
added text-help functionality to inputCalendar, location of image is now definable
Modified:
myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java
myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelp.java
myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelpTag.java
myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/inputTextHelp/HtmlTextHelpRenderer.java
Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java?rev=357973&r1=357972&r2=357973&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/calendar/HtmlCalendarRenderer.java Tue Dec 20 04:32:15 2005
@@ -26,6 +26,8 @@
import org.apache.myfaces.util.MessageUtils;
import org.apache.myfaces.custom.buffer.HtmlBufferResponseWriterWrapper;
import org.apache.myfaces.custom.prototype.PrototypeResourceLoader;
+import org.apache.myfaces.custom.inputTextHelp.HtmlTextHelpRenderer;
+import org.apache.myfaces.custom.inputTextHelp.HtmlInputTextHelp;
import org.apache.commons.lang.StringEscapeUtils;
import javax.faces.application.Application;
@@ -119,12 +121,14 @@
Application application = facesContext.getApplication();
- HtmlInputText inputText = getOrCreateInputTextChild(inputCalendar, application);
+ HtmlInputTextHelp inputText = getOrCreateInputTextChild(inputCalendar, application);
RendererUtils.copyHtmlInputTextAttributes(inputCalendar, inputText);
inputText.setConverter(null); // value for this transient component will already be converted
inputText.setTransient(true);
+ inputText.setHelpText(inputCalendar.getHelpText());
+ inputText.setSelectText(true);
if (value == null && inputCalendar.getSubmittedValue() != null)
{
@@ -233,9 +237,9 @@
}
}
- private HtmlInputText getOrCreateInputTextChild(HtmlInputCalendar inputCalendar, Application application)
+ private HtmlInputTextHelp getOrCreateInputTextChild(HtmlInputCalendar inputCalendar, Application application)
{
- HtmlInputText inputText = null;
+ HtmlInputTextHelp inputText = null;
List li = inputCalendar.getChildren();
@@ -243,16 +247,16 @@
{
UIComponent uiComponent = (UIComponent) li.get(i);
- if(uiComponent instanceof HtmlInputText)
+ if(uiComponent instanceof HtmlInputTextHelp)
{
- inputText = (HtmlInputText) uiComponent;
+ inputText = (HtmlInputTextHelp) uiComponent;
break;
}
}
if(inputText == null)
{
- inputText = (HtmlInputText) application.createComponent(HtmlInputText.COMPONENT_TYPE);
+ inputText = (HtmlInputTextHelp) application.createComponent(HtmlInputTextHelp.COMPONENT_TYPE);
}
return inputText;
}
@@ -295,6 +299,9 @@
addresource.addJavaScriptAtPosition(facesContext, AddResource.HEADER_BEGIN, javascriptLocation+ "/date.js");
addresource.addJavaScriptAtPosition(facesContext, AddResource.HEADER_BEGIN, javascriptLocation+ "/popcalendar.js");
}
+
+ HtmlTextHelpRenderer.addJavaScriptResources(facesContext);
+
facesContext.getExternalContext().getRequestMap().put(JAVASCRIPT_ENCODED, Boolean.TRUE);
}
@@ -853,16 +860,21 @@
public Date getAsDate(FacesContext facesContext, UIComponent uiComponent);
}
- public static class CalendarDateTimeConverter implements DateConverter
+ private static String getHelperString(UIComponent uiComponent)
+ {
+ return uiComponent instanceof HtmlInputCalendar?((HtmlInputCalendar) uiComponent).getHelpText():null;
+ }
+
+ public static class CalendarDateTimeConverter implements DateConverter
{
private static final String CONVERSION_MESSAGE_ID = "org.apache.myfaces.calendar.CONVERSION";
public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s)
{
- if(s==null || s.trim().length()==0)
+ if(s==null || s.trim().length()==0 || s.equals(getHelperString(uiComponent)))
return null;
- DateFormat dateFormat = null;
+ DateFormat dateFormat;
if(uiComponent instanceof HtmlInputCalendar && ((HtmlInputCalendar) uiComponent).isRenderAsPopup())
{
@@ -909,9 +921,9 @@
Date date = (Date) o;
if(date==null)
- return null;
+ return getHelperString(uiComponent);
- DateFormat dateFormat = null;
+ DateFormat dateFormat;
if(uiComponent instanceof HtmlInputCalendar && ((HtmlInputCalendar) uiComponent).isRenderAsPopup())
{
Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelp.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelp.java?rev=357973&r1=357972&r2=357973&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelp.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelp.java Tue Dec 20 04:32:15 2005
@@ -31,6 +31,7 @@
public static final String JS_FUNCTION_SELECT_TEXT = "selectText";
public static final String JS_FUNCTION_RESET_HELP = "resetHelpValue";
public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlInputTextHelp";
+ public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.TextHelp";
private String _helpText = null;
private Boolean _selectText = null;
@@ -48,6 +49,7 @@
public HtmlInputTextHelp()
{
+ setRendererType(DEFAULT_RENDERER_TYPE);
}
public String getHelpText()
Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelpTag.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelpTag.java?rev=357973&r1=357972&r2=357973&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelpTag.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/inputTextHelp/HtmlInputTextHelpTag.java Tue Dec 20 04:32:15 2005
@@ -35,7 +35,7 @@
public String getRendererType()
{
- return "org.apache.myfaces.TextHelp";
+ return HtmlInputTextHelp.DEFAULT_RENDERER_TYPE;
}
public void release()
Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/inputTextHelp/HtmlTextHelpRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/inputTextHelp/HtmlTextHelpRenderer.java?rev=357973&r1=357972&r2=357973&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/inputTextHelp/HtmlTextHelpRenderer.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/inputTextHelp/HtmlTextHelpRenderer.java Tue Dec 20 04:32:15 2005
@@ -36,6 +36,8 @@
*/
public class HtmlTextHelpRenderer extends HtmlTextRenderer
{
+ private static final String JAVASCRIPT_ENCODED = "org.apache.myfaces.inputTextHelp.JAVASCRIPT_ENCODED";
+
protected void renderNormal(FacesContext facesContext, UIComponent component) throws IOException
{
if(component instanceof HtmlInputTextHelp)
@@ -160,9 +162,17 @@
return super.getConvertedValue(facesContext, component, submittedValue);
}
- private static void addJavaScriptResources(FacesContext facesContext)
+ public static void addJavaScriptResources(FacesContext facesContext)
{
+ // check to see if javascript has already been written (which could happen if more than one calendar on the same page)
+ if (facesContext.getExternalContext().getRequestMap().containsKey(JAVASCRIPT_ENCODED))
+ {
+ return;
+ }
+
AddResource.getInstance(facesContext).addJavaScriptAtPosition(
facesContext, AddResource.HEADER_BEGIN, HtmlTextHelpRenderer.class, "inputTextHelp.js");
+
+ facesContext.getExternalContext().getRequestMap().put(JAVASCRIPT_ENCODED, Boolean.TRUE);
}
}