I want a toastbar that should display a message to the user before calling a service and hides it after getting the service response.How can I do this??I mean i dont need the expire time to hide it .It should be hidden only after getting the service response.
You can create a ToastBar.Status and show/dispose it manually:
ToastBar.Status s = ToastBar.getInstance().createStatus();
s.setIcon(FontImage.createMaterial(icon, stl, 4));
s.setMessage(msg);
s.setExpires(-1);
s.show();
When you are done with this just call s.clear().
Related
I am trying to use the Channel API to push updates from server to the client. The flow is the user presses a button which triggers a server side action that generates a lot of logs. I want to display the logs to the user "in real time".
When I first load the page it I get all the messages, no problem. If I trigger the action a second time without refreshing the page in my browser, then all messages appear twice. Here is the set up portion of the channel that is tied to the page onLoad event. With resulting console logs I gathered that the onMessage() method is being invoked more than once when the page is not refreshed. Looks like I need to "kill" earlier sockets in some way, but could not find a way in the official documentation. Can someone point me in the right direction to get rid of the spurious messages?
// First fetch a token for the async communication channel and
// create the socket
$.post("/app/channels", {'op':'fetch', 'id' : nonce},
function (data, status, xhr) {
if (status == "success") {
data = JSON.parse(data);
token = data["token"];
console.log("Cookie: " + get_mp_did() + "; token: " + token);
var channel = new goog.appengine.Channel(token);
var handler = {
'onopen': onOpened,
'onmessage': onMessage,
'onerror': function() {
$("#cmd_output").append('Channel error.<br/>');
},
'onclose': function() {
$("#cmd_output").append('The end.<br/>');
$.post("/app/channels", {'op':'clear'});
}
};
var socket = channel.open(handler);
socket.onopen = onOpened;
socket.onmessage = onMessage;
}
});
onOpened = function() {
$("#cmd_output").empty();
};
onMessage = function(data) {
message = JSON.parse(data.data)['message'];
$("#cmd_output").append(message);
console.log('Got this sucker: ' + message);
}
If I understand your post and code correctly, the user clicks on a button which calls the $.post() function. The server code is responsible to create the channel in GAE as response to a /app/channels request. I think that your server in fact creates a new channel client ID / token with every subsequent request. Since the page is not reloaded, any subsequent request would add a new channel to this client. And all these channels would be still connected (hence, no page refresh).
I assume your server code has all channels associated to a user, and you send the message to a user utilizing all channels? Such pattern would result in this behavior. You can verify my assumption by clicking 3 or four times on the button with-out page refresh. The log output would be multiplied by the factor of 3 or 4.
I suggest, that you store the token in the client and on the server. Then make a modification to your client JS. If a channel is already created store the token value and provide it to any subsequent request to /app/channels. Modify the server so it will not create a new channel, if a token is provided with the request. If the token links to an existing valid channel, re-use the channel and return the same token in the response. You may need to add some more details for disconnected or expired channels, maybe also a cron-job to delete all expired channels after a while.
I want to show a Feed back message in sales force Standard page on custom button click using visual force page on the basis of Apex class logic.Any one who can help me?For example if some thing successfully done then success message and if not error message should display on standard page.
You can create a new method to handle your messages
private void displayFeedback(ApexPages.Severity msgType, String message)
{
ApexPages.Message msg = new ApexPages.Message(msgType, message);
ApexPages.addMessage(msg);
}
Build your message you want to show..
displayFeedback(ApexPages.Severity.Error, String.valueOf(TripProfileHandlerServices.ERROR_SAVING_DATA + missingDataError));
Put this message in your VF page
<apex:pageMessages id="feedback" />
You will also have to rerender='feedback" when you want show the message after an event
If you put a <apex:messages /> in the page, you can use the message class to fill it up.
I'm trying to use web sockets to add a new notification to my app. I'm using Backand as my server, and can't seem to get a grasp on responding to the new event. Here's my server side code to send the event:
//Action: Update - After data saved and committed
function backandCallback(userInput, dbRow, parameters, userProfile) {
//Send to array of users
socket.emitUsers("new_notification",userInput, ["admins"]);
return {};
}
And my client code to receive it:
//Wait for server updates on 'items' object
Backand.on('new_notification', function (data) {
//Get the 'items' object that have changed
console.log(data);
});
But when I try to receive the event in my app code, I never see a notification of type "new_notification". Can someone please let me know what's going on?
Make sure you are using emitRole instead of emitUsers. The code above emits to a user array, but it looks like you want to send a notification to the "admins" role. Change this to emitRole() and you should be ok.
For role you want to keep it case sensitive so it will be:
socket.emitRole("items_updated",userInput, "Admin");
For users the syntax is:
socket.emitUsers("items_updated",userInput, ["user2#gmail.com","user1#gmail.com"]);
I would like to achieve the following kind of orchestration with CAMEL:
Client sends a HTTP POST request to CAMEL
CAMEL sends HTTP POST request to external endpoint (server)
External server replies with a 200 OK
CAMEL sends HTTP GET request to external endpoint (server)
External server replies
After step 5, I want to check the reply: if the reply is a 200 OK and state = INPROGRESS (this state can be retrieved from the received XML body), I want to re-transmit the HTTP GET to the external endpoint until the state is different from INPROGRESS.
I was thinking to use the retryWhile statement, but I am not sure how to build the routine within the route.
Eg, for checking whether the reply is a 200 OK and state = INPROGRESS, I can easily introduce a Predicate. So the retryWhile already becomes like:
.retryWhile(Is200OKandINPROGRESS)
but where should I place it in the route so that the HTTP GET will be re-transmitted ?
Eg: (only taking step 4 and 5 into account)
from("...")
// here format the message to be sent out
.to("external_server")
// what code should I write here ??
// something like:
// .onException(alwaysDo.class)
// .retryWhile(Is200OKandINPROGRESS)
// .delay(2000)
// .end ()
// or maybe it should not be here ??
I am also a bit confused how the "alwaysDo.class" should look like ??
Or ... should I use something completely different to solve this orchestration ?
(I just want to re-transmit as long as I get a 200 OK with INPROGRESS state ...)
Thanks in advance for your help.
On CAMEL Nabble, someone replied my question. Check out:
http://camel.465427.n5.nabble.com/Camel-Apache-can-I-use-a-retryWhile-to-re-send-a-request-td5498382.html
By using a loop statement, I could re-transmit the HTTP GET request until I received a state different from INPROGRESS. The check on the state needs to be put inside the loop statement using a choice statement. So something like:
.loop(60)
.choice()
.when(not(Is200OKandINPROGRESS)).stop() // if state is not INPROGRESS, then stop the loop
.end() // choice
.log("Received an INPROGRESS reply on QueryTransaction ... retrying in 5 seconds")
.delay(5000)
.to(httpendpoint")
.end() //loop
I never experimented what you are trying to do but it seems does not seem right.
In the code you are showing, the retry will only occur when an alwaysDo Exception is thrown.
The alwaysDo.class you are refering to should be the name of the Java Exception class you are expecting to handle. See http://camel.apache.org/exception-clause.html for more details.
The idea should be to make the call and inspect the response content then do a CBR based on the state attribute. Either call the GET again or terminate/continue the route.
You probably should write a message to the Apache Camel mailing list (or via Nabble) . Commiters are watching it and are very reactive.
I'm writing a Silverlight 4 application using "Silverlight 4 Unleashed" as a foundation.
I have a ChildWindow for loggin in with Username, Password, and Remember Me. The OK button is tied to my AuthUserViewModel SignIn using RelayCommand.
Since I'm just starting, I don't have any data validation yet and noticed something weird.
If I click "OK" on my Login child window, my Action callback tells me I have invalid credentials in a MessageBox...which is perfect. I'm using my own Authentication service for various reasons.
However, if I click "OK" again, my service gets called once, but the Action callback is fired twice, telling me I have invalid credentials. If I press "OK" again, the service is called once, but the Action callback is fired three times, and so on and so on.
Why would it be doing that?
Here is the offending code:
public void SignIn(AuthUserDataModel authUser, Action<ErrorContainer> callback)
{
EnsureClient();
client.SignInCompleted += (sender, result) =>
callback(new ErrorContainer
{
AsyncException = result.Error,
CustomError = result.Result.CustomMessage //holds "Invalid credentials"
});
client.SignInAsync(authUser);
}
Like I said, the button event is fired once, the web service is called once, but the callback is fired an amount equaling the number of times I press OK.
Thank you.
Ah! your client object is a field, and you ensured that it is shared across calls. It prevent it from being initialized on each SignIn call, but each time you add an handler to the SignInCompleted vent before executing the SignInAsyncFunction.
Therefore it's normal that the handler gets executed one time by subsequent SignIn.
To prevent this, you have 2 approaches:
1) create a new client in each SignIn call (it will be garbage collected later)
2) attach your handler when you initialize the client.
ie in your EnsureClient, you should have something like:
if(client == null)
{
client = new MyClient();
client.SignInCompleted +=(sender,result) =>{...};
}
and in the SignIn function:
EnsureClient();
client.SignInAsync(authUser);