How to avoid the display of multiple alert windows in Flex - apache-flex

I have a timer in my application. For every 30 min, it will hit the web services and fetch the data and updates the UI. The application was working fine till yesterday. Suddenly, because of some issue, the web services were not available for some time. During that period, Application displayed the RPC Error multiple times(More than 100 alert boxes) in alert window. Because of this alert boxes, my application was hanged and i was not able to do anything.
I have tried several approaches, but nothing worked.Finally, I have tried to use a flag. In all the approaches, this looked promising. so i have implemented it.Basically, in this approach whenever we open an alert we will set a flag.While opening and closing alert we will reset this flag. But it didn't work as expected. Is there any approach, which can help us in avoiding multiple alert windows.
Please help me, to fix this issue.

I would write wrapper for opening alerts, and use only this wrapper, not Alert.show in the code:
public class AlertWrapper {
private static var lastAlert:Alert;
public static function showAlert(text:String, title:String):void {
if (lastAlert) {
PopUpManager.removePopUp(lastAlert);
//or
//return; //ignore last alert
}
lastAlert = Alert.show(text, title, null, 4, onAlertClose);
}
private static function onAlertClose(event:CloseEvent):void {
lastAlert = null;
}
}
Imports are missing, but I hope the idea is clear.

Related

How do I run code at client start (Not at page open) in Blazor

I need to run some code to get a user's username and department when they first connect to my Blazor Server Side application. I could just do this using OnInitialized() but that appears to only work on the one page in which it was placed. Users will likely be sent separate links to different pages though and I don't want to have to place this code on every page. I discovered that I can place code in my main layout and it will run no matter what page I start on but it runs on every page change and it doesn't allow me to run things asynchronously so that's not ideal. I'm looking for something like a Global.asax but in Blazor if that makes sense.
Edit: Turns out I can run things asynchronously in my layout! I just needed to create a code block like any other razor page. Makes sense. Though It's still weird that we have to put this type of code in the layout. It just doesn't feel right.
This is what I do:
Create a state object (class) that can be injected where needed. This is somewhat like session, but can also have global events. See here.
Add it to IoC in Startup.cs. Background info here
services.AddScoped<MyState>();
Initialize it in MainLayout.razor or elsewhere:
if (MyState.User == null)
{
MyState.User = authService.User;
}
Instantiate in pages/components as needed:
[Inject]
public MyState myState { get; set; }
...
myObj.CreatedBy = myState.User.UserName;

JXBrowser control over dialog website not responding

Hey im having issues with a website in the jxbrowser. it seems like it is running into a timeout or whatever and then in the jxbrowser there is a dialog showing up "website not responding" and i can click on "reload" or "leave".
Can I in any way access this dialog and overwrite it? For instance everytime i would get this dont ask but go to the homepage instead?
I'm having trouble finding this if it is even possible.
I found a solution. JXBrowser has a RenderAdapter where a function exists onRenderUnresponsive wich can be overridden. Look at this: https://jxbrowser.support.teamdev.com/support/solutions/articles/9000091687-detecting-unresponsive-web-page
In my case I simply want to reload the website:
Browser browser = new Browser();
browser.addRenderListener(new RenderAdapter() {
#Override
public void onRenderUnresponsive(RenderEvent event) {
browser.reloadIgnoringCache(false);
}
});

Program crashes with WebKit Previewer example with on_textEdit_textChanged()

I recreated the example of a webkit that displays the content of a textEdit containing HTML: http://qt-project.org/doc/qt-4.8/webkit-previewer.html
I changed it so rather than the webkit HTML being changed upon clicking the button, it's changed upon the text in the textEdit being changed:
// changed when button is click. Works fine.
void Previewer::on_previewButton_clicked()
{
// Update the contents in web viewer
QString text = htmlTextEdit->toPlainText();
webView->setHtml(text);
}
// change when text is changed. Crashes.
void Previewer::on_htmlTextEdit_textChanged()
{
// Update the contents in web viewer
QString text = "<html><body><h1>No crash!</h1></body></html>";
webView->setHtml(text);
}
This causes the program to crash as soon as it starts. I altered the program to run the function only a bit later (I thought maybe something needed to be initialized) but it still crashed once it reached the textChanged function. Why is it crashing? How can I fix this?
Your program is entering an infinite loop because, in the example, there's a connection between the webView's loadFinished(bool) signal and the text/html editor's updateTextEdit() slot.
Basically, editing the HTML causes the page to load again, which causes an update to the editor, which causes the page to load again, so on and so forth.
A quick way I solved this was to add a static bool flag to the updateTextEdit SLOT/function that only allows it to run once.
void MainWindow::updateTextEdit()
{
static bool once = false;
if (once) {
return;
}
once = true;
QWebFrame *mainFrame = centralWidget->webView->page()->mainFrame();
QString frameText = mainFrame->toHtml();
centralWidget->plainTextEdit->setPlainText(frameText);
}
Doing this worked for me, but your version might work differently than mine. I followed the example closely, but added an htmlchanged() slot to the previewer class, and made the connection like so:
connect(centralWidget->plainTextEdit, SIGNAL(textChanged()), centralWidget, SLOT(html_changed()));
Also, I'm no expert, but I'm pretty sure this is not the best way to get around this, and I assume that updateTextEdit() needs to run more than once. It'll work for the time being, though.

Custom URL issue in flex ios app

i am using custom url scheme in my flex iOS app and it’s working fine when i start my app from a web link..but the issue is when i start my app from start menu in iPad and move to webpage in safari.In page i click a button that redirects it to my app, at that time app call “preinitialize” method more than once..it wary every time, some time it’s 2,3,4 and different one each time..i don't know why it’s behaving like this..can i know the reason please its urgent..
thanks…any help will be appreciated.
Create a flag initialized and set it to true when preinitialize is called. All other calls to this method can be filtered out. Simple example:
private var initialized:Boolean = false;
public function preinitialize():void
{
if (initialized) return;
initialized = true;
}
Next step would be finding the real cause of the multiple calls, but for that we would need to see some code of your app.

Initialization order of static variables in Flex causing bug

I've got a component written for my app by a third party developer and am trying to integrate it, but I've found a bug that seems like it's either a compiler bug, or there's something with how Flex and static variables work that I wasn't aware of.
Basically, I have this:
public class ModeChangeController {
public static const DISPLAY_MODE:String = "DisplayMode";
}
public class Events {
public static const DISPLAY_MODE:String = "DisplayMode";
public static function myStaticFunction( viewState:String = null):void {
//Empty
}
}
<?xml version="1.0" encoding="utf-8"?>
<s:BorderContainer /*snip*/ >
<fx:Script><![CDATA[
import mypackage.sub1.ModeChangeController;
import mypackage.sub2.Events;
private function showInitialView():void {
// Variant 1
Events.myStaticFunction( Events.DISPLAY_MODE);
// Variant 2
Events.myStaticFunction( ModeChangeController.DISPLAY_MODE);
}
]]></fx:Script>
}
If I use //V2 (i.e. comment out V1), a bug occurs at the startup of the application (some TextFields are uneditable and contains no text), but with //V1 and not V2, it works fine. If I comment out both, that also works fine (I don't get the TextField bug).
It took me a while to figure out that it was that static const String that was causing the issue, but I'm still not sure why or if there's something I can do about it except for just moving the DISPLAY_MODE to Events (which is what I've done at the moment, but it's not a particularly nice solution).
There are no errors in the log. The order of the includes in my BorderContainer code doesn't matter. I've googled for "as3/flex static initialization order" but haven't found anything.
Does anyone know what the problem is?
Clarification: showInitialView() never gets called. It doesn't get there before the other bug shows up. Just having the V2 line there causes the problem.
Update: I've fixed my problem with the TextInput strings not showing: Turns out that adding the component caused the Tahoma font to not show up. However, setting the font-weight to bold fixed that problem, or switching to Arial. With that said, the original question still stands, because when I ran it without V2, it found Tahoma with normal font-weight.
It's not the static string. I tested it myself without a problem. I was skeptical of your issue since the flash static vars would get created when the application is loaded no matter what and the variable would be available.
I believe the problem has nothing to do with the static var but with something else causing an error. It seems that you don't have a version of Flash Player debug by your description. Get it, debug your application line by line and see what the problem is.

Resources