How to pass parameter into inner ui:call

17 views
Skip to first unread message

AdrianP

unread,
Jul 16, 2019, 3:34:42 PM7/16/19
to TopBraid Suite Users
Hello,

I'm trying to create the following JSON structure for return from a web service call:

"players" : [
    {
"playerId" : "123",
    "playerName" : "JD Martinez",
"playerCurrentTeam" : "Boston Redsox",
"teamId" : "1000",
"playerFormerTeams" : [
    "Diamondbacks",
"Tigers",
"Astros"
]
},
    {
"playerId" : "456",
    "playerName" : "Chris Sale",
"playerCurrentTeam" : "Boston Redsox",
"teamId" : "1000",
"playerFormerTeams" : [
    "Whitesox",
"Dodgers"
]
}
]

I'm being given access to two SPIN templates to call:
1. returns all current players for a team whose value is passed in as a parameter.
2. returns all former teams for player whose value is a result of the id in the first template (1000 in the case above).


                    <swon:Value arg:name=\"players\">
    <swon:Array>
<swon:Object>
<ui:call arg:team_id=\"{= ?team_id }\" ui:template=\"{= int-spin:PlayersByTeamIdTemplate }\" ui:varName=\"rs\">
<ui:forEach ui:bindVars="?playerId,?playerName,?playerCurrentTeam,?teamId" ui:resultSet="{= ?rs }">
<swon:Value arg:name="playerId" arg:value="{= ?playerId }" />
<swon:Value arg:name="playerName" arg:value="{= ?playerName }" />
<swon:Value arg:name="playerCurrentTeam" arg:value="{= ?playerCurrentTeam }" />
<swon:Value arg:name="teamId" arg:value="{= ?teamId }" />
<swon:Value arg:name=\"playerFormerTeams\">
<ui:call arg:pft=\"{= former_team:1000 }\" ui:template=\"{= int-spin:FormerTeamsByIdTemplate }\" ui:varName=\"pft_rs\">
<swon:RSArray arg:resultSet=\"{= ?pft_rs }\"/>
</ui:call>
</swon:Value>
</ui:forEach>
</ui:call>
</swon:Object>
</swon:Array>
                    </swon:Value>
How do I pass in the teamId result from the first query (PlayersByTeamIdTemplate) to the second query (FormerTeamsByIdTemplate)?
In the example above I've hard-coded it (former_team:1000 to prove it works and it does (there is a prefix for "former_team").

I've tried things like arg:pft=\"{= former_team:?teamId }\" but that doesn't work.

Thanks...

Holger Knublauch

unread,
Jul 16, 2019, 7:21:39 PM7/16/19
to topbrai...@googlegroups.com

Hi Adrian,

Have you also tried arg:pft="{= ?teamId }"? If that doesn't work, could you send us the definition of the int-spin:FormerTeamsByIdTemplate query so that I can see what else could be mismatching?

Looking at the snippet above I also do wonder why the " characters are sometimes escaped with \ and sometimes not...

Regards,
Holger


AdrianP

unread,
Jul 16, 2019, 8:18:38 PM7/16/19
to TopBraid Suite Users
Thanks, Holger.

I actually tried to simplify the real code but in doing so I realize I made it misleading.  The parameter for the outer ui:call is not teamId in the actual use case.  It's something that could return multiple teamIds, say something like jerseyColor.  Multiple teams could result but I'd be looking for the players and their former teams for multiple teams by the current teamId.  Does that make sense?

I hadn't noticed the inconsistently escaped double-quotes. They are like that in the real code too.  Seems like that would cause issues but it's (mostly) working as expected except for the parameter to the inner ui:call.  Worth noting that with my small sample set so far I'm only getting one "team" back so far so perhaps the quote issue would reveal itself once I expand my testing.

Should I be trying to ui:concat with formerTeam: and ?teamId   ?   I played around with that but could not get the syntax right.

Thank you, Adrian.

Holger Knublauch

unread,
Jul 16, 2019, 8:34:16 PM7/16/19
to topbrai...@googlegroups.com

Ah Ok, if the issue is to convert a string (teamId) to a URI then maybe try

{= IRI(CONCAT("http://namespace-whatever#", str(?teamId))) }

Holger

--
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/f308799b-25a1-449c-9f11-564f1c2a8189%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

AdrianP

unread,
Jul 18, 2019, 5:23:08 PM7/18/19
to TopBraid Suite Users
Thanks, Holger.  That did the trick.
To unsubscribe from this group and stop receiving emails from it, send an email to topbrai...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages