WebListBoxStyleRenderer

Hello,

I created a web app in 2021 R1 making extensive use of WebListBoxStyleRenderer/s. The WebListBoxStyleRenderer/s function well.

A few days ago, I opened, then ran the project in 2021 R2 and the WebListBox now displays a JSON string in the cells where the WebListBoxStyleRenderer/s were used instead of the value usually displayed. See below.

json

Thought it may have been fixed in 2021 R3, but issue still persists.

Is anyone else experiencing this? Still works fine in 2021 R1.

Kind regards, Andrew

Do you have a little example project to give it a look?

Hello @Ricardo_Cruz_Fernandez,

Thank you for replying.

I don’t but will create a small project easily enough overnight.

BTW, I enjoyed your 2 part blog post on the subject back in September.

Kind regards, Andrew

1 Like

Thank you @Andrew_Paul_Dickey!, glad you liked it =)

While preparing those custom cells I’ve seen from time to time it was throwing some JSON instead of the expected result, and it was an issue with my JS.

Just a guess without seeing the code, but if the JS or JSON interpreter Xojo is using has been updated since one version to another, it could be considering an “error” now, something that it was a “warning” before.

@Ricardo_Cruz_Fernandez,

I suspect you are right. When you use the renderer in 2021 R2 and R3, the data type of the contents of the cell is no longer a String. See images below:




The code (recipe for testing)

In Xojo 2021 R1 or 1.1:

Create a new web project:

  1. drag a WebListBox (ListBox2) onto the Webpage
  2. add an opening event with the following code:
'Add a row to the list box
  Me.AddRow("Hello World!")
  1. drag two buttons onto the web page
    3.1 set the caption of button1 to “Use Style Renderer”
    3.2 add a pressed event with the following code
'Create a webstyle
  Var style As New WebStyle
  style.BackgroundColor = Color.Yellow
  style.BorderColor = Color.Green
  style.BorderThickness = 3
  style.Bold = True
'Create a renderer from the webstyle and some text
  Var cellRenderer As New WebListBoxStyleRenderer(style, "Hello Styled World!")
'Assign the renderer to the cell
  ListBox2.CellValueAt(0,0) = cellRenderer

3.3 set the caption of button2 to “CellValueAt”
3.4 add a pressed event with the following code
MessageBox(ListBox2.CellValueAt(0,0))

Kind regard, Andrew

This looks like a regression to me, I think we should be able to change the cell value using a cell renderer, without this issue. Fortunately there is a workaround =)

Update the Pressed event of your first button. You will first have to remove the row you want to give the style, add an empty row in the same position and finally assign your styled renderer:

'Assign the renderer to the cell
Listbox2.RemoveRowAt(0)
Listbox2.AddRowAt(0, "")
ListBox2.CellValueAt(0,0) = cellRenderer

The way to get the value from your WebListBoxStyleRenderer is by getting its value (no idea if it was casted to a String automatically in previous releases):

Var styledCell As WebListBoxStyleRenderer = ListBox2.CellValueAt(0,0)
MessageBox(styledCell.Value)

Hope this helps @Andrew_Paul_Dickey !

1 Like

You are having way too much fun with cellRenderers :slight_smile:

Hola! Por cierto Ricardo

1 Like

Please somebody stop me!

¡Un abrazo Héctor! :joy: :fist_right::fist_left:

3 Likes

@Ricardo_Cruz_Fernandez (Champion of the Renderers!),

Thank you very much for the workaround.

I will mark your answer as the solution, however sometimes I wish the forum had three buttons (one for “solutions” (multiple), another for valid “workarounds” (multiple) and another to elevate the discussion to “feedback” (as I would argue there is already enough detail posted here for a valid feedback case).

Again, thank you for your assistance.

Kind regards, Andrew

1 Like

Happy to help @Andrew_Paul_Dickey, that idea for creating a Feedback case directly from here would be super useful :blush:

@Greg_O_Lone is there a feedback case for this one already?, would you want us to create it?

@Ricardo_Cruz_Fernandez,

I have more thoroughly tested your work around.

Point 1:
The workaround, works in 2021 R3 but not 2021 R1. It throws the following compile error in 2021 R1:
WebPage1.Button2.Pressed, line 5
Type “WebListBoxStyleRenderer” has no member named “Value”
MessageBox(styledCell.Value)

Point 2: Enhancement

Not every cell (or row) will have a Style Renderer, therefore outputting the value associated with CellValueAt using your method would naturally bomb if no renderer was used. So, we need to check the type each time.

If VarType(ListBox2.CellValueAt(0,0)) = 8 Then // var type 8 = string
  MessageBox(ListBox2.CellValueAt(0,0))
Else // we assume we are using a Style Renderer
  Var styledCell As WebListBoxStyleRenderer = ListBox2.CellValueAt(0,0)
  MessageBox(styledCell.Value)
End If

Point 3:

The need to first Remove and then Add an empty Row, before populating again with the renderer is complex in everything but the simplest of examples, especially when the WebListBox has a DataSource or multiple (many) columns and you are only formatting or updating a single cell.

I am using Style Renderers driven by timers to format mostly numeric data from live database feeds (reacting to negative/positive trends, live sales data etc).

Ultimately, CellValueAt needs to reliably return the value of the cell regardless of whether a renderer has been used or not.

That said, a workaround is called a work around for a reason, not perfect but moves us forward.

Again, thank you.

Kind regards, Andrew

Hi Andrew!,

For Points 1 & 2, maybe you can use CellTagAt instead of the value, it will be easier I think.

Point 3, totally agree =(, that used to work fine. I’ll take a look this weekend to see if there is another way.

1 Like

Hi again Andrew,

To me, it looks like the big difference between the previous versions and this one is how CellValueAt works. It used to call ReloadData behind the scenes, now it attempts to update the specific cell without calling to the server.

If you’re working with plain strings, that’s fine, should be even faster now. But it looks like this breaks cell renderers.

What we can do (while this gets a permanent fix) is calling WebListBox.ReloadData after calling CellValueAt. It still shows the JSON for a second :frowning_face:

I’ve created a feedback case:
feedback://showreport?report_id=66788

2 Likes

@Ricardo_Cruz_Fernandez,

Thank you for creating a feedback case Ricardo.

Once fixed, I assume CellValueAt(Row#,Col#) will return the value of the cell and not the JSON of the renderer.

In that case testing VarType() to guess whether a renderer is in play will become redundant.

Therefore, I believe you should be able to interrogate a cell to discover whether it has a renderer applied to it, the name of the renderer, and it’s type.

For example:

CellValueAt(Row#,Col#).HasRenderer (bool: true|false)
CellValueAt(Row#,Col#).RendererName (string: the name of the renderer)
CellValueAt(Row#,Col#).RendererType (enum: style | image | datetime | custom)
CellValueAt(Row#,Col#).Renderer (json: the json of the renderer)

…assuming there is no current easy way to do so…

Kind regards, Andrew

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.