Custom Unit: Difficult example in Guide ... any suggestions?

02 May '13, 09:49 AM
10,031 Views
Forum Forum Starter - Level 2

Hi, I've struggled through the Custom Unit Guide and have made some progress. I say the example in the Custom Unit Guide is poor because the examples vary between the input, output and logic so you have to make it up a bit as you go.

I have two questions.

QUESTION 1

I have had success with:
- creating the Input.template parameter so that it when included in my main project I can see it in the Link Coupling as would be expected.
- creating a Selector Unit on a database entity to pass the Oid value to the Input.template parameter. (I know this works because I also link to a Content Unit and it displays the correct database entry)
- creating the Logic template to expose the Unit's Id, Name and also a Sub Unit (a Context Parameter set to the UserCtxParam ... more on that below in Question 2).
- retrieving the Unit Name, Id and at least the literal string "UserCtxParam" inside the <unitname>Server.java class when calling DescriptorHelper.getChildValue() as per the Guide.

My problem is that I can't find how to access the value of the new Input.template parameter in the Logic.template so that it can be referenced also using the DescriptorHelper.

Any guidance would be greatly appreciated!

QUESTION 2

How does the UserCtxParam work? I would have thought that there if you create a Sub Unit Context Parameter (set to the UserCtxParam) then you would get something like an Oid for a value, or at least a UserObject accessible through the same XML via DescriptorHelper. I did try a quick HttpSessionListener like in the getActiveUsers() example but this can't be the way to go or why bother putting in a UserCtxParam as a Unit Attribute in the first place?!

Any help on getting the User Oid primary key (of the current user) into the Custom Unit Service class (or Bean class) would be greatly appreciated.

Thanks in advance Aiden

PS - QUESTION 3: Has anyone successfully gotten a custom unit to accept an input.template parameter at all?

 
x 0
Follow
Answer Answer at this question and get points!
Forum Hero - Level 9

Hi,

if you want to pass the value of the ""UserCtxParam"" to your unit I suggest you to define the input parameter in the input template and retrieve the value in similar way like the uri:

String uri = BeanHelper.asString(operationContext.get(getId() + "".uri""));

In fact the method like this

DescriptorHelper.getChildValue(descr, ""Host"", true, this);

refers to the parameter defined as Property (visible in the Properties View). If you define it in the input.template you can set the value on the incoming Link. In this way you can retrieve the value of the Context Parameter by the Get Unit and pass it to your custom unit.

For more details about the Context Parameters you can refer to this article of the wiki: Context Parameters

   
x 1
Forum Starter - Level 2

Hi,

Firstly THANK YOU!!! This has saved me hours and put me on the right track. I now have the UserOid as a input.template parameter and have the UserCtxParam correctly coupled and retrieved. I also have my SignOid coming in too!

For anyone following this and still a bit confused, the following points:

1) It's not super clear in the example (to me), but for the input.template parameters, you don't need to specify associate logic.template entries but you must access them in the execute() method and NOT the constructor.

Also, I was trying to access them in the constructor using the line below (which did not work):

String theSignOid = DescriptorHelper.getChildValue(descr, "SignOid", true, this);

2) Also be mindful if you start by building the Hello World Unit tutorial. This Guide has different parameter names for the (ClassName)UnitService.java file. The BeanHelper method above must go in the execute() method (not the constructor) but the Map parameter name for the first parameter is different to the Guide. I had to use:


theUserId = BeanHelper.asString(pageContext.get(getId() + ".UserOid"));


instead of:
theUserId = BeanHelper.asString(operationContext.get(getId() + ".UserOid"));

One final question(s) please? What does the Parameters collection contain? Where do the come from or how are they populated? There isn't any description there of this and it's not clear if this is part of the standard parameter passing mechanism or if it's specific to this Guide's example.

 
x 0
Answer at this question and get points!

Related questions