Hi Erwan,

please remember to add the "alternate" parameter to all the other ftl macro 
renderers.

Jacopo

On Mar 22, 2010, at 10:10 AM, [email protected] wrote:

> Author: erwan
> Date: Mon Mar 22 09:10:24 2010
> New Revision: 926006
> 
> URL: http://svn.apache.org/viewvc?rev=926006&view=rev
> Log:
> Adding alternate tag when using hyperlink in forms. If the image is not 
> found, then the alternate text will be displayed
> 
> Modified:
>    ofbiz/trunk/framework/widget/dtd/widget-form.xsd
>    
> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java
>    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
>    ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl
> 
> Modified: ofbiz/trunk/framework/widget/dtd/widget-form.xsd
> URL: 
> http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-form.xsd?rev=926006&r1=926005&r2=926006&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original)
> +++ ofbiz/trunk/framework/widget/dtd/widget-form.xsd Mon Mar 22 09:10:24 2010
> @@ -836,6 +836,9 @@ under the License.
>             <xs:annotation><xs:documentation>Specifies the string to display, 
> can use the ${} syntax to insert context values; if empty the value of the 
> field will be printed for a default.</xs:documentation></xs:annotation>
>         </xs:attribute>
>         <xs:attribute type="xs:string" name="target-window"/>
> +        <xs:attribute type="xs:string" name="alternate">
> +            <xs:annotation><xs:documentation>Alternate text if the image is 
> not found at image-location</xs:documentation></xs:annotation>
> +        </xs:attribute>
>         <xs:attribute type="xs:string" name="image-location"/>
>         <xs:attribute name="request-confirmation" default="false">
>             <xs:annotation><xs:documentation>If true then the user is 
> presented with a dialog box, if confirmation-message is empty, use 
> default</xs:documentation></xs:annotation>
> 
> Modified: 
> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java
> URL: 
> http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java?rev=926006&r1=926005&r2=926006&view=diff
> ==============================================================================
> --- 
> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java 
> (original)
> +++ 
> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java 
> Mon Mar 22 09:10:24 2010
> @@ -332,6 +332,8 @@ public class MacroFormRenderer implement
>         this.request.setAttribute("image", hyperlinkField.getImage());
>         ModelFormField modelFormField = hyperlinkField.getModelFormField();
> 
> +        String encodedAlternate = 
> encode(hyperlinkField.getAlternate(context), modelFormField, context);
> +        this.request.setAttribute("alternate", encodedAlternate);
>         makeHyperlinkByType(writer, hyperlinkField.getLinkType(), 
> modelFormField.getWidgetStyle(), hyperlinkField.getTargetType(), 
> hyperlinkField.getTarget(context),
>                 hyperlinkField.getParameterList(), 
> hyperlinkField.getDescription(context), 
> hyperlinkField.getTargetWindow(context), 
> hyperlinkField.getConfirmation(context), modelFormField,
>                 this.request, this.response, context);
> @@ -2841,6 +2843,7 @@ public class MacroFormRenderer implement
>             String event = "";
>             String action = "";
>             String imgSrc = "";
> +            String alt = "";
>             String hiddenFormName = 
> WidgetWorker.makeLinkHiddenFormName(context, modelFormField);
> 
>             if (UtilValidate.isNotEmpty(modelFormField.getEvent()) && 
> UtilValidate.isNotEmpty(modelFormField.getAction(context))) {
> @@ -2850,6 +2853,7 @@ public class MacroFormRenderer implement
> 
>             if (UtilValidate.isNotEmpty(request.getAttribute("image"))) {
>                 imgSrc = request.getAttribute("image").toString();
> +                alt = request.getAttribute("alternate").toString();
>             }
> 
>             StringWriter sr = new StringWriter();
> @@ -2864,6 +2868,8 @@ public class MacroFormRenderer implement
>             sr.append(action);
>             sr.append("\" imgSrc=\"");
>             sr.append(imgSrc);
> +            sr.append("\" alternate=\"");
> +            sr.append(alt);
>             sr.append("\" linkUrl=\"");
>             sr.append(linkUrl.toString());
>             sr.append("\" targetWindow=\"");
> 
> Modified: 
> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
> URL: 
> http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java?rev=926006&r1=926005&r2=926006&view=diff
> ==============================================================================
> --- 
> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java 
> (original)
> +++ 
> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java 
> Mon Mar 22 09:10:24 2010
> @@ -2251,6 +2251,7 @@ public class ModelFormField {
>         protected String image;
>         protected FlexibleStringExpander target;
>         protected FlexibleStringExpander description;
> +        protected FlexibleStringExpander alternate;
>         protected FlexibleStringExpander targetWindowExdr;
>         protected List<WidgetWorker.Parameter> parameterList = 
> FastList.newInstance();
> 
> @@ -2272,6 +2273,7 @@ public class ModelFormField {
>             super(element, modelFormField);
> 
>             this.setDescription(element.getAttribute("description"));
> +            this.setAlternate(element.getAttribute("alternate"));
>             this.setTarget(element.getAttribute("target"));
>             this.alsoHidden = 
> !"false".equals(element.getAttribute("also-hidden"));
>             this.linkType = element.getAttribute("link-type");
> @@ -2337,6 +2339,10 @@ public class ModelFormField {
>             return this.description.expandString(context);
>         }
> 
> +        public String getAlternate(Map<String, Object> context) {
> +            return this.alternate.expandString(context);
> +        }
> +
>         public String getTarget(Map<String, Object> context) {
>             return this.target.expandString(context);
>         }
> @@ -2373,6 +2379,13 @@ public class ModelFormField {
>         /**
>          * @param string
>          */
> +        public void setAlternate(String string) {
> +            this.alternate = FlexibleStringExpander.getInstance(string);
> +        }
> +
> +        /**
> +         * @param string
> +         */
>         public void setTarget(String string) {
>             this.target = FlexibleStringExpander.getInstance(string);
>         }
> 
> Modified: ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl
> URL: 
> http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl?rev=926006&r1=926005&r2=926006&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl (original)
> +++ ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl Mon Mar 
> 22 09:10:24 2010
> @@ -526,4 +526,4 @@ ${item.description}</div>
> 
> <#macro makeHiddenFormLinkForm actionUrl name parameters targetWindow><form 
> method="post" action="${actionUrl}" <#if 
> targetWindow?has_content>target="${targetWindow}"</#if> 
> onsubmit="javascript:submitFormDisableSubmits(this)" name="${name}"><#list 
> parameters as parameter><input name="${parameter.name}" 
> value="${parameter.value}" type="hidden"/></#list></form></#macro>
> <#macro makeHiddenFormLinkAnchor linkStyle hiddenFormName event action imgSrc 
> description confirmation><a <#if 
> linkStyle?has_content>class="${linkStyle}"</#if> 
> href="javascript:document.${hiddenFormName}.submit()"<#if action?has_content 
> && event?has_content> ${event}="${action}"</#if><#if 
> confirmation?has_content> onclick="return 
> confirm('${confirmation?js_string}')"</#if>><#if imgSrc?has_content><img 
> src="${imgSrc}"/></#if>${description}</a></#macro>
> -<#macro makeHyperlinkString linkStyle hiddenFormName event action imgSrc 
> linkUrl targetWindow description confirmation><a <#if 
> linkStyle?has_content>class="${linkStyle}"</#if> href="${linkUrl}"<#if 
> targetWindow?has_content> target="${targetWindow}"</#if><#if 
> action?has_content && event?has_content> ${event}="${action}"</#if><#if 
> confirmation?has_content> onclick="return 
> confirm('${confirmation?js_string}')"</#if>><#if imgSrc?has_content><img 
> src="${imgSrc}"/></#if>${description}</a></#macro>
> +<#macro makeHyperlinkString linkStyle hiddenFormName event action imgSrc 
> alternate linkUrl targetWindow description confirmation><a <#if 
> linkStyle?has_content>class="${linkStyle}"</#if> href="${linkUrl}"<#if 
> targetWindow?has_content> target="${targetWindow}"</#if><#if 
> action?has_content && event?has_content> ${event}="${action}"</#if><#if 
> confirmation?has_content> onclick="return 
> confirm('${confirmation?js_string}')"</#if>><#if imgSrc?has_content><img 
> src="${imgSrc}" alt="${alternate}"/></#if>${description}</a></#macro>
> 
> 

Reply via email to