Adrian Crum wrote:
Are you serious? That macro has the exact same parameters and they
aren't documented either. Actually, all that macro does is call the
renderLookupField macro, so I don't understand why it's even there.
No, it does some other important things, like setting default values (eg presentation="layer" width="" height="" position="topleft"
fadeBackground="true"), etc. You should always use this macro if you don't want to experience issues. Because it's supposed to be
the real root for lookup calls from ftl templates and bypassing it might cause issues in the future if we change parameters or their
order, etc.
I would prefer to use the same macro the widgets use for one very good
reason that is made obvious in this commit: Those macros will be
maintained, while the htmlTemplate macros will not.
This does not make sense, since <@htmlTemplate.lookupField calls <@renderLookupField, any changes in <@renderLookupField will be
reflected in <@htmlTemplate.lookupField
As you can see, for reasons explained above, the <@htmlTemplate.lookupField is the entry for lookups in ftl templates. And this is
how it's supposed to be used, so far...
Now for the documentation, most parameters are obvious if you look a bit at the existing examples. But yes, this could be better
documented, I totally agree...
Jacques
-Adrian
On 6/20/2011 10:46 AM, Jacques Le Roux wrote:
Hi Adrian,
Why not using <@htmlTemplate.lookupField ? There are plenty of examples
HTH
Jacques
Adrian Crum wrote:
Jacques,
Coincidentally, I am trying to use the renderLookupField macro in a
Freemarker template. Do you have any idea what all of the macro
parameters are for? I am having a difficult time sorting out what
arguments to pass to get it to work.
-Adrian
On 6/19/2011 9:59 PM, [email protected] wrote:
Author: jleroux
Date: Sun Jun 19 20:59:35 2011
New Revision: 1137433
URL: http://svn.apache.org/viewvc?rev=1137433&view=rev
Log:
A patch from Leon<<"setUserPreference" goes to main page instead
last view if current form includes any lookup field>>
https://issues.apache.org/jira/browse/OFBIZ-4313 When I open a form
which include lookup field and then click the expand/collapse button
around the upper right corner in the the
header, the page will go to "main" after user preference is settled.
The cause is the requests initiated by lookup field does not
remember the last view name. It simply use "main" instead.
Patch to make lookup requests remember the LAST_VIEW_NAME correctly.
Modified:
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java
ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl
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=1137433&r1=1137432&r2=1137433&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
Sun Jun 19 20:59:35 2011 @@ -2149,6 +2149,14 @@
public class MacroFormRenderer implement boolean showDescription =
"Y".equals(UtilProperties.getPropertyValue("widget",
"widget.lookup.showDescription", "N"));
+ // lastViewName, used by lookup to remember the real last
view name
+ String lastViewName =
request.getParameter("_LAST_VIEW_NAME_"); // Try to get it from
parameters firstly
+ if (UtilValidate.isEmpty(lastViewName)) { // get from session
+ lastViewName = (String)
request.getSession().getAttribute("_LAST_VIEW_NAME_");
+ }
+ if (UtilValidate.isEmpty(lastViewName)) {
+ lastViewName = "";
+ }
StringWriter sr = new StringWriter();
sr.append("<@renderLookupField ");
sr.append(" className=\"");
@@ -2208,6 +2216,8 @@ public class MacroFormRenderer implement
sr.append(Boolean.toString(showDescription));
sr.append("\" initiallyCollapsed=\"");
sr.append(Boolean.toString(isInitiallyCollapsed));
+ sr.append("\" lastViewName=\"");
+ sr.append(lastViewName);
sr.append("\" />");
executeMacro(writer, sr.toString());
Modified:
ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl?rev=1137433&r1=1137432&r2=1137433&view=diff
==============================================================================
---
ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl
(original) +++
ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl Sun
Jun 19 20:59:35 2011 @@ -543,7 +543,7 @@
${item.description}</span> </#if>
</#macro>
-<#macro renderLookupField className alert name value size maxlength
id event action readonly autocomplete descriptionFieldName
formName fieldFormName targetParameterIter imgSrc ajaxUrl
ajaxEnabled presentation width height position fadeBackground
clearText showDescription initiallyCollapsed> +<#macro
renderLookupField className alert name value size maxlength id event
action readonly autocomplete descriptionFieldName formName
fieldFormName targetParameterIter imgSrc ajaxUrl ajaxEnabled
presentation width height position fadeBackground clearText
showDescription initiallyCollapsed lastViewName="main"> <#if
ajaxEnabled?has_content&& ajaxEnabled> <script
type="text/javascript"> jQuery(document).ready(function(){ @@
-575,11 +575,7 @@
${item.description}</span> <#if ajaxEnabled?has_content&&
ajaxEnabled>
<#assign defaultMinLength =
Static["org.ofbiz.base.util.UtilProperties"].getPropertyValue("widget.properties",
"widget.autocompleter.defaultMinLength")> <#assign
defaultDelay =
Static["org.ofbiz.base.util.UtilProperties"].getPropertyValue("widget.properties",
"widget.autocompleter.defaultDelay")> -<#if
parameters?has_content&& parameters._LAST_VIEW_NAME_?has_content>
-<#local ajaxUrl = ajaxUrl + "&_LAST_VIEW_NAME_=" +
parameters._LAST_VIEW_NAME_ />
-<#else>
-<#local ajaxUrl = ajaxUrl + "&_LAST_VIEW_NAME_=main"/>
-</#if>
+<#local ajaxUrl = ajaxUrl + "&_LAST_VIEW_NAME_=" + lastViewName />
<#if !ajaxUrl?contains("searchValueFieldName=")>
<#if descriptionFieldName?has_content&& showDescription == "true">
<#local ajaxUrl = ajaxUrl + "&searchValueFieldName=" +
descriptionFieldName />
@@ -611,10 +607,8 @@ ${item.description}</span>
<#if readonly?has_content&& readonly><a id="${id}_clear"
style="background:none;margin-left:5px;margin-right:15px;"
class="clearField" href="javascript:void();"
onclick="javascript:document.${formName}.${name}.value='';<#if
descriptionFieldName?has_content>document.${formName}.${descriptionFieldName}.value='';</#if>">${clearText}</a></#if>
</span>
<#if ajaxEnabled?has_content&& ajaxEnabled> -<#if
parameters?has_content&& parameters._LAST_VIEW_NAME_?has_content&&
ajaxUrl?index_of("_LAST_VIEW_NAME_")< 0>
-<#local ajaxUrl = ajaxUrl + "&_LAST_VIEW_NAME_=" +
parameters._LAST_VIEW_NAME_ />
-<#elseif ajaxUrl?index_of("_LAST_VIEW_NAME_")< 0>
-<#local ajaxUrl = ajaxUrl + "&_LAST_VIEW_NAME_=main"/>
+<#if ajaxUrl?index_of("_LAST_VIEW_NAME_")< 0>
+<#local ajaxUrl = ajaxUrl + "&_LAST_VIEW_NAME_=" + lastViewName />
</#if>
<script language="JavaScript"
type="text/javascript">ajaxAutoCompleter('${ajaxUrl}',
${showDescription},
${defaultMinLength!2}, ${defaultDelay!300});</script><#t/> </#if>