Ofbiz
Wednesday 12 March 2014
Ofbiz: Working with Ofbiz FTL(FreeMarker Template Languag...
Ofbiz: Working with Ofbiz FTL(FreeMarker Template Languag...: How to create a variable in FTL as XML <#assign vaiableToUse = objectClass.getMethod()> How to fetch the data from an entity ...
Wednesday 29 January 2014
Working with Ofbiz FTL(FreeMarker Template Language) tags.
How to create a variable in FTL as XML
<#assign vaiableToUse = objectClass.getMethod()>How to fetch the data from an entity
<#assign genericObject = delegator.findByPrimaryKey("Entity", Static["org.ofbiz.base.util.UtilMisc"].toMap("keyColumnName", valueFromVariable))>Comment a line in FTL
<#-- Insert comment in between -->
Iterate a list
<#list facilityContactMechs as facilityContactMech></#list>
If condition
<#if object.getValue() == "STATIC VALUE">
${printSomething}
</#if>
Using a class
<#assign object= Static["org.ofbiz.package.AnyClass"].getMethodOfCalss(parameter)>Checking of data (Exixtence and content)
<#if object.Value?has_content>
${object.Value?if_exists}
</#if>
Monday 20 January 2014
Working with Ofbiz forms
Adding on click event on form
<field name="submitButton" widget-style="find" title="Print" event="onclick" action="javascript:var field=document.Form.inputElement; var tmp=field.value;if (condition) { do what you want };return true;">
<submit button-type="button"/>
</field>
Changing the target by conditions in form
<form name="FromName" type="single" target="likeUpdatetarget" default-map-name="mapName"
header-row-style="header-row" default-table-style="basic-table">
<alt-target use-when="variableParameter==null" target="likeCreateTarget"/>
<fields></fields>
.................
</form>
For dorp down in Forms
<drop-down allow-empty="false">
<entity-options entity-name="Entity" key-field-name="columnName" description="${entityColumnId} [${enttityColumnName}]">
<entity-constraint name="filterByColumne" operator="equals" value="${parameters.entityId}"/>
<entity-order-by field-name="entityColumn"/>
</entity-options>
</drop-down>
<set field="variableName" value="${bsh:
import org.ofbiz.entity.GenericValue;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.util.EntityUtil;
GenericValue gv= EntityUtil.getFirst(delegator.findByAnd("EntityName",UtilMisc.toMap("ColumnName",value)));
if(result==null) return ;
if(result!=null) variable= gv.getString("columnName");
return output;
}"/>
Working with Ofbiz forms
<display description="Y" type="text" default-value="N"/>
</field>
<field name="submitButton" widget-style="find" title="Print" event="onclick" action="javascript:var field=document.Form.inputElement; var tmp=field.value;if (condition) { do what you want };return true;">
<submit button-type="button"/>
</field>
Changing the target by conditions in form
<form name="FromName" type="single" target="likeUpdatetarget" default-map-name="mapName"
header-row-style="header-row" default-table-style="basic-table">
<alt-target use-when="variableParameter==null" target="likeCreateTarget"/>
<fields></fields>
.................
</form>
For dorp down in Forms
<drop-down allow-empty="false">
<entity-options entity-name="Entity" key-field-name="columnName" description="${entityColumnId} [${enttityColumnName}]">
<entity-constraint name="filterByColumne" operator="equals" value="${parameters.entityId}"/>
<entity-order-by field-name="entityColumn"/>
</entity-options>
</drop-down>
For getting data using delegator in forms
in action :<set field="variableName" value="${bsh:
import org.ofbiz.entity.GenericValue;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.util.EntityUtil;
GenericValue gv= EntityUtil.getFirst(delegator.findByAnd("EntityName",UtilMisc.toMap("ColumnName",value)));
if(result==null) return ;
if(result!=null) variable= gv.getString("columnName");
return output;
}"/>
Creating a FORM
1. include in screen
<include-form name="FormName" location="component://Form.xml"/>
2. Create a FORM . *Form.xml
<form name="FormName" type="single" default-map-name="" target="action" title="Title" header-row-style="header-row" default-table-style="basic-table">
<field name="FieldName"><hidden/></field>
<field position="1" name="Field1" ><text default-value="${fieldValue}"> </text> </field>
<field position="2" name="buttonName" title="Title" widget-style="smallSubmit"><submit button-type="button"/></field>
</form>
3. Populating form inside Action tag
<actions>
<entity-and entity-name="EntityName" list="populatedList">
<field-map field-name="columnName" from-field="columnValue"/>
</entity-and>
<set field="object" value="${groovy: return org.ofbiz.entity.util.EntityUtil.getFirst(populatedList).column;}" default-value="null"/>
</actions>
4. you can also use the auto field tag inside a form to auto populate any Entity with its field.
<auto-fields-entity entity-name="EntityName" default-field-type="display"/>
*******************************************************************************
To make a validation on the forms fields
"USE-WHEN"
<field name="name" title="title" widget-area-style="centered" use-when="object!=null&&object.equals("SOME_VALUE")"><display description="Y" type="text" default-value="N"/>
</field>
Tuesday 14 January 2014
Code Snippets of Ofbiz while developing...
Adding a Column inside Form tag in Ofbiz xml file.
<field name="name" title="title" widget-area-style="centered" use-when="test.equals("SomeValue")">
<display description="Y" type="text" default-value="N"/>
</field>
Using Use-When attribute of Field Tag
For Conditions we use "use-when" attribute of the field tag. In this tag we write the java code to make comparisons. Like in above code snippet I have a column "test" of string type. Now for comparing or using used-when tag i write it as java comparison of a String.For calling a method from the XML file to a java class.
<call-class-method class-name="org.ofbiz.accounting.util.Util" method-name="getMethodName" ret-field="returnFieldObject">
<field field="parameterValue" type="BigDecimal"/>
<field field="parameterValue" type="BigDecimal"/>
</call-class-method>
For calling an entity with primary key in java class
GenericValue payment = delegator.findByPrimaryKey("EntityName", UtilMisc.toMap("FieldName", FieldValue));
payment.getString("column/fieldname");
Fetching data from an entity :
List<GenericValue> objectlist = delegator.findByAnd("Entity", "primaryKeyColumnName", value);
Double objectToStore = someValue;
for(GenericValue singleObject : objectlist ){
if(singleObject .getTypeOfAttribute("column_name")!=null ){
objectToStore = singleObject .getTypeOfAttribute("column_name");
break;
}
}
For Generating Sequence on Service.xml using Delegator's getNextSequenceId("")
<set field="enitity.column" value="${groovy:delegator.getNextSeqId("EntityName")}"/>
For sum of a column.
<view-entity entity-name="SampleName" package-name="packageName" title="Description">
<member-entity entity-alias="II" entity-name="Entity"/>
<alias entity-alias="II" name="testColumn1" group-by="true"></alias>
<alias entity-alias="II" name="testColumn1" group-by="true"></alias>
<alias entity-alias="II" name="testColumnForCondition1" group-by="true"></alias>
<alias entity-alias="II" name="testColumnForCondition2" group-by="true"></alias>
<alias entity-alias="IID" name="columnForSum" field="columnForSum" function="sum"/>
</view-entity>
Subscribe to:
Posts (Atom)