VMware {code} Community
alfric
Contributor
Contributor

How to refresh navigator content

Now i am working on developping a plugin of web-client using html.

how to refresh left-side navigator when i do something.

0 Kudos
11 Replies
laurentsd
VMware Employee
VMware Employee

The only time the navigator needs refreshing is when it is displaying a list of objects (i.e. non static nodes). Your action service should use the ActionResult pattern as shown in the chassisA sample (see ActionsController.java and ActionResult.java in chassisA-service). This result sent back in response to an action will notify the Client platform that an object has been added, deleted or modified and in turns the object list navigator will be refreshed.

0 Kudos
dloverin
Contributor
Contributor

Hi Laurent,

I see how WEB_PLATFORM.callActionsController(url, json); is used in chassisA but would it work if the action on the Java side needed to create a long running task that required polling to know when the task completed?

We are currently polling and using 

WEB_PLATFORM.sendModelChangeEvent

to update the UI after a task completes (same approach as in Flex).

Which method is recommended for the html client?

Thanks,

-Darrell

0 Kudos
laurentsd
VMware Employee
VMware Employee

> We are currently polling and using WEB_PLATFORM.sendModelChangeEvent to update the UI after a task completes (same approach as in Flex).


Yes, this is the only way to notify the platform that something changed from your UI view code (i.e. not as a response from an action)

0 Kudos
dloverin
Contributor
Contributor

We are using the same approach for actions as well. I don't see how we could use WEB_PLATFORM.callActionsController() to poll for the completion of a task since I don't believe the call returns anything to the caller..

0 Kudos
laurentsd
VMware Employee
VMware Employee

WEB_PLATFORM.callActionsController() doesn't allow any polling and doesn't return anything.  I was replying to your question about sendModelChangeEvent() where you indicate that you are already doing some polling on your own.  May be I misinterpreted your question?

0 Kudos
dloverin
Contributor
Contributor

You answered my question about sendModelChangeEvent() but I wanted to clarify that sendModelChangeEvent() was also the correct approach for actions that poll for completion as well as views. The "not as a response from an action" part of your answer left some doubt in my mind.

>>Yes, this is the only way to notify the platform that something changed from your UI view code (i.e. not as a response from an action)

-Darrell

0 Kudos
laurentsd
VMware Employee
VMware Employee

OK, let me clarify: you only need to use sendModelChangeEvent() in that polling use case where your UI code is detecting the change itself.  In the normal use case where you call an action on the server side which returns immediately you must use the ActionResult class to let the vSphere Client what changed: it will take care of updating the model.  That's how it works in the ChassisA and ChassisB samples, see for instance

samples/chassisA-service/src/main/java/com/vmware/samples/chassisa/mvc/ActionResult.java

Hope this helps!

0 Kudos
dloverin
Contributor
Contributor

Hi Laurent,

I'm having a problem polling for the completing on a long running task. After the user presses OK in an HTML dialog we validate the input and start a long running task. After the task has been started we poll the task for completion and call WEB_PLATFORM.sendModelChangeEvent() after the task succeeds. The problem is the timer (using setInterval) is stopped after calling WEB_PLATFORM.closeDialog().

What is the recommended way to close the dialog and still poll for completion of a task?

Thanks,

-Darrell

0 Kudos
laurentsd
VMware Employee
VMware Employee

There are 2 use cases:

1) You initiated the long running task from a dialog that was opened from a menu, or from an action bar over a list of objects (not your view)

2) The dialog was opened from one of your views.

In case #1 the current view is not one of yours, so you cannot run any Javascript code to perform polling and wait for your task to complete. My recommendation is to warn users that they will have to refresh the list themselves after they exit the dialog.

In case #2 you can initiate your polling logic in the parent view code, at the same time the dialog is opened.  That logic needs to stop polling either when the view is no longer active or if it detects that no task was started afterall.

0 Kudos
dloverin
Contributor
Contributor

Hi Laurent,

Thanks for the clarification of the two use cases.

My use case is #1. I wanted to get your feedback on a way to update the ui for case #1 that I have prototyped.

Instead of polling in the dialog code for task completion, call

WEB_PLATFORM.callActionsController("/tasks/" + taskId, jsonString);

to poll for task completion on the server and return the correct ActionResult. The type of update (add, modify, or delete) can be passed in the jsonString parameter.

To summarize, on submit a dialog would do the following:

1. Make http request to perform the action. If the user input is invalid then keep the dialog up and allow the input to be corrected.

2. Get returned taskId from step 1.

3. Call WEB_PLATFORM.callActionsController("/tasks/" + taskId, jsonString);

4. Call WEB_PLATFORM.closeDialog().

The spring controller for "/tasks" is currently waiting a maximum of two minutes for the task to complete before giving up.  I chose two minutes because typically our tasks complete within two minutes and I didn't want to keep the thread occupied too long.

What are your thoughts on this workaround?

Thanks,

-Darrell

0 Kudos
laurentsd
VMware Employee
VMware Employee

hi Darrell,

That should work if you include an actionUid query parameter to your /tasks URL, because when the http post returns to the platform it needs to know which target object must be updated (unless you're creating a new object).  Let me know.

0 Kudos