eclipse-archived / smarthome

Eclipse SmartHome™ project
https://www.eclipse.org/smarthome/
Eclipse Public License 2.0
865 stars 782 forks source link

Classic UI: update of a switch not working when present in several subpages #3489

Open lolodomo opened 7 years ago

lolodomo commented 7 years ago

For a switch element located in a subpage, when the switch value is updated externally, the value of the switch and its icon are updated as expected but the switch control itself is not.

If the switch is in the main page, it is working as expected.

lolodomo commented 7 years ago

If someone can give me tips on how is handled (and where in the code) the page refresh in the front side of Classic UI, I could take a look and try to fix this issue.

triller-telekom commented 7 years ago

Have a look at SwitchRenderer . The classicui is prerendered on the server side and then the client only polls the newly created html site from the server in a loop

lolodomo commented 7 years ago

I see that we are using checked="true". Wouldn't it be better to use checkedor checked="checked" ? http://stackoverflow.com/questions/7851868/whats-the-proper-value-for-a-checked-attribute-of-an-html-checkbox

lolodomo commented 7 years ago

This bug is really not obvious to reproduce but I finally found how. To reproduce it with the demo sitemap, duplicate the "DemoSwitch" switch from the page "Widget Overview" into the page "Group Demo".

        Text label="Group Demo" icon="firstfloor" {
            Switch item=Lights mappings=[OFF="All Off"]
            Group item=Heating
            Group item=Windows
            Text item=Temperature
            Switch item=DemoSwitch label="Toggle Switch"
        }
        Text label="Widget Overview" icon="chart" {
            Frame label="Binary Widgets" {
                Switch item=DemoSwitch label="Toggle Switch"
                Switch item=DemoSwitch label="Button Switch" mappings=[ON="On"]
            }

Start OH and open the "Widget Overview" page in Classic UI and Basic UI. Use Basic UI to toggle the switch. The change is OK in Classic UI. Now go to the "Group Demo" with Classic UI. Toggle the switch again in Basic UI and you will see that the switch control is not updated in Classic UI.

I checked, there is nothing wrong on the backend, the switch renderer is adjusting the "checked" property as expected.

This might be a bug in frontend when "AsyncLoad" is used (only in a subpage) and you have two switch linked to the same items in 2 different pages.

When in a subpage like "http://192.168.1.x:8080/classicui/app#_1001" and requesting the source code in Firefox, unfortunately I only got the source code of the main page.

lolodomo commented 7 years ago

In my HTML page, I have:

            function AsyncLoad(widgetId) {
                WA.Request("app?sitemap=demo&w=" + widgetId, null, -1, true, null);
            }

What is WA ? What backend method is finally called by "WA.Request" ?

lolodomo commented 7 years ago

Ok I found, WebAppServlet.service is called.

lolodomo commented 7 years ago

Ok, I can confirm that the backend is returning a correct page with or without "checked=true" to the frontend. I don't know how it is then handled by the frontend but there is probably a conflict between the result of 2 different pages in the time: http://192.168.1.x:8080/classicui/app#_1001 and http://192.168.1.x:8080/classicui/app#_1002. Could it be due to a kind of cache in the browser ? Is there a way in the frontend to first clear previous loaded subpages before loading a new siubpage ?

I stop here my analysis, I am not able to fix that, it requires someone having a good frontend knowledge. @resetnow : maybe you can help ?

lolodomo commented 7 years ago

Just to be clear, when you only access one of the 2 subpages, it is working well. The problem appears as soon as you have opened the 2 subpages.

triller-telekom commented 7 years ago

@lolodomo Thank you for your extensive analysis!

In the long run we would like to get rid of the classicui anyway, in favor for the basicui. So if you find such nasty bugs which afford a lot of work, I think its not worth fixing them in classicui unless you are really really interested in fixing it :). However, if you find "one line fixes" for classicui, feel free to do them.