BBjThinClient::setUserProperties

Description

In BBj 15.00 and higher, this method sets multiple client-side properties within a given property group.

BUI logoDWC logo

See below.

Syntax

Return Value Method
void setUserProperties(Map map)
void setUserProperties(long group, Map map)
void setUserProperties(long group, String attributes, Map map)

Parameters

Parameter Description
group
  • USER_PROPERTIES_COOKIES (0)
  • USER_PROPERTIES_STORAGE (1)
  • USER_PROPERTIES_SESSION (-1)
attributes
  • A SameSite value of "Lax", "Strict", or "None".
  • In BBj 23.06 and higher, the attributes parameter can be set to a string of arbitrary cookie attribute values (e.g. "secure; partitioned").
map Map structure containing key/value pairs to be set in the specified property group.

Return Value

None.

Remarks

In BUI and DWC, USER_PROPERTIES_COOKIES maps to browser cookies with a 30-day expiration, USER_PROPERTIES_STORAGE maps to browser local storage, and USER_PROPERTIES_SESSION maps to browser session storage. Any other group value is treated as a cookie with a specified expiration timestamp (e.g. System.currentTimeMillis()+24*60*60*1000*7 is exactly 7 days from now).

In GUI, the three groups map to nodes in a Preferences tree, which doesn't allow keys or values to include any $00$ characters.

If no group is specified, the default value is taken from STBL("!USER_PROPERTIES").

In BBj 20.00 and higher, the attributes parameter can be set to a SameSite value of "Lax", "None", or "Strict" to specify the set of domains that can read a given cookie. For more information, see Google's notes for Chrome 80+. If no attributes value is specified, the default value is taken from STBL("!SAME_SITE"). The SameSite value is only meaningful in BUI and DWC.

In BBj 23.06 and higher, the attributes parameter can be set to a string of arbitrary cookie attribute values (e.g. "secure; partitioned").

When a BUI or DWC application creates a browser cookie, the cookie path attribute defaults to window.location.pathname. Some applications might want more control over the path attribute. In BBj 22 and higher, STBL("!COOKIE_PATH") can be used to specify the path value for any cookies created with setUserProperties.

Example 1

tc! = bbjapi().getThinClient()
props! = new java.util.HashMap()
props!.put("key1","value1")
props!.put("key2","value2")
tc!.setUserProperties(props!)
print tc!.getUserProperties()

Example 2

rem ' BBjThinClient setUserProperties
sysgui = unt
open (sysgui)"X0"
sysgui! = bbjapi().getSysGui()
window! = sysgui!.addWindow(25,25,550,550,"userProperties",$00090003$)
window!.setCallback(window!.ON_CLOSE,"eoj")
cookies! = window!.addRadioButton(101,25,25,150,25,"Cookies",$0024$)
cookies!.setCallback(cookies!.ON_CHECK_ON,"cookies")
storage! = window!.addRadioButton(102,200,25,150,25,"Local Storage",$0020$)
storage!.setCallback(storage!.ON_CHECK_ON,"storage")
session! = window!.addRadioButton(103,375,25,150,25,"Session Storage",$0020$)
session!.setCallback(session!.ON_CHECK_ON,"session")
pathname! = sysgui!.executeScript("window.location.pathname")
pathname$ = iff(pathname!=null(),"",str(pathname!))
rem System.err.println("window.location.pathname="+pathname$)
group! = window!.addRadioGroup()
group!.add(cookies!)
group!.add(storage!)
group!.add(session!)
group = 0, group$ = "USER_PROPERTIES_COOKIES"
window!.addStaticText(201,25,75,150,25,"Key",$$)
window!.addStaticText(202,200,75,325,25,"Value",$$)
dim key![1:5],value![1:5]
key![1] = window!.addEditBox(301,25,125,150,25,"key",$$)
value![1] = window!.addEditBox(302,200,125,325,25,"value",$$)
key![2] = window!.addEditBox(303,25,175,150,25,"",$$)
value![2] = window!.addEditBox(304,200,175,325,25,"",$$)
key![3] = window!.addEditBox(305,25,225,150,25,"",$$)
value![3] = window!.addEditBox(306,200,225,325,25,"",$$)
key![4] = window!.addEditBox(307,25,275,150,25,"",$$)
value![4] = window!.addEditBox(308,200,275,325,25,"",$$)
key![5] = window!.addEditBox(309,25,325,150,25,"",$$)
value![5] = window!.addEditBox(310,200,325,325,25,"",$$)
cookiePath! = window!.addEditBox(401,25,375,150,25,pathname$,$$)
cookiePath!.setToolTipText("Cookie path")
setUserProperty! = window!.addButton(402,200,375,150,25,"setUserProperty",$$)
setUserProperty!.setCallback(setUserProperty!.ON_BUTTON_PUSH,"setUserProperty")
getUserProperty! = window!.addButton(403,375,375,150,25,"getUserProperty",$$)
getUserProperty!.setCallback(getUserProperty!.ON_BUTTON_PUSH,"getUserProperty")
setUserProperties! = window!.addButton(404,25,425,150,25,"setUserProperties",$$)
setUserProperties!.setCallback(setUserProperties!.ON_BUTTON_PUSH,"setUserProperties")
getUserProperties! = window!.addButton(405,200,425,150,25,"getUserProperties",$$)
getUserProperties!.setCallback(getUserProperties!.ON_BUTTON_PUSH,"getUserProperties")
clearUserProperties! = window!.addButton(406,375,425,150,25,"clearUserProperties",$$)
clearUserProperties!.setCallback(clearUserProperties!.ON_BUTTON_PUSH,"clearUserProperties")
attr! = window!.addEditBox(501,25,475,150,25,"",$$)
attr!.setToolTipText("SameSite Lax|None|Strict or semicolon-delimited cookie attributes")
clear! = window!.addButton(1,200,475,150,25,"Clear",$$)
clear!.setCallback(clear!.ON_BUTTON_PUSH,"clear")
close! = window!.addButton(2,375,475,150,25,"Close",$$)
close!.setCallback(close!.ON_BUTTON_PUSH,"eoj")
tc! = bbjapi().getThinClient()
process_events
eoj:
release
cookies:
group = BBjThinClient.USER_PROPERTIES_COOKIES
group$ = "USER_PROPERTIES_COOKIES"
return
storage:
group = BBjThinClient.USER_PROPERTIES_STORAGE
group$ = "USER_PROPERTIES_STORAGE"
return
session:
group = BBjThinClient.USER_PROPERTIES_SESSION
group$ = "USER_PROPERTIES_SESSION"
return
setUserProperty:
  key$ = key![1].getText()
  value$ = value![1].getText()
  attr$ = attr!.getText()
  pathname$ = stbl("!COOKIE_PATH",cookiePath!.getText())
  tc!.setUserProperty(group,attr$,key$,value$,err=oops)
  msg$ = "setUserProperty "+group$+",attr="+attr$+","+key$+","+value$
  i = msgbox(msg$)
return
getUserProperty:
  key$ = key![1].getText()
  value$ = tc!.getUserProperty(group,key$,err=oops)
  msg$ = "getUserProperty "+group$+","+key$+" = "+value$
  i = msgbox(msg$)
return
setUserProperties:
  properties! = new java.util.HashMap()
  for i = 1 to 5
    key$ = key![i].getText()
    value$ = value![i].getText()
    if len(key$) then
       properties!.put(key$,value$)
    endif
  next i
  attr$ = attr!.getText()
  pathname$ = stbl("!COOKIE_PATH",cookiePath!.getText())
  tc!.setUserProperties(group,attr$,properties!,err=oops)
  msg$ = "setUserProperties "+group$+",attr$="+attr$+","+str(properties!)
  i = msgbox(msg$)
return
getUserProperties:
  keys! = bbjapi().makeVector()
  for i = 1 to 5
    key$ = key![i].getText()
    if len(key$) then
       keys!.add(key$)
    endif
  next i
  properties! = tc!.getUserProperties(group,keys!,err=oops)
  msg$ = "getUserProperties "+group$+","+str(keys!)+" = "+str(properties!)
  i = msgbox(msg$)
return
clearUserProperties:
  tc!.clearUserProperties(group,err=oops)
  msg$ = "clearUserProperties "+group$
  i = msgbox(msg$)
return
clear:
  for i = 1 to 5
    key![i].setText("")
    value![i].setText("")
  next i
return
oops:
  i = msgbox(errmes(-1))
return

See Also

BBjAPI

BBjCookie

BBjThinClient::getUserProperties

BBjThinClient::setUserProperty

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.