How complex can Custom Unit output be?

03 May '13, 09:07 AM
15,947 Views
Forum Forum Starter - Level 2

Hi, I'm trying to create a dynamic custom unit and wonder if anyone can confirm whether I can achieve this. Does anyone have an example of a custom unit that contains sub-units, specifically a entry unit with selector field?

I want a custom unit to be able to query a database and populate a selection field on an Entry Unit. I want to be able to programmatic-ally create the label text on load.

I want to be able to have a link from this unit to a database add unit using Ajax, and upon OK Link back to the form, be able to re-render the unit so that it is then blank (viz: 0nce an option is selected and saved, then the user can't save again).

Bonus round: can the options provided could be displayed as radio option buttons instead of a combo drop-list?

 
x 0
Follow
Answer Answer at this question and get points!
Forum Starter - Level 2

I ended up using a script in the layout template to query the database at generation time directly. Groovy sql didn't work because I kept getting errors on the import (despite the jar being in the declarations of the project, in the <web-inf> directory, etc.

Here is the code in the script, including how to get the value onto the output html:

<% import java.sql.Connection import java.sql.DriverManager import java.sql.ResultSet import java.sql.Statement import javax.sql.DataSource

import org.apache.derby.drda.NetworkServerControl;

def signOid = unit["SignId"]

Class.forName("org.apache.derby.jdbc.ClientDriver"); NetworkServerControl serverControl = new NetworkServerControl(InetAddress.getByName("localhost"),1527); serverControl.start (null); Connection conn = DriverManager.getConnection('jdbc:derby://localhost:1527/StigmergyDb;password=user');

def sql = "SELECT COUNT(Value) FROM CONTRIBUTION WHERE Sign_Oid = " + signOid; Statement stmt = conn.createStatement(); ResultSet options = stmt.executeQuery(sql); options.next();

def optionCount = 0 def queryError = "" try { optionCount = options.getInt(1); } catch (Exception e) { optionCount = -1; queryError = e.toString(); }

setHTMLOutput()

%>

// Here is how to output the count outside of the groovy script. // The provided WebRatio example shows already how to use the variable // value in groovy conditions option Count = <%= optionCount%>

   
x 0
Forum Starter - Level 2

Ok, previous question resolved:

I've created a custom unit, and the service class populates the associated bean class with the required database records. It uses a parameter sub-unit to provide context to the services sql WHERE clause. I'm using a JSP <c:foreach> iterator in the unit's style template to provide the LinkedHashMap of primary key and descriptions as <OPTION> nodes for the drop list <SELECT> field. This all works very well.

The next question is: Can the style unit's groovy script access the same run time instances of the bean to determine whether a part of page is hidden based on a bean property. E.g: Using ${<wr:UnitId/>.hasMultipleOptions}") within an <% if (...) {%> or is it only possible to use these run time values in the JSP "<c:if ... " scripts? From what I understand the generation of conditional output in the template can only occur in the Groovy script and not the JSP (as you would only imagine).

The "Getting Started With the Style Unit" help page describes that a unit's bean can be accessed using the Groovy script, but it also says "Groovy scriplets can access to the Layout XML and are compiled before the WR tags". This would mean that you don't have access to the runtime WR tag at generation time. The example given only shows using design time properties of the bean (viz: useEmptyUnitMessage).

Can anyone confirm this please?

 
x 0
Answer at this question and get points!

Related questions

Ayuda Simple List Component Layout personalizado Button to go on another page Criptare dati sensibili nel database CSV Component with utf8 encoding Custom components Custom descriptors Custom Plug-in Custom Time Unit Custom Unit and AJAX / SOAP Custom Unit: Difficult example in Guide ... any suggestions? Data flow from a page which is not visible anymore Dynamic link labelling for Custom Unit Encoding Confirm Dialog file analysis then update MySQL database Google Map Unit Guardar Saltos de LINEA How can I add a credit card payment gateway or integrate paypal in my web app logic? how can i open a pdf file using download dialog How to run the example from Custom Unit Guide? Is there any custom unit store or repository? Do you create/sell custom units? java.lang.NullPointerException More Custom Unit questions: example of Content and Operation Unit? Need help with Landmark Overlays for Google Map Unit. Personalizzazione del login component Problema Invocation Unit Problems with Custom components: Can't get values from output parameters on ok flow. "Run Now" on a job scheduled to run later Selezione sul giorno "Events Planning" Status ProcessInstance and activityInstance in spanish Stored procedure component Twitter Unit - Get Geo location of twitt Usage of the Gantt Unit ¿Visor de imágenes y reproductor de video para la versión 7.2? Image viewer and video player for version 7.2? Web project without initial login form - how to create custom logins? Webratio Add-ons no permite login Webratio don't recognize JSON library WebRatio Platform 7.2 Community Cloud Edition