Done - comments added to https://issues.apache.org/jira/browse/OFBIZ-3702
On Wed, Apr 28, 2010 at 11:53 AM, Jacques Le Roux < jacques.le.r...@les7arts.com> wrote: > Hi Chris, > > Could you please take care of Scott's remarks > > Thanks > > Jacques > > > Scott Gray wrote: > >> Inline >> >> Regards >> Scott >> >> On 28/04/2010, at 10:02 PM, jler...@apache.org wrote: >> >> Author: jleroux >>> Date: Wed Apr 28 10:02:57 2010 >>> New Revision: 938844 >>> >>> URL: http://svn.apache.org/viewvc?rev=938844&view=rev >>> Log: >>> A slightly modified patch from Chris Snow "Provide better user help" ( >>> https://issues.apache.org/jira/browse/OFBIZ-3702) - >>> OFBIZ-3702 >>> >>> Provides help by hovering over the field label. See Example for... an >>> example :o) And also >>> >>> https://issues.apache.org/jira/secure/attachment/12442717/fieldLabelTooltip2.png >>> >>> Added: >>> >>> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java >>> (with props) >>> Modified: >>> ofbiz/trunk/framework/example/config/ExampleEntityLabels.xml >>> ofbiz/trunk/framework/example/entitydef/entitymodel.xml >>> ofbiz/trunk/framework/example/widget/example/ExampleForms.xml >>> ofbiz/trunk/framework/widget/config/widget.properties >>> >>> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java >>> ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl >>> >>> Modified: ofbiz/trunk/framework/example/widget/example/ExampleForms.xml >>> URL: >>> >>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/widget/example/ExampleForms.xml?rev=938844&r1=938843&r2=938844&view=diff >>> ============================================================================== >>> --- >>> ofbiz/trunk/framework/example/widget/example/ExampleForms.xml (original) >>> +++ >>> ofbiz/trunk/framework/example/widget/example/ExampleForms.xml Wed Apr 28 >>> 10:02:57 2010 @@ -101,7 +101,7 @@ under the License. >>> </actions> >>> <alt-target use-when="example==null" target="createExample"/> >>> <auto-fields-service service-name="updateExample"/> >>> - <field use-when="example!=null" name="exampleId" >>> title="${uiLabelMap.ExampleExampleId}" >>> tooltip="${uiLabelMap.CommonNotModifRecreat}"><display/></field> + >>> <field use-when="example!=null" name="exampleId" >>> title="${uiLabelMap.ExampleExampleId}" >>> tooltip="${uiLabelMap.CommonNotModifRecreat}" >>> entity-name="Example"><display/></field> <field >>> use-when="example==null @and exampleId==null" name="exampleId" >>> title="${uiLabelMap.ExampleExampleId}"><ignored/></field> <field >>> use-when="example==null @and exampleId!=null" >>> name="exampleId" title="${uiLabelMap.ExampleExampleId}"><display >>> description="${uiLabelMap.CommonCannotBeFound}: [${exampleId}]" >>> also-hidden="false"/></field> <field name="exampleTypeId" >>> title="${uiLabelMap.CommonType}" >>> id-name="exampleTypeId"> @@ -112,12 +112,12 @@ under the >>> License. </entity-options> </drop-down> >>> </field> >>> - <field name="statusId" use-when="example==null" >>> title="${uiLabelMap.CommonStatus}"> >>> + <field name="statusId" use-when="example==null" >>> title="${uiLabelMap.CommonStatus}" entity-name="Example"> >>> <drop-down allow-empty="false"> >>> <entity-options entity-name="ExampleStatusItem" >>> description="${description}"/> >>> </drop-down> >>> </field> >>> - <field name="statusId" use-when="example!=null" >>> title="${uiLabelMap.CommonStatus}"> >>> + <field name="statusId" use-when="example!=null" >>> title="${uiLabelMap.CommonStatus}" entity-name="Example"> >>> <drop-down allow-empty="false" >>> current-description="${currentStatus.description}"> >>> <entity-options entity-name="StatusValidChangeToDetail" >>> key-field-name="statusIdTo" >>> description="${transitionName} (${description})"> >>> <entity-constraint name="statusId" >>> env-name="example.statusId"/> >>> >> >> There is a field on the form element that can be used instead of setting >> these entity names individually >> >> >>> 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=938844&r1=938843&r2=938844&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 >>> Wed Apr 28 10:02:57 2010 @@ -48,6 +48,7 @@ import >>> org.ofbiz.base.util.UtilPropertie >>> import org.ofbiz.base.util.UtilValidate; >>> import org.ofbiz.base.util.string.FlexibleStringExpander; >>> import org.ofbiz.base.util.template.FreeMarkerWorker; >>> +import org.ofbiz.entity.Delegator; >>> import org.ofbiz.webapp.control.RequestHandler; >>> import org.ofbiz.webapp.taglib.ContentUrlTag; >>> import org.ofbiz.widget.ModelWidget; >>> @@ -1202,11 +1203,23 @@ public class MacroFormRenderer implement >>> style = requiredStyle; >>> } >>> } >>> + Delegator delegator = >>> (Delegator)request.getAttribute("delegator"); >>> >> >> Should be modelForm.getDelegator(); >> Ideally the form renderer wouldn't be dependent on an HttpServletRequest >> object at all >> >> + Locale locale = (Locale)context.get("locale"); >>> + String entityName = modelFormField.getEntityName(); >>> + String fieldName = modelFormField.getFieldName(); >>> + String helpText = UtilHelpText.getHelp(entityName, >>> fieldName, delegator, locale); >>> >> >> Retrieving the help text before checking the property? >> >> + >>> + String displayHelpText = >>> UtilProperties.getPropertyValue("widget.properties", >>> "widget.form.displayhelpText"); >>> + >>> StringWriter sr = new StringWriter(); >>> sr.append("<@renderFieldTitle "); >>> sr.append(" style=\""); >>> sr.append(style); >>> - sr.append("\" title=\""); >>> + if ("Y".equals(displayHelpText)) { >>> + sr.append("\" fieldHelpText=\""); >>> + >>> sr.append(FreeMarkerWorker.encodeDoubleQuotes(helpText)); >>> + } >>> + sr.append("\" fieldTitle=\""); >>> sr.append(sb.toString()); >>> sr.append("\" />"); >>> executeMacro(writer, sr.toString()); >>> >>> Added: >>> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java >>> URL: >>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java?rev=938844&view=auto >>> >>> ============================================================================== >>> --- >>> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java >>> (added) >>> +++ >>> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java Wed >>> Apr 28 10:02:57 2010 >>> @@ -0,0 +1,56 @@ >>> +package org.ofbiz.widget.form; >>> + >>> +import java.util.Locale; >>> + >>> +import org.ofbiz.base.util.Debug; >>> +import org.ofbiz.base.util.UtilProperties; >>> +import org.ofbiz.base.util.UtilValidate; >>> +import org.ofbiz.entity.Delegator; >>> +import org.ofbiz.entity.GenericEntityException; >>> +import org.ofbiz.entity.model.ModelEntity; >>> +import org.ofbiz.entity.model.ModelReader; >>> + >>> +/** >>> + * Util for working with Help Text >>> + */ >>> +public class UtilHelpText { >>> + >>> + public static final String module = UtilHelpText.class.getName(); >>> + >>> + /** >>> + * Find the help text associated with an entity field. >>> + * >>> + * @param entityName the entity name >>> + * @param fieldName the field name >>> + * @param delegator the delegator >>> + * @param locale the locale >>> + * @return the help text, or the resource propertyName if no help >>> text exists >>> + */ >>> + public static String getHelp(final String entityName, final String >>> fieldName, final Delegator delegator, final Locale >>> locale) { >>> >> >> Bad method name choice >> >> + >>> + if (UtilValidate.isEmpty(entityName)) { >>> + Debug.logWarning("entityName [" + entityName + "] is empty", >>> module); >>> + return ""; >>> + } >>> + if (UtilValidate.isEmpty(fieldName)) { >>> + Debug.logWarning("fieldName [" + fieldName + "] is empty", >>> module); >>> + return ""; >>> + } >>> + ModelReader reader = delegator.getModelReader(); >>> + ModelEntity entity = null; >>> + try { >>> + if (!reader.getEntityNames().contains(entityName)) { >>> + Debug.logWarning("couldn't find entityName [" + >>> entityName + "]", module); >>> + return ""; >>> + } >>> + entity = reader.getModelEntity(entityName); >>> + } catch (GenericEntityException e) { >>> + Debug.logError(e, "Error getting help text for entity=" + >>> entityName + " field " + fieldName, module); >>> + return ""; >>> + } >>> + String entityResourceName = entity.getDefaultResourceName(); >>> + String messageId = "FieldDescription." + entityName + "." + >>> fieldName; >>> + String fieldDescription = >>> UtilProperties.getMessage(entityResourceName, messageId, locale); >>> + return fieldDescription; >>> + } >>> +} >>> \ No newline at end of file >>> >>> Propchange: >>> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java >>> >>> ------------------------------------------------------------------------------ >>> svn:eol-style = native >>> >>> Propchange: >>> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java >>> >>> ------------------------------------------------------------------------------ >>> svn:keywords = Date Rev Author URL Id >>> >>> Propchange: >>> ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/UtilHelpText.java >>> >>> ------------------------------------------------------------------------------ >>> svn:mime-type = text/plain >>> >>> Modified: ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl >>> URL: >>> >>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl?rev=938844&r1=938843&r2=938844&view=diff >>> ============================================================================== >>> --- >>> ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl >>> (original) +++ >>> ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl Wed Apr >>> 28 10:02:57 2010 @@ -205,14 +205,20 @@ >>> ${item.description}</span> >>> >>> <#macro renderIgnoredField></#macro> >>> >>> -<#macro renderFieldTitle style title> >>> +<#macro renderFieldTitle style fieldTitle fieldHelpText=""> >>> + <#if fieldHelpText?has_content> >>> + <span title="${fieldHelpText}"><#t/> >>> + </#if> >>> <#if style?has_content> >>> <span class="${style}"><#t/> >>> </#if> >>> - ${title}<#t/> >>> + ${fieldTitle}<#t/> >>> <#if style?has_content> >>> - </span><#lt/> >>> + </span><#t/> >>> </#if> >>> + <#if fieldHelpText?has_content> >>> + </span><#t/> >>> + </#if> >>> </#macro> >>> >> >> What about the other macro libraries? >> > > >