<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.infinite-erp.co.id/index.php?action=history&amp;feed=atom&amp;title=How_to_create_a_Datasource_Widget</id>
	<title>How to create a Datasource Widget - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.infinite-erp.co.id/index.php?action=history&amp;feed=atom&amp;title=How_to_create_a_Datasource_Widget"/>
	<link rel="alternate" type="text/html" href="https://wiki.infinite-erp.co.id/index.php?title=How_to_create_a_Datasource_Widget&amp;action=history"/>
	<updated>2026-04-06T15:13:15Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.infinite-erp.co.id/index.php?title=How_to_create_a_Datasource_Widget&amp;diff=2755&amp;oldid=prev</id>
		<title>Wikiadmin: Created page with &quot;== Introduction ==  This How To article describes how to create a new widget that fetches its data from an user-defined datasource. The generic documentation about widgets can...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.infinite-erp.co.id/index.php?title=How_to_create_a_Datasource_Widget&amp;diff=2755&amp;oldid=prev"/>
		<updated>2021-12-16T03:05:50Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Introduction ==  This How To article describes how to create a new widget that fetches its data from an user-defined datasource. The generic documentation about widgets can...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Introduction ==&lt;br /&gt;
&lt;br /&gt;
This How To article describes how to create a new widget that fetches its data from an user-defined datasource. The generic documentation about widgets can be found [[Widgets|here]].&lt;br /&gt;
&lt;br /&gt;
A related How to article explaining how to embed a widget into a generated Window/Tab can be found in this [[How_to_embed_a_Widget_into_a_Window_Tab|link]].&lt;br /&gt;
&lt;br /&gt;
== Developing the datasource ==&lt;br /&gt;
&lt;br /&gt;
The new datasource like all developments must belong to a module. [[How_To_Create_and_Package_a_Module#Creating_a_Module|Create a new one]] if you still don't have it.&lt;br /&gt;
&lt;br /&gt;
=== Implementing the Java datasource ===&lt;br /&gt;
&lt;br /&gt;
{{(!)|By default Datasources cannot be executed by Portal users. To make them accessible for portal users they must implement &amp;lt;code&amp;gt;org.openbravo.portal.PortalAccessible&amp;lt;/code&amp;gt; interface.}}&lt;br /&gt;
&lt;br /&gt;
This test datasource is going to return the following Data:&lt;br /&gt;
&lt;br /&gt;
Row 1 - 1&lt;br /&gt;
&lt;br /&gt;
Row 2 - 2&lt;br /&gt;
&lt;br /&gt;
The first column is a String, and the second column is a Number.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Java&amp;quot;&amp;gt;&lt;br /&gt;
package org.openbravo.datasourceWidget;&lt;br /&gt;
&lt;br /&gt;
import java.util.ArrayList;&lt;br /&gt;
import java.util.LinkedHashMap;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
import java.util.Map;&lt;br /&gt;
&lt;br /&gt;
import org.openbravo.service.datasource.ReadOnlyDataSourceService;&lt;br /&gt;
&lt;br /&gt;
public class TestDatasourceForWidget extends ReadOnlyDataSourceService {&lt;br /&gt;
&lt;br /&gt;
  /**&lt;br /&gt;
   * Returns the count of objects based on the passed parameters.&lt;br /&gt;
   * &lt;br /&gt;
   * @param parameters&lt;br /&gt;
   *          the parameters passed in from the request&lt;br /&gt;
   * @return the total number of objects&lt;br /&gt;
   */&lt;br /&gt;
  @Override&lt;br /&gt;
  protected int getCount(Map&amp;lt;String, String&amp;gt; parameters) {&lt;br /&gt;
    return 2;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  @Override&lt;br /&gt;
  protected List&amp;lt;Map&amp;lt;String, Object&amp;gt;&amp;gt; getData(Map&amp;lt;String, String&amp;gt; parameters, int startRow,&lt;br /&gt;
      int endRow) {&lt;br /&gt;
    List&amp;lt;Map&amp;lt;String, Object&amp;gt;&amp;gt; result = new ArrayList&amp;lt;Map&amp;lt;String, Object&amp;gt;&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
    Map&amp;lt;String, Object&amp;gt; firstRow = new LinkedHashMap&amp;lt;String, Object&amp;gt;();&lt;br /&gt;
    firstRow.put(&amp;quot;column1&amp;quot;, &amp;quot;Row 1&amp;quot;);&lt;br /&gt;
    firstRow.put(&amp;quot;column2&amp;quot;, 1);&lt;br /&gt;
    result.add(firstRow);&lt;br /&gt;
&lt;br /&gt;
    Map&amp;lt;String, Object&amp;gt; secondRow = new LinkedHashMap&amp;lt;String, Object&amp;gt;();&lt;br /&gt;
    secondRow.put(&amp;quot;column1&amp;quot;, &amp;quot;Row 2&amp;quot;);&lt;br /&gt;
    secondRow.put(&amp;quot;column2&amp;quot;, 2);&lt;br /&gt;
    result.add(secondRow);&lt;br /&gt;
&lt;br /&gt;
    return result;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Defining the datasource in the application dictionary ===&lt;br /&gt;
&lt;br /&gt;
Select the module where your developments belong, give a name to the datasource, and specify its java class name.&lt;br /&gt;
&lt;br /&gt;
[[Image:Datasource.png|thumbnail|600px|center|Datasource definition in the application dictionary.]]&lt;br /&gt;
&lt;br /&gt;
== Developing the widget ==&lt;br /&gt;
&lt;br /&gt;
The new widget like all developments must belong to a module. [[How_To_Create_and_Package_a_Module#Creating_a_Module|Create a new one]] if you still don't have it.&lt;br /&gt;
&lt;br /&gt;
==== Create the widget ====&lt;br /&gt;
&lt;br /&gt;
All the widget definition is done in the ''Widget'' window.&lt;br /&gt;
&lt;br /&gt;
Create a new ''widget class'':&lt;br /&gt;
&lt;br /&gt;
;Widget title: is the title that appear on the widget header. Put here a short sentence that describes the widget.&lt;br /&gt;
;Superclass &amp;amp; Widget superclass: leave the flag unchecked and select the ''Query/List'' superclass widget from the drop/down menu.&lt;br /&gt;
;Height: set up any value, the Query/List override this value setting up the height based on the number of rows.&lt;br /&gt;
;Enable for all users: Check it if the widget has to be available to all roles. Otherwise leave unchecked and give access to the desired roles on the ''Widget Access'' tab.&lt;br /&gt;
&lt;br /&gt;
As the widget is implementing a superclass widget some parameters might have been created to the new widget. On the ''Query/List'' case the ''Number of Rows'' parameter is created automatically. This sets the number of rows visible on the grid.&lt;br /&gt;
&lt;br /&gt;
[[Image:DatasourceWidgetDefinition.png|thumbnail|600px|center|Widget definition]]&lt;br /&gt;
&lt;br /&gt;
==== Select the datasource ====&lt;br /&gt;
&lt;br /&gt;
The datasource is selected on the ''Query'' tab. Select the Datasource option in the Type field, and then select the previously defined selector in the Datasource combo.&lt;br /&gt;
&lt;br /&gt;
[[Image:SettingTheWidgetDatasource.png|thumbnail|600px|center|Setting the datasource of the widget.]]&lt;br /&gt;
&lt;br /&gt;
==== Create the columns ====&lt;br /&gt;
&lt;br /&gt;
Once the query is defined and the necessary parameters created is time to define the columns that will be available on the grid on the ''Column'' tab.&lt;br /&gt;
&lt;br /&gt;
In this example two column have the be defined. The first one is a string named column1 and the second one is a number named column2 (see Java datasource definition).&lt;br /&gt;
&lt;br /&gt;
[[Image:DatasourceColumns.png|600px|center|Datasource widget example.]]&lt;br /&gt;
&lt;br /&gt;
== Adding the widget to your workspace ==&lt;br /&gt;
&lt;br /&gt;
Once the widget is done if you have access to it you are able to add it to your workspace. It is not needed to compile anything.&lt;br /&gt;
&lt;br /&gt;
On the ''Add widget'' menu select your new widget. If all the parameters have a default value or are fixed you will see the widget added on the workspace. Otherwise you will be prompted to fill the parameters.&lt;br /&gt;
&lt;br /&gt;
This is the final result:&lt;br /&gt;
&lt;br /&gt;
[[Image:DatasourceWidgetExample.png|center|Datasource widget example.]]&lt;br /&gt;
&lt;br /&gt;
[[Category:HowTo]]&lt;/div&gt;</summary>
		<author><name>Wikiadmin</name></author>
		
	</entry>
</feed>