ADF: What is a quick and easy way to display a debug/log message on the UI? - oracle-adf

So I am debugging some code in my application (dev and test environment) and I am not allowed to use appsloggers or System.out.print or any such logging.
I would like to see the value some of the variables hold at a given time and put messages like "Entered first If loop" and "Enter x function".
The code usually exists in ManagedBean, VOImpl and AMImpl and some java handlers.
What is the best way to display something on the UI of my application, like a comment box or a warning message for debugging purposes?
It would be great if I can close the message box and code flow continues.

It would be great if I can close the message box and code flow continues.
What you are describing is debugging. In Java and ADF debugging isn't done in the UI and should not. You can use JDeveloper debugger functionnality on your local instance or by plugging the remote debug functionnality to your target server.
https://download.oracle.com/otn_hosted_doc/jdeveloper/101301/java_app_dev/debug/deb_p_local.html
Debugging a Project in JDeveloper
Make sure that your code is compiled with debugging information in Tools then choose ProjectProperties - Compiler before you can make use of some of the debugger features such as viewing arguments and local variables in the Data window.
See About Debugger Icons to determine the purpose and functions of the various debugger icons displayed on the toolbar or in the debugger windows. Each of these commands is also available from the Debug main menu.
To set breakpoints and step through your code:
In a source editor, set a breakpoint on an executable statement by clicking in the margin to the left of the statement.
The unverified breakpoints icon red_dot appears in the left margin.
Select D ebug then choose Debug [filename.java] or click Debug Button on the toolbar.
The class runs and stops at the first breakpoint.
From the toolbar, click step_into_toolbar_icon Step Into to trace into a method call or click step_over_toolbar_icon Step Over to step over a method call.
Look in the Stack window to examine the sequence of method calls that brought your program to its current state. Double-click a method to display the associated source code in the source editor.
In the Smart Data and Data windows, examine the arguments and variables.
Display the Threads window to see the status of other threads in your program.
Remote debugging on your target server :
https://aboutsoa.wordpress.com/2009/03/10/remote-debugging-in-jdeveloper/
Open Enterprise Manager (http://{hostname}:{port}/em) and click on the oc4j_soa instance.
Click the Administration tab.
Click on Server Properties.
Under command-line options add the following line: -Xrunjdwp:transport=dt_socket,server=y,address=9901,suspend=n.
Click Apply and then be sure to restart the OC4J server.
Next you need to configure your JDeveloper project for remote debugging:
Right-click on the project and choose Project Properties.
Click the Run/Debug option.
Click on the default run configuration and click Edit…
Under the Launch Settings option make sure the Remote Debugging and Profiling checkbox is checked.
Choose the Debug > Remote option.
If you still want to display and alert on the UI you can trigger a javascript alert function programmatically.
https://cedricleruth.com/how-to-execute-client-javascript-in-an-adf-java-bean-action/
this.executeClientJavascript("alert('HERE IS MY VARIABLE VALUE, i should really use the debugger for this :)" + YOURJAVAVARTOSTRING + " ')");
//You should put this function in a util java class if you want to use it in multiple bean
public static void executeClientJavascript(String script) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExtendedRenderKitService service = Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);
service.addScript(facesContext, script);
}

Related

How to make WebDriver operate browser in background?

I have a python script which uses Selenium WebDriver to start a Chrome, open an URL, enter simple captcha, check if some data available (time for visit government organization) and repeat this process in 5 minutes.
I want it work in background. Headless mode is not an option because site would show DDos Guard in that case.
I have tried to use driver.minimize_window() but the windows activates for short periods for number input and click of button which is annoying when I work on PC.
Is it possible to make it work completely in background without activate Chrome window?
You can packaging your script using PyInstaller, then run it with Windows Task Scheduler (assuming you are using Windows)
Install pyinstaller
pip install -U pyinstaller
2. Packaging your script (run in cmd)
pyinstaller --onefile --name=your-package-name yourscript.py
Check pyinstaller docs and make sure add --hidden-import or --collect-data flag if needed.
Setup your task scheduler:
Create basic task, choose task name, and description (if needed)
Create trigger
Set action to start a program then define your script name in Program/script and make sure put your script folder path in Start in
Then voila. You can custom the trigger more detail in task properties (creating multiple triggers, specific conditions, etc...)
You could try to start your exe file as process manually using cmd/powershell like this SO answer, and some kind of process/service manager but I have never tried it yet.
When I use selenium and headless option don't work with me, I always do this trick by changing the window size and just leave it.
So, set the window size in the driver itself, like this:
driver.set_window_size(1, 1)
Or, set it as an argument, like this:
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('window-size=1,1')
Or use both.
I hope this helps you.

Restart Applescript causing infinite reboot loop

I tried to set up Voice Control to restart my mac by running the applescript:
tell application "System Events"
restart
end tell
I set it up for voice control. I'd say "Restart the Mac"
However this put my mac into an infinite restart loop!
Had to trash the script.
Is there a solution to this problem with a different applescript that doesn't go into a loop? It would be great to simply say "Restart the Mac" and then presto it restarts.
I use Voice Control every day, without error, to restart my computer.
These are the steps I took.
Paste this following AppleScript code into a new Script Editor document and save it as "Restart Computer.scpt" (Don't save it to any "Startup Items" Folder)
tell application "System Events" to restart
Make sure you grant access in System Preferences for System Events.app to be allowed to control your computer.
With Voice Control currently active, select the new "Restart Computer.scpt" file in Finder, then speak the command "Make This Speakable".
You Should then see a pop-up window like this...
Just insert the voice command you want to use (I use "Restart Computer") and click Save.
Note: Before doing all of this, you should remove any previous custom commands you have set for restarting the computer, from your Commands list in System Preferences.
As an added bonus, this following AppleScript code will reveal the file which stores all of your custom voice commands, in Finder. It's a good idea to backup this file from time to time. Also copying this file to a different computer will allow you to use the custom commands on that computer.
set customDictationCommands to (path to preferences folder as text) & ¬
"com.apple.speech.recognition.AppleSpeechRecognition.CustomCommands.plist"
tell application "Finder" to reveal alias customDictationCommands
I don't think AppleScript is the best tool for this. In System Preferences→Accessibility→Voice Control you can enable Apple's built-in voice command system, which should work out-of-the-box. They don't have a built-in Restart command so you'll have to create one, but that's easy enough. Click the 'Commands...' button at the bottom right, then click the '+' button at the bottom left, and you can choose any of several ways of implementing it.
With restarting script saved as application the simple restart command will enter into infinite reboot loop. This is because of unsaved state of application.
To solve this problem, use following script application instead:
tell application "System Events" to restart with state saving preference

Keyboard shortcut to toggle OUT of a Citrix Workspace Desktop Viewer session

Background
I'm using the Desktop Viewer functionality in Citrix Workspace (version 20.2.0.25(2002)) to access my work computer from my home computer.
Request
I would like to be able to toggle out of my (full-screen) remote session back to my local desktop more easily.
Currently I can only accomplish this via the control bar at the top of the remote session screen which is starting to feel tedious.
Alt+Tab doesn't work, because it only toggles the applications within the remote session when the session is open.
Whether toggling is accomplished via getting Alt+Tab to work as desired, a hotkey that just minimizes the session window, or some other method doesn't matter to me.
What I've Tried
There are many questions online addressing how to enable Alt+Tab within the remote session, but not disable it. Naturally I've tried to do the reverse of these instructions but no luck. They typically suggest setting TransparentKeyPassthrough=Remote in the registry of the local machine, so I figured mine should have Remote already and I would just need to clear it or replace it with something else, but mine is a null value.
I've gone through all options within Citrix Workspace and the Remote session Preferences but there's nothing about enabling/disabling/setting hotkeys.
I tried the "Disable Hotkeys through the ICACLIENT.ADM Template" of this Citrix Support page, but was unable to locate the icaclient template file they refer to.
I've contacted my company's help desk but they don't know of any solutions.
You can access the citrix menu as described here:
As an accessibility feature of the Desktop Viewer, pressing CTRL+ALT+BREAK
displays the Desktop Viewer toolbar buttons in a pop-up window.
So the shortcut for toggling out of the viewer session would be:
CTRL + ALT + BREAK, CURSOR-DOWN, ENTER
I had the same problem and solved it with an Autohotkey script. Autohotkey can intercept keypresses even when citrix has focus.
This script will allow you to get out of your citrix session with Ctrl-F1.
^F1::
WinMinimize, A
return
If you have not used Autohotkey before: Download Autohotkey, install it, save the code above in a file named citrix.ahk, double-click that file. The hotkey is now active and the script is visible as a H icon in your taskbar.
See here if you want to bind a different key.
Unable to comment on ht13's answer so i'll post my own.
CTRL+ALT+BREAK, h
worked for me.
Thankfully i remembered some keyboards have BREAK, some (like mine) call it PAUSE in case you run into that too.
I have a method for this that involves editing the registry on your local machine.
It definitely counts as 'some other method' - essentially, it sets up a keyboard shortcut that (I think) passes the Win-key keystroke to your local machine.
This opens your local start menu on top of Citrix - and from there you can Alt+Tab locally as normal.
Citrix has multiple entries in different parts of the registry, and also some settings that you can change with the Local Group Policy Editor (gpedit). Unfortunately, the only one I've found that helps is 'Hotkey13', which is only available in the registry.
I've changed multiple things, but I believe the minimal necessary steps are this:
open regedit, and navigate to Computer\HKEY_CURRENT_USER\SOFTWARE\Citrix\ICA Client\Engine\Lockdown Profiles\All Regions\Lockdown\Client Engine\Hot Keys\
ensure the value of AllowHotkey is set to 1
set the value of Hotkey13Shift; I've used Shift, if I recall correctly it accepts Ctrl and Alt and some combinations joined by +
set the value of Hotkey13Char; I've used F1, and think it accepts all Fx keys and possibly some others
restart Citrix, reconnect to your remote desktop, and test your chosen combination
Now, to access my local machine from within a Citrix session I press Shift+F1 to open my local Start menu and give focus to my local machine, and then while it is open Alt+Tab or anything else acts locally.
A screenshot of regedit highlighting Computer\HKEY_CURRENT_USER\SOFTWARE\Citrix\ICA Client\Engine\Lockdown Profiles\All Regions\Lockdown\Client Engine\Hot Keys\Hotkey13Shift
this bothered me for so long and I finally got a fix: (AHK+Virtualdesktop)
put your citrix desktop viewer in a different virtual desktop
install AutoHotKey and Windows-desktop-switcher
https://github.com/vnavkal/windows-desktop-switcher#:~:text=An%20AutoHotkey%20script%20for%20Windows%20that%20lets%20a,desktops%20by%20hotkey%2C%20etc.%20%28see%20Hotkeys%20section%20below%29.
define whatever hotkey you want to use to toggle between different virtual desktop.
it seems the AHK is able to intercept the hotkey BEFORE it is send to the Desktop Viewer.
my setup:
I use a windows desktop and 2 extra display
I put citrix on virtual desktop2, and fullscreen to all 3 screens
use the hotkey to toggle back to laptop host window virtual desktop 1 without any problem.
FN+F11 toggles out to my windows taskbar. Just need to click on the citrix icon on the task bar to go back again.
Press Ctrl+Alt+Fn+B and then W for switching to window or F to get Citrix in full screen mode. A bit faster then using arrows ...
Using SHIFT + F2 you can resize the Citrix window and access the local machine taskbar so that you can easily switch between the apps.
Refer to this link: CTX232298.
I place citrix workspace on separate windows desktop, and use CTRL + ALT + BREAK and then CTRL + WIN + LEFT/RIGHT to switch from it to another desktop.

Execute a c program as a background process

I am trying to make a background process in C to disable the visibility of the output/execution window. I used the following code but on using this the antivirus software reporst it as a threat and generates warnings:
HWND stealth;
AllocConsole();
stealth=FindWindowA("ConsoleWindowClass",NULL);
ShowWindow(stealth,0);
details are :
language : c
compiler : dev cpp
platform : windows 7/8
Is there any way I can create a background process in C without antivirus alerts?
If you just want an application that runs in the background without showing a console window, then the solution to your problem is far simpler: just don't create a console window!
Now, easier said than done. You've presumably created a Console application using the template in Visual Studio or some other IDE. This causes the application to be flagged when it is built as a Console application, and such applications always have a console window allocated to them on startup.
You don't want that, so you need to indicate that your application is not a Console application. In fact, it is just a regular Windows (Win32) application that doesn't show any windows. When writing a standard Windows application, no windows are created by default. If you don't create them in your code, then nothing gets created or displayed. And that's exactly what you want for a background process.
How you make this magic happen depends on your compiler/linker/IDE. Assuming you are using Visual Studio, you can follow these steps:
Right-click your project in the Solution Explorer.
Open the "Linker" category in the left-hand tree.
Select the "System" item in the tree.
Change the "Subsystem" setting to Windows, rather than Console.
That will automatically set the /SUBSYSTEM linker flag to specify WINDOWS, rather than CONSOLE.
(Edit: I just noticed that you said you're using Dev CPP. I've never used that IDE, but according to the directions I find online, you can just set the target to "GUI" in your project options. That should cause the -Wl,-subsystem,windows switch to be set when the linker is called. If not, find the linker flags in your project options and ensure that that switch is being passed.)
You will also need to take the final step of changing your application's entry point. Console applications have an entry point named main. For Windows applications, it is named wWinMain and has the following signature:
int WINAPI wWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PWSTR pCmdLine,
int nCmdShow);
You should be able to simply change the signature of your main method to the above signature for wWinMain and be off to the races.
If you don't want to do it the right way, there is still a better option than what you're currently doing. Instead of issuing suspicious-looking commands to hunt around, look for a process, and hide its windows (just smacks of malware, doesn't it?), you can simply deallocate the console window that is automatically created for your application. To do that, call the FreeConsole function.
It takes no parameters, because a process can only ever be attached to one console. You don't need to tell it what to free because there is only one possibility. The console window will automatically be closed when it has been detached from all processes—if your application is the one that created it and the only one that was attached to it, that means it'll close automatically.
If you need a console window again for some reason, you can call AllocConsole.

How to debug silverlight application with OpenFileDialog?

I try to debug my silverlight application that contain OpenFileDialog.ShowDialog() call - and i get error exception about security ( "SecurityException was unhandled by user code : Dialogs must be user-initiated" )
When i run the application without debug - i don't get this exception.
But i must run it in debug mode because i need to see that i doing the right thing with the file that the customer choose ...
How can i run it with in debug mode ?
Thanks for any help.
If you are, and I assume you are, initiating the ShowDialog() call with a button click, Silverlight has some strange heuristics for determining if the action was user initiated.
It does work with debugging, but if you're stepping though the code from the Button_Click to the ShowDialog(), it seems to think that because of the delay, it is not a user initiated action.
To get around this, I'd recommend using logging instead of stepping through to debug the application. Silverlight is notorious for throwing these exceptions when trying to debug the ShowDialog() calls.
*EDIT
Silverlight does not use the Click() event to determine whether the button was user initiated. It uses a host of heuristics to determine it correctly including a timer (which is why debugging fails)
This issue has been logged at Microsoft:
http://connect.microsoft.com/VisualStudio/feedback/details/597430/debugging-of-code-between-the-user-initiated-entry-point-and-call-for-the-savefiledialog-openfiledialog-showdialog-method-lead-to-the-dialogs-must-be-user-initiated-exception#details
Just put the breakpoint after .ShowDialog().
make sure that when you open the dialog it is triggered by a button click. This is done for security reasons.
Edit
Apparently there is a bug in IE that can cause this error to raise even when user initiated
http://forums.silverlight.net/forums/p/208282/491053.aspx
Another knack on the "Dialogs must be user-initiated" Security Exception in Silverlight printing

Resources