﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-liangcmwn-文章分类-Ofbiz</title><link>http://www.blogjava.net/liangcmwn/category/48941.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 31 Aug 2011 19:53:57 GMT</lastBuildDate><pubDate>Wed, 31 Aug 2011 19:53:57 GMT</pubDate><ttl>60</ttl><item><title>CACHING - How to implement "Distributed cache clearing" in Ofbiz?</title><link>http://www.blogjava.net/liangcmwn/articles/357256.html</link><dc:creator>liangcmwn</dc:creator><author>liangcmwn</author><pubDate>Thu, 25 Aug 2011 05:56:00 GMT</pubDate><guid>http://www.blogjava.net/liangcmwn/articles/357256.html</guid><wfw:comment>http://www.blogjava.net/liangcmwn/comments/357256.html</wfw:comment><comments>http://www.blogjava.net/liangcmwn/articles/357256.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liangcmwn/comments/commentRss/357256.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liangcmwn/services/trackbacks/357256.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: We have multiple instances of Ofbiz/Opentaps running. All the instances talk to same database. There are many tables that are rarely updated hence the are cached and all the instances maintain their i...&nbsp;&nbsp;<a href='http://www.blogjava.net/liangcmwn/articles/357256.html'>阅读全文</a><img src ="http://www.blogjava.net/liangcmwn/aggbug/357256.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liangcmwn/" target="_blank">liangcmwn</a> 2011-08-25 13:56 <a href="http://www.blogjava.net/liangcmwn/articles/357256.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>OFBIZ分页操作</title><link>http://www.blogjava.net/liangcmwn/articles/353354.html</link><dc:creator>liangcmwn</dc:creator><author>liangcmwn</author><pubDate>Wed, 29 Jun 2011 06:27:00 GMT</pubDate><guid>http://www.blogjava.net/liangcmwn/articles/353354.html</guid><wfw:comment>http://www.blogjava.net/liangcmwn/comments/353354.html</wfw:comment><comments>http://www.blogjava.net/liangcmwn/articles/353354.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liangcmwn/comments/commentRss/353354.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liangcmwn/services/trackbacks/353354.html</trackback:ping><description><![CDATA[<div>需在xxxScreens.xml中action属性中设置set属性，其格式为<br />&lt;set field="queryString"  value="*"/&gt;<br />&lt;set field="viewIndex"  from-field="parameters.VIEW_INDEX" type="Integer"  default-value="0"/&gt;<br />&lt;set field="viewSize"  from-field="parameters.VIEW_SIZE" type="Integer"  default-value="5"/&gt;<br />其中第一个是设置查询字符串，第二个是设置结果集的索引，第三个是设置显示记录的条数,<br />还需在 xxxForms.xml中相关form中设置paginate和paginate-target属性，其格式为 <br />&lt;form  name="GuestbookList" type="list" list-name="allGuests" paginate="true"  paginate-target="guestbook"&gt;，<br />其中将<span style="color: red;">paginate设置为&#8220;true&#8221;</span>，是表示允许分页，<span style="color: red;">paginate- target的值表示是对哪个screen进行分页</span>，对应于xxxScreen.xml中相关的screen的名字</div><img src ="http://www.blogjava.net/liangcmwn/aggbug/353354.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liangcmwn/" target="_blank">liangcmwn</a> 2011-06-29 14:27 <a href="http://www.blogjava.net/liangcmwn/articles/353354.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>THE FORM-WIDGET COOKBOOK</title><link>http://www.blogjava.net/liangcmwn/articles/353122.html</link><dc:creator>liangcmwn</dc:creator><author>liangcmwn</author><pubDate>Tue, 28 Jun 2011 01:16:00 GMT</pubDate><guid>http://www.blogjava.net/liangcmwn/articles/353122.html</guid><wfw:comment>http://www.blogjava.net/liangcmwn/comments/353122.html</wfw:comment><comments>http://www.blogjava.net/liangcmwn/articles/353122.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/liangcmwn/comments/commentRss/353122.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/liangcmwn/services/trackbacks/353122.html</trackback:ping><description><![CDATA[<div>THE FORM-WIDGET COOKBOOK<br />========================<br /><br />This document is a series of HOWTOs on using the OFBIZ form-widget to create forms.<br /><br />* Important warning about submit button names: Don't name your submit field "submit", because this will cause a bug "button.form.submit is not a function"<br /><span style="color: red;">关于submit按钮的重要警告：不要将提交按钮命名为"submit"，这将导致一个bug:"button.form.submit is not a function"</span><br />&nbsp; &lt;field name="submit" ...&gt;&nbsp; &lt;!- Don't do this! call it "submitButton" instead. --&gt;<br />&nbsp; For reference on this: http://www.chovy.com/2005/06/21/1/javascript-error-submit-is-not-a-function/<br /><br />* How to make each line of a list form a submit form of its own<br />&nbsp;&nbsp;&nbsp; &lt;form ... type="list" target=""...&gt; where target is the target of each line item of the form<br /><br />&nbsp;&nbsp;&nbsp; For each &lt;field&gt; which has input values, use a &lt;text&gt; or &lt;date-time&gt; instead of &lt;display&gt; tag<br /><span style="color: red;">&nbsp;&nbsp; &nbsp;对于需要编辑的域，使用标记：&lt;text&gt;或&lt;date-time&gt;来替代&lt;display&gt;</span><br />&nbsp;&nbsp;&nbsp; Then make a submit button (see below):<br /><br />* How to make one form and submit button per list entry<br />&nbsp; 如何在一个form中提交每一个列表项<br />&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; First, create your form as normal.&nbsp; Then add a submit button of type "text-link":<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;首先，创建一个普通的form，添加一个类型为"text-link"的submit按钮。<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="submitButton" title="ButtonTextLabel" widget-style="buttontext" use-when="hasUpdatePermission==true"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;submit button-type="text-link"/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/field&gt;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next, create a service and invoke it as a regular (not multi) service. Only the row which was submitted will be processed.<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<span style="color: red;">然后，创建一个service并以一个规则的service调用。只有提交的行才会被更新。</span><br /><br />* How to display a field as a currency<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="${amount}"&gt;&lt;display type="currency" currency="${currencyUomId}"/&gt;&lt;/field&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The currencyUomId must be part of the entity, or you can hardcode it (e.g., currency="USD")<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: red;">&nbsp;输出一个货币域。currencyUomId必须是实体的一个属性或者被硬编码。</span><br /><br />* How to display a date/time input field<br />&nbsp;&nbsp; &nbsp;如何输出一个日期/时间对象<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="dateField"&gt;&lt;date-time/&gt;&lt;/field&gt;&nbsp; &nbsp;<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp; This will display it as a timestamp.&nbsp; For input fields, it will also put a javascript calendar next to it.<br />&nbsp;&nbsp; 这将输出一个timestamp，在输入框后有一个日期选择控件。<br />&nbsp;&nbsp; To display it as a date only, use<br />&nbsp;&nbsp; 只输出一个<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;date-time type="date"/&gt;<br />&nbsp;&nbsp; To display only a time, use<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;date-time type="time"/&gt;<br /><br />&nbsp;&nbsp; A much better way to input date + time,<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="something"&gt;&lt;date-time type="timestamp" input-method="time-dropdown" clock="12"/&gt;<br /><br />&nbsp;&nbsp; This generates a standard date input with dropdowns to select the hour, minutes, and AM/PM.<br /><br />* How to display a date/time as text<br />&nbsp;&nbsp; &nbsp;<span style="color: red;">如何输出一个text的时间</span><br /><br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="dateField"&gt;&lt;display/&gt;&lt;/field&gt;<br /><br />&nbsp;&nbsp; Sometimes it will appear red, in which case do the following to stop that:<br />&nbsp;&nbsp; 日期显示为红色<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="dateField" red-when="false"&gt;&lt;display/&gt;&lt;/field&gt;<br />&nbsp;&nbsp; Sometimes you want to truncate the hours, minutes and so on to show only the date (watch out for bsh errors)<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="dateField"&gt;&lt;display description="${bsh: dateField.substring(0,10)}"/&gt;&lt;/field&gt;<br /><br />* How to default date time fields to now<br />&nbsp; <span style="color: red;">设置默认时间</span><br />&nbsp;&nbsp;&nbsp; In general, you can use the ${bsh: } directive to invoke bsh in the form widget to display values.&nbsp; This is one<br />&nbsp;&nbsp;&nbsp; good example of it:<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="productsSoldThruTimestamp" title="${uiLabelMap.ProductShowProductsSoldThruTimestamp}" widget-style="inputBox"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;date-time default-value="${bsh: org.ofbiz.base.util.UtilDateTime.nowTimestamp()}"/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/field&gt;&nbsp; &nbsp;<br /><br />* How to change the style of a form widget<br />&nbsp;&nbsp; &nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Form widget styles are CSS styles listed in /images/maincss.css and /images/tabstyles.css<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Two ways: block level and inline style<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; block: equivalent to the styles you'd give to a &lt;p&gt;, &lt;div&gt; or &lt;table&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field widget-area-style="css_block_style"&gt; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; inline: equivalent to the styles you'd give to a &lt;span&gt; or &lt;em&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field widget-style="css_inline_style"&gt;<br /><br /><br />* How to tell the form what map or list to use<br /><span style="color: red;">如何让一个form使用一个map或list</span><br /><br />&nbsp; &lt;form type="single" default-map-name="map"&gt;<br />&nbsp; &lt;form type="list" list-name="list"&gt;<br />&nbsp; &lt;form type="multi" list-name="list"&gt;<br /><br /><br />* How to pass a parameter on to the "success" view when a form is successfully processed<br /><span style="color: red;">当一个form成功处理后如何传递一个参数到success视图</span><br /><br />&nbsp; For example, suppose you have a "createNoteForm" form to create notes and when it finishes, you want<br />&nbsp; to continue to "viewParty?partyId=${partyId}". How do you pass the partyId to the next view-map (viewParty)<br />&nbsp; when the form is submitted? There's a trick to do this:<br /><span style="color: red;">&nbsp;&nbsp; &nbsp;例如，假如有个"createNoteForm"，当它提交后需要创建notes，然后跳转到页面"viewParty?partyId=${partyId}"。</span><br /><span style="color: red;">&nbsp;&nbsp; &nbsp;当提交的时候如何传递partyId给下一个视图？</span><br />&nbsp;&nbsp; &nbsp;<br />&nbsp; &lt;form name="createNoteForm" target="createNote?partyId=${partyId}" ...&gt;<br /><br />&nbsp; And in controller.xml:<br /><br />&nbsp; &lt;request-map uri="createNote"&gt;<br />&nbsp;&nbsp;&nbsp; &lt;event type="service" invoke="createNote"/&gt;<br />&nbsp;&nbsp;&nbsp; &lt;response name="success" type="view" value="viewParty"/&gt;<br />&nbsp; &lt;/request&gt;<br /><br />&nbsp; The "viewParty" view-map will then be invoked with the partyId in the parameters.<br />&nbsp;&nbsp; &nbsp;<br /><br />* How to call Java from within a display tag<br />&nbsp;&nbsp;&nbsp; &lt;display description="${bsh: code_here }"/&gt;<br />&nbsp;&nbsp; ex:<br />&nbsp;&nbsp;&nbsp; &lt;field position="1" name="invoiceAmount"&gt;&lt;display description="${bsh:org.ofbiz.accounting.invoice.InvoiceWorker.getInvoiceTotalBd(delegator,invoiceId)}" type="currency" currency="${invoice.currencyUomId}" also-hidden="false"/&gt;&lt;/field&gt;<br />&nbsp;&nbsp; For double quotes ("), use the xml directive &amp;quot;<br /><br /><br />* How to set the length and maxsize of a text field<br /><br />&nbsp; &lt;text size="10" maxlength="20"/&gt;<br /><br /><br />* How to make a tooltip box appear above a field when hoving over it<br /><br />&nbsp; &lt;field tooltip="tooltip-text"&gt;<br /><br /><br />* How to mark a field as required<br /><br />Change the widget style to something that stands out and maybe add an asterix after the description.<br /><br /><br />* How to create a drop down<br /><br />&lt;drop-down allow-empty="true"&gt;<br />&nbsp; &lt;option key="parameterValue1" description="selectText1"/&gt;<br />&nbsp; &lt;option key="parameterValue2" description="selectText2"/&gt;<br />&nbsp; &lt;option key="parameterValue3" description="selectText3"/&gt;<br />&lt;/drop-down&gt;<br /><br />* How to specify default values for a drop down<br />&lt;drop-down current="selected" no-current-selected-key="default value"&gt;<br /><br />&nbsp;&nbsp; current="selected" tells it to make the current key selected, so if you're refilling out a form, a selected field will be selected again<br />&nbsp;&nbsp; no-current-key-selected= is used to specify a default value.&nbsp; It can be a literal value ("USD") or a variable ("${currencyUomId"})<br /><br /><br />* How to make multi column forms<br /><br />&nbsp; &lt;field name="firstColumn" position="1"/&gt;<br />&nbsp; &lt;field name="secondColumn" position="2"/&gt;<br />&nbsp; &lt;field name="thirdColumn" position="3"/&gt;<br />&nbsp; ...<br />&nbsp; &lt;field name="firstColumnNextRow" position="1"/&gt;<br />&nbsp; &lt;field name="secondColumnNextRow" position="2"/&gt;<br />&nbsp; ...<br /><br />* How to make a "multi" form to list and operate on many entities at once<br /><br />&lt;pre&gt;<br />&lt;form type="multi" use-row-submit="true" target="controllerTarget"&gt;<br />&nbsp; &lt;field name="submitButton" title="ButtonName"&gt;&lt;submit/&gt;&lt;/field&gt;<br />&lt;/form&gt;<br />&lt;/pre&gt;<br />&nbsp;&nbsp; &nbsp;<br />use-row-submit<br />&nbsp;&nbsp;&nbsp; "false" will invoke a multi service for every row. This is the default<br />&nbsp;&nbsp;&nbsp; "true" will invoke a multi service only when the row is checked<br />submitButton<br />&nbsp;&nbsp;&nbsp; a single submit button at the bottom of the list<br />&nbsp;&nbsp;&nbsp; target<br />specify &lt;event type="service-multi" invoke="serviceName"&gt; in controller.xml request-map controllerTarget <br />&nbsp;&nbsp;&nbsp; to invoke serviceName once for each row according to use-row-submit<br />&nbsp; <br />* How to then pass just one field back to the multi-form<br /><br />What if you need to pass just one field to a multi-form, such as a facilityId?&nbsp; One way (maybe not the best way!) is to put into the form target URL, like this:<br />target="BatchScheduleShipmentRouteSegments?facilityId=${facilityId}"<br /><br />* How to have each row of a multi-form be selected by default<br /><br />This is very tricky, but I saw Jacopo do it in commit r 448936, tried it, and it worked!&nbsp; You have to set it in the<br />screen-widget in the &lt;actions&gt; section like this:<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;set field="_rowSubmit" value="Y"/&gt;<br /><br />* How to reference the description field from a related entity, such as displaying<br />&nbsp;StatusItem.description when the field is statusId (and similar)<br />me="statusId" title="Return Status" widget-style="selectBox"&gt;<br /><br />&lt;display-entity entity-name="Foo"/&gt;<br />&lt;display-entity entity-name="Foo" key-field-name="fooId"/&gt;<br />&lt;display-entity entity-name="Foo" description="${something} - ${complex}"/&gt;<br /><br />&nbsp; by default this retrieves the description from the field named "description"<br />&nbsp; -&nbsp; use description="" to format the output: the context will contain the<br />&nbsp;&nbsp;&nbsp;&nbsp; entities fields and their values<br />&nbsp; use key-field-name="primaryKeyId" if the field name is different from the<br />&nbsp; entity's field name (e.g., the field is paymentStatusId but we're looking up<br />&nbsp; StatusItem.statusId, so use key-field-name="statusId")<br /><br />* Using the sub-hyperlink to put a link next to display entity<br /><br />&nbsp; Here is an example where you can use display-entity to cross-reference data from a related entity,<br />then put a link as well:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="glAccountId" title="Account" widget-style="tabletext"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;display-entity entity-name="GlAccount" description="${accountName}"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;sub-hyperlink target="ListGlAccountEntries?glAccountId=${glAccountId}" description="[${glAccountId}]" link-style="tabletext"/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/display-entity&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/field&gt;<br />&nbsp;<br /><br />* How to get a set of options from StatusItem table<br /><br />&nbsp; &lt;field name="fooStatusId" title="Foo Status" widget-style="selectBox"&gt;<br />&nbsp;&nbsp;&nbsp; &lt;drop-down&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;entity-options entity-name="StatusItem" description="${description}"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;entity-constraint name="statusTypeId" value="ORDER_RETURN_STTS"/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;entity-order-by field-name="sequenceId"/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/entity-options&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/drop-down&gt;<br />&nbsp; &lt;/field&gt;<br /><br />&nbsp; NOTE: This will filter by date if a fromDate and thruDate are present. Make sure that these fields are of type="date-time" and not "date",<br />&nbsp; otherwise you'll get a mysterious class cast exception with Date in the error log. If you want to avoid the filter, you can specify:<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;entity-options filter-by-date="false"&gt;<br /><br />&nbsp; A good example of this is CustomTimePeriod which has fromDate and thruDate of type "date", but will crash unless you stop the filter by date.<br />&nbsp; It's good practice to specify filter-by-date if the entity has a fromDate and thruDate just to make it explicit.<br /><br /><br />* How to turn a field into a link<br /><br />&nbsp;&nbsp; Use the &lt;hyerlink ../&gt; tag inside of &lt;field&gt; ... &lt;/field&gt; with description= for the<br />anchor text on the form and target= for the link to use.&nbsp; Use the target-type="inter-app"<br />when the hyperlink goes to a different webapp (ie, from marketing to party manager). &nbsp;<br />&nbsp;&nbsp; Ex:<br />&lt;hyperlink description="${visitId}" target="/partymgr/control/visitdetail?visitId=${visitId}&amp;amp;DONE_PAGE=${donePage}" target-type="inter-app"/&gt;<br /><br />&nbsp;&nbsp; IMPORTANT: use XML notation such as &amp;amp; when entering HTML tag with special characters such as "&amp;"<br /><br /><br />* How to disable display/execution of a field with a condition<br /><br />&nbsp; &lt;field name="fooId" use-when="${bsh:fooId!=null}"&gt;<br />&nbsp; &lt;field name="fooId" use-when="fooId!=null"&gt;&nbsp;&nbsp; &lt;!-- values are from context --&gt;<br /><br />&nbsp; use-when="true" will cause a field always to display.<br />&nbsp; use-when="false" will cause a field never to display.<br /><br />&nbsp; use-when is interpreted as beanshell using the current beanshell interpreter context. You can test for variables<br />&nbsp; from the screen widget that were defined with &lt;set field="field" value="value"/&gt;.&nbsp; You can also invoke Java methods that<br />&nbsp; return a boolean true/false with something like<br />&nbsp; use-when="com.mysite.MyClass.myStaticBooleanMethod(myParameter);"<br /><br />&nbsp; IMPORTANT: Due to the way beanshell works, testing "foo==null" will return true if foo has not been defined yet!&nbsp; This is<br />&nbsp; because beanshell considers undefined parameters as "void", and void is not consiered to be null. You can see this behavior<br />&nbsp; for yourself by executing this bsh: print("Is foo null? " + (foo==null) + ". Is foo void? " + (foo==void));<br /><br />&nbsp; What if you have a list form and need to access a field from each member of the list?&nbsp; After some (rather blind) trial and<br />&nbsp; error, we found that the magic word is "context", as in:<br />&nbsp; &lt;form name="MyForm" ... list-name="myList"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="myField" use-when="context.getString(&amp;quot;myField&amp;quot;).equals(&amp;quot;someValue&amp;quot;)"&gt;....<br />&nbsp; this will test "myField" in each element of myList in your use-when<br /><br />&nbsp; IMPORTANT: Also note that most other form-widget fields that accept ${} notation uses FTL markup language, not beanshell.<br />&nbsp; This leads to situations where you have use-when="parameters.get(&amp;quot;fieldName&amp;quot;)" and later on, description="${parameters.fieldName}"<br /><br />*&nbsp; How to set the default styles of a form<br /><br />&nbsp;&nbsp; -&nbsp; headers/titles: &lt;form default-title-style="tableheadtext"&gt;<br />&nbsp;&nbsp; -&nbsp; text: &lt;form default-widget-style="tabletext"&gt;<br />&nbsp;&nbsp; -&nbsp; tooltip: &lt;form default-tooltip-style="tableheadtext"&gt; (tooltip is the text next to the input or display fields)<br /><br />* How to show a list of valid status changes<br /><br />&nbsp; OFBIZ uses the StatusValidChange entity to control valid status transitions.&nbsp; You can use the StatusValidChangeToDetail and your current<br />statusId to control the list of status in a drop down, so the user doesn't try to make an illegal status change:<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="statusId" use-when="communicationEvent!=null" title="${uiLabelMap.CommonStatus}" widget-style="selectBox"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;drop-down allow-empty="false" current-description="${uiLabelMap.CommonSelectOne}"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;entity-options entity-name="StatusValidChangeToDetail" key-field-name="statusIdTo" description="${transitionName}"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;entity-constraint name="statusId" value="${communicationEvent.statusId}"/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;entity-order-by field-name="sequenceId"/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/entity-options&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/drop-down&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/field&gt;<br /><br />This is from applications/marketing/webapp/marketing/contact/ContactListForms.xml <br /><br />Note that current-description tag here needs to be something like ${uiLabelMap.CommonSelectOne} - trying to lookup <br />${currentStatus.description} would just return the current statusId.<br /><br /><br />* How to fill-in default values on a form<br /><br />&nbsp; &lt;form name="myForm" default-map-name="displayValue" ..&gt;<br /><br />&nbsp; will pre-fill an input form with the values from displayValue.&nbsp; Note that displayValue can either be a Java Map or<br />an OFBIZ GenericValue.&nbsp; This allows you to add new fields to your display form from an OFBIZ GenericValue.&nbsp; Here is a neat<br />trick you can do in beanshell (.bsh):<br /><br />&nbsp; value = delegator.findByPrimaryKey("SomeGenericValue", UtilMisc.toMap("keyField", keyFieldId));<br />&nbsp; displayValue = new HashMap();<br />&nbsp; displayValue.putAll(value.getAllFields());<br />&nbsp; displayValue.put("another Field", anotherValue);<br />&nbsp; // etc. etc.<br /><br />&nbsp; context.put("displayValue", displayValue);<br /><br />* How to add some descriptive text in the middle of a form<br /><br />&nbsp; This is a hack, pure and simple.&nbsp; Let's say you want some text in the middle of the same form so there are<br />separate sections to your form.&nbsp; You can create a "dummy" field with a description of your text and use CSS<br />to make it look like a section divider:<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="" widget-style="tableheadtext"&gt;&lt;display description="Arbitrary Text"/&gt; &lt;/field&gt;<br /><br />What if you need several lines of this spread throughout your form?&nbsp; Each field name is only displayed by the<br />form widget once, so you'll need several slightly different field names, like this:<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name=" " widget-style="tableheadtext"&gt;&lt;display description="More Arbitrary Text"/&gt; &lt;/field&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="&nbsp; " widget-style="tableheadtext"&gt;&lt;display description="Still More Arbitrary Text"/&gt; &lt;/field&gt;<br /><br />* How to use the same field or value more than once on the form<br /><br />&nbsp; Let's say you need to display productId twice on your form, once as productId and once as the product description.<br />The form widget will only display each field name="" once.&nbsp; You can explicitly set the 'entry-name' attribute (by default the <br />'entry-name' attribute is equals to the 'name' attribute) to make it display the same field twice.<br /><br />&lt;field name="productId"&gt;&lt;display/&gt;&lt;/field&gt;<br />&lt;field name="productDescription" entry-name="productId"&gt;<br />&nbsp;&nbsp; &lt;display-entity entity-name="Product"/&gt;&nbsp; &lt;!-- defaults to display description --&gt;<br />&lt;/field&gt;<br /><br />(Thanks to Jacopo for this tip.)<br /><br />* How to put in a lookup form with a widget button<br /><br />&nbsp; In the form widget, use the &lt;lookup-target &gt; for the field:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="productId"&gt;&lt;lookup target-form-name="LookupProduct" size="20"/&gt;&lt;/field&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; This will put a link to &lt;javascript:call_fieldlookup2(name_of_form_field, "LookupProduct")<br />&nbsp;&nbsp;&nbsp;&nbsp; around the /content/images/fieldlookup.gif image to call request LookupProduct. &nbsp;<br /><br />&nbsp; In your controller, put a request-map and a view-map for this target <br />&nbsp;&nbsp;&nbsp; &lt;request-map uri="LookupProduct"&gt;&lt;security auth="true" https="true"/&gt;&lt;response name="success" type="view" value="LookupProduct"/&gt;&lt;/request-map&gt;<br />&nbsp;&nbsp;&nbsp; &lt;view-map name="LookupProduct" page="component://product/widget/catalog/LookupScreens.xml#LookupProduct" type="screen"/&gt;<br /><br />&nbsp; The screen appears to be just a regular OFBIZ screen widget definition.&nbsp; The typical lookup screen has two sections: a lookup fields form<br />&nbsp; and a list-of-results form.<br /><br />&nbsp; The lookup field form is just a regular form, except the entry fields may use &lt;text-find/&gt; instead of &lt;text/&gt; to generate the<br />&nbsp; Begins With/Contains/Ignore Case etc. etc. options next to the text entry box<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="productId" title="${uiLabelMap.ProductProductId}"&gt;&lt;text-find/&gt;&lt;/field&gt;<br />&nbsp; The target of this form should be the same as before, ie "LookupProduct" &nbsp;<br /><br />&nbsp; The list-of-results form is also just a regular list form with the display fields, except for the field which should cause a value<br />&nbsp; to be set back on the original form, you need a &lt;hyperlink &gt; tag with target="" attribute to call javascript:set_values() <br />&nbsp; with the values to set, as in:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="productId" title=" " widget-style="buttontext" use-when="isVirtual==null||&amp;quot;${isVirtual}&amp;quot;.equals(&amp;quot;N&amp;quot;)"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;hyperlink also-hidden="false" target-type="plain" description="${productId}" target="javascript:set_values('${productId}', '${internalName}')"/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/field&gt;<br />&nbsp; or:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="partyId" title="${uiLabelMap.PartyPartyId}"&nbsp; widget-style="buttontext"&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;hyperlink also-hidden="false" target-type="plain" description="${partyId}" target="javascript:set_value('${partyId}')"/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/field&gt;<br /><br />&nbsp; Note that target-type is very important.&nbsp; It tells OFBIZ not to put the &lt;@ofbizUrl&gt; tag in front of it.<br />&nbsp; <br />* How to control how the lookups work<br /><br />&nbsp; &lt;text-find&gt; has a default-option attribute and an ignore-case attribute.&nbsp; default-option is set by default to "like" but can be set to "contains", "equals", and "empty"<br />&nbsp; ignore-case is by default set to "true" but can be turned off and set to "false". &nbsp;<br /><br />* How to reuse list form for both lookup and list<br /><br />&nbsp; 1.&nbsp; use the use-when directive to check if a field has been set (not just check for null, but actually for its value)<br />&nbsp; 2.&nbsp; do a &lt;set field="isLookup" value="true|false" global="true"&gt; in the top-level decorator of both your LookupScreens.xml and your CommonScreens.xml<br /><br />* What if you have a list-name and list-iterator-name for list form?<br /><br />&nbsp; The list-iterator-name takes precedence over the list-name.&nbsp; (see ModelForm.java renderItemRows method.)<br /><br />* How to use FTL with form-widget<br /><br />&nbsp; Right now the best way is to tell the form not to generate the form header or trailer, and then use the screen widget<br />&nbsp; to piece it together with some FTL.&nbsp; This can be done with a skip-start="true" and skip-end="true" attributes of &lt;form ..&gt;<br /><br />* A word about error messages<br /><br />&nbsp; Sometimes you'll get a message like: <br />org.xml.sax.SAXParseException: Attribute "widget-style" was already specified for element "field". (Error rendering included form named [MyForm] at location [component://.../MyForms.xml]<br /><br />&nbsp; BE CAREFUL!&nbsp; It may or may not be that particular form in that Forms.xml file.<br /><br />* How to select only the fields required for our target service from the input map<br /><br />&nbsp; &lt;auto-fields-service service-name="serviceToInvoke" default-field-type="display|edit|find|hidden"/&gt;<br /><br />&nbsp; If we get our data from a map other than the default, specify it with map-name="otherMap"<br /><br />* How to select only the fields in a given entity from the input map<br /><br />&nbsp; &lt;auto-fields-entity entity-name="Entity" default-field-type="display|edit|find|hidden"/&gt;<br /><br />* Fancy formatting of list forms: see http://jira.undersunconsulting.com/browse/OFBIZ-655 for some examples of fancy formatting for list forms. Here's a quic example,<br /><br />&nbsp; &lt;form name="BigListForm" type="list"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default-table-style="cssStyleForTable" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; header-row-style="cssStyleForHeader" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; even-row-style="rowWhite" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; odd-row-style="rowLightGray"&gt;<br /><br />* Paginated forms - for when your list is too large and you need [Previous] and [Next] to page through results.<br />Note that pagination is automatic if you set viewSize and viewIndex in your screen and set the paginate-target in the form.&nbsp; The rest of these settings are for<br />"customizing" your pagination:<br /><br />&nbsp; &lt;form name="BigListForm" type="list"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; paginate-target="${ URL where Prev and Next buttons should link to }" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; paginate-target-anchor="${ attaches text as an anchor to the target after URL parameters }" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; paginate-size-field="bigListSize" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; paginate-index-field="bigListIndex"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; paginate-previous-label="${ text for [Previous] link }" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; paginate-next-label="${ text for [Next] link}" <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; paginate-previous-style="cssStyleForPrevious"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; paginate-next-style="cssStyleForNext"<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ......<br /><br />This group of form attributes provides you with complete control over pagination. The&nbsp; minimal configuration<br />for one list form on a page is simply,<br /><br />&nbsp;&nbsp;&nbsp;&nbsp; paginate-target=" where you want [Previous] and [Next] to go "<br /><br />For multiple lists on a single page, it is necessary to provide different -size-field and -index-field<br />parameter names for each. If you don't, then all lists will use the VIEW_SIZE and VIEW_INDEX parameters<br />to paginate. This will have the undesired effect of advancing all lists by one page if you click on<br />[Next] for any list! <br /><br />And while you're at it, give each list a different -target-anchor. This will append<br />the anchor, say "bigListForm" to the UR.&nbsp; The result will be,<br /><br />&nbsp;&nbsp;&nbsp; URL?parameters=foobar#bigLisForm<br /><br />Then you can use&nbsp; &lt;a name="anchorName"&gt; in your ftl to make the [Previous] and [Next] buttons jump to that<br />part of the document rather than the top of the page.<br /><br />If you want a name other than Previous or Next, say for localization, or you'd rather use "&lt;&lt;" and "&gt;&gt;"<br />instead, you can specify the text and the CSS style for the buttons with the -label and -style attributes.<br /><br />* How to select null values<br /><br />Sometimes you need to do a query like "SELECT ... WHERE value IS NULL".&nbsp; You can do this with entity-constraint<br />in the form (or screen) widget by using a "null" which is already in the environment, like this:<br /><br />&lt;entity-options entity-name="CostComponentType" description="${description}"&gt;<br />&nbsp; &lt;entity-constraint name="parentTypeId" oeprator="equals" env-name="null"/&gt;<br />&lt;/entity-options&gt;<br /><br />* List iterator and list<br /><br />Beginning with OFBiz r 7451 (after opentaps 0.9), the list-iterator-name attribute for &lt;form ..&gt; is deprecated.<br />list-name="" will now accept either List or EntityListIterator.&nbsp; If you are using the performFind name, the<br />list-name must equal "listIt".<br /><br />* How to set the alignment for the content of a column in a list form*<br /><br />Use the field's attribute widget-area-style.<br />For example, to right align a field:<br /><br />&lt;field name="postedBalance" widget-area-style="tabletextright" widget-style="tabletext"&gt;<br />&lt;display type="currency" currency="${defaultCurrencyUomId}"/&gt;<br />&lt;/field&gt;&nbsp;&nbsp; &nbsp;<br /><br />* You can add a special html characters pretty easily, like this:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;!-- a cool way to show a check mark for reconciled transactions --&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="reconciled" title="" widget-area-style="tabletext" use-when="reconcileStatusId.equals(&amp;quot;AES_NOT_RECONCILED&amp;quot;)"&gt;&lt;display description="-"/&gt;&lt;/field&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;field name="reconciled" title="" widget-area-style="tabletext" use-when="reconcileStatusId.equals(&amp;quot;AES_RECONCILED&amp;quot;)"&gt;&lt;display description="✓"/&gt;&lt;/field&gt;d</div><img src ="http://www.blogjava.net/liangcmwn/aggbug/353122.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/liangcmwn/" target="_blank">liangcmwn</a> 2011-06-28 09:16 <a href="http://www.blogjava.net/liangcmwn/articles/353122.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>