JSON Parameters set from javascript at runtime

97 views
Skip to first unread message

Steve Pisani

unread,
May 8, 2013, 3:43:32 AM5/8/13
to intersys...@googlegroups.com

Hi,

 

Before invoking the javascript client side json.getContentObject() method, I want to see the parameters for the json component.  Their values sit in text boxes on my page.  Two text boxes:

 

<text id="objectClass" label="ClassName"  />
<text id="objectID" label="Id"  />

 

I have tried the following:

 

var jprov=zen("json")

jprov.parameters['classname'].value=zen("objectClass").value
                jprov.parameters['objectID'].value=zen("objectID").value

 

 

however, in the callback server side method pointed to by the attribute OnGetTargetObject:

 

Method GetJSONObject(ByRef pParameters, Output pObject As %Library.RegisteredObject) As %Status
{
                set tStatus=$$$OK
               
                set tClass=$g(pParameters("classname"))
                set tID=$g(pParameters("objectID"))
               
                quit:tClass="" $$$OK
                quit:tID="" $$$OK
               
               
                /// simplest case - return object
                set pObject=$classmethod(tClass,"%OpenId",tID)
               
                quit tStatus
}

 

This always QUITS, because ‘tClass’ and indeed pParameters is empty.

 

How can I programmatically set the parameters of the <jsonProvider> component from javascript ??

 

Thanks in advance –

 

Steve Pisani

Dale du Preez

unread,
May 8, 2013, 9:47:14 AM5/8/13
to intersys...@googlegroups.com
Hi Steve,

How have you defined your jsonProvider in your XML? The expected parameters must be specified as <parameter /> children of the jsonProvider element.

Dale

P.S. The sample you sent out is very insecure! You will likely want to do some sanity checking of the class name before you open up all persistent objects to the user, especially since they can manipulate the client-side properties using any Javascript debugger or console.
--
You received this message because you are subscribed to the Google Groups "InterSystems: Zen Community" group.
To post to this group, send email to InterSys...@googlegroups.com
To unsubscribe from this group, send email to InterSystems-Z...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/InterSystems-ZEN?hl=en
Zen Community Terms and Conditions: http://groups.google.com/group/InterSystems-ZEN/web/community-terms-and-conditions
---
You received this message because you are subscribed to the Google Groups "InterSystems: Zen Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to intersystems-z...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Steve Pisani

unread,
May 8, 2013, 8:53:13 PM5/8/13
to intersys...@googlegroups.com

Hi Dale –

 

Like this:

 

<jsonProvider id="json" OnGetTargetObject="GetJSONObject" >
<parameter paramName="classname" id="parClassname" />
<parameter paramName="objectID" id="parObjectID"/>
</jsonProvider>

 

Steve

Dale du Preez

unread,
May 8, 2013, 9:06:45 PM5/8/13
to <intersystems-zen@googlegroups.com>
Hi Steve,

I generally set the parameter value after getting the parameter by its ID. I am sure I ran into similar trickiness when using parameters... and decided to go that way instead!

So something like:
zen('parClassname').value = 'yourClass';

Dale

Steve Pisani

unread,
May 9, 2013, 9:21:27 PM5/9/13
to intersys...@googlegroups.com

Ok thanks.

 

For reference therefore:

 

Addressing the parameter directly rather than as an element of the property array associated with the jsonProvider component solved the problem:

 

So this works

 

                zen(<idOfParameter>).value = <value>

 

and this does not:

 

var jprov=zen("json")

jprov.parameters[<paramName>].value=<value>

 

 

Thanks Dale.

(in truth I thought I had tried that and dismissed it,  but I obviously did not…!)

Reply all
Reply to author
Forward
0 new messages