I am using chrriis.dj.nativeswing.swtimpl.components.JWebBrowser in my swing application to open web page.
The page is going to show "Facebook Authentication" page and I want to prevent user from inputting some other URL other than I specify and also Forward and Back buttons should be visible but not has no affect.
So following functions are applicable for my goal
setButtonBarVisible(false);
setLocationBarVisible(false);
Once user completes the authentication I will handle the locationChanged event.
#Override
public void locationChanged(WebBrowserNavigationEvent arg0) {
System.out.println("locationChanged!");
....
}
}
I think what you want is a custom decorator. Check the demo application, under "JWebBrowser > Custom Decorator".
In your case, you could create a new decorator class, as an adapted copy of DefaultWebBrowserDecorator or a subclass with appropriate override.
You would also have to decide if this decorator is to be used only by one instance of the JWebBrowser or all instances (like child popups, etc.)
Related
Wicket throws StalePageException only if some Ajax action has been performed on a page before duplicating the page.
Example wicket project can be found at, along with steps to reproduce the exception.
https://github.com/rjngshn/java-wicket-testing/tree/main
Is there a way to ensure this exception is not thrown?
Thanks
Rajani
The default behavior provided in Wicket is too queue AJAX requests as they come in. Let’s say you have a button with a callback that does some work when clicked and updates the UI. This means that if the button is quickly clicked three times successively, the last two requests will be queued up and processed after the first request finishes.
A simple solution is to change the behavior of the AjaxChannel from queueing to active. This means that if any AJAX requests are received while there is an active(unfinished) request being processed, they will be ignored.
So how do we override Wicket’s default behavior in one spot and ensure all AjaxChannel‘s are modified? We use a custom AjaxRequestTarget.IListener.
public class ActiveAjaxListener implements AjaxRequestTarget.IListener {
private static final AjaxChannel ACTIVE_CHANNEL = new AjaxChannel(AjaxChannel.DEFAULT_NAME, AjaxChannel.Type.ACTIVE);
#Override
public void updateAjaxAttributes(AbstractDefaultAjaxBehavior behavior, AjaxRequestAttributes attributes) {
attributes.setChannel(ACTIVE_CHANNEL);
}
}
Our ActiveAjaxListener class will modify every AJAX behavior and make sure it uses the active channel. To register it, we simple insert this line into our WebApplication init() method:
getAjaxRequestTargetListeners().add(new ActiveAjaxListener());
(I've copied this explanation from https://www.coderdreams.com/wicket-quick-tip-4-change-default-ajaxchannel-to-active/)
Another way is to use a veil that prevents the double clicks via JS/CSS. More details about this approach could be found at JavaScript / Wicket : How to display an overlay which prevents user interaction
Well, I will try to explain the problem as well as possible.
I'm using vaadin 8 and I'm using java. I'm doing an app like Youtube.
First Of All I have two important class for the problem. 1º user_header. 2º main_user_page.
On the first class (1º). I have some code integrated with components vaadin that creates a header for youtube with An image and nickname.
public class Zona_de_busqueda_UR extends Zona_de_busqueda_UR_ventana {
public Zona_de_busqueda_UR() {
imagenCabeceraURZ.setSource(new ExternalResource(parametros.getMiniaturaUsuarioNavega()));
apodoCabeceraURZ.setCaption(parametros.getApodoUsuarioNavega());
}
The two atributtes are components vaadin, and I'm setting the text to show on the app.
On the second class (2º). is one page, where (after I initiate session) I can see a normal page with videos and the header of the class (1º). THIS CLASS IS WHAT I RUN AND THIS CLASS CALL THE OTHER WHERE THE ATRIBUTTES ARE EJECUTED.
public class Pagina_inicio_UR extends Pagina_inicio_UR_ventana implements View {
Zona_de_busqueda_UR cabeceraZUR = new Zona_de_busqueda_UR();
public Pagina_inicio_UR() {
horizontalLayout.addComponent(cabeceraZUR);
}
In this class, only call the other class what you can see.
The problem is that the value of the components is showing where I refresh the app, but this would be after I initiate session. I show an example with photos.
First Of all, I initiate session.
![a busy cat(https://raw.githubusercontent.com/jmr779/images/master/primero.PNG)
And then, The header is without information...
![a busy cat(https://raw.githubusercontent.com/jmr779/images/master/segundo.PNG)
Now, I click F5 on my browser or refresh the page and I can see the information but I want see the information without having to click F5 or refresh.
![a busy cat(https://raw.githubusercontent.com/jmr779/images/master/tercero.PNG)
Thanks for the help.
I have a conceptual question.( some questions ! )
Let explain it with a real project.
I have a Login swing form,it has the main method and application starts from here.
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Login().setVisible(true);
}
}); // this method is inside main Method
The Login Form contains some TextFields and Buttons,And also some methods.
( For example when I press the Enter Button some authenticatation and action perform )
After press Enter Button, if authenticate success it goes to another form named MainTabbedForm.
Now the question is about Object Oriented Programming and class loading.
I want to access the Login Form form the MainTabbedForm. For example I want to dispose the Login Form after authentications successfully, And wanna do it in the MainTabbedForm constructor. I write a method inside the Login class to connect the Login to the MainTabbedForm. In this way :
public void disappearForm(MainTabbedForm form) {
this.form=form; // I already has defined a MainTabbedForm field in top of the Login class
this.dispose(); // Dispose the Login class
}
And use it in the constructor of the MainTabbedForm, Before using just declare a Login Form as a field in MainTabbedForm;
public MainTabbedForm(Login login) {
this.login=login;
login.disappearForm(this)
}
But it gives me NullPointException because the Login has not initialize.
And if i make a new class of Login, of course it is a new class and will not DO the thing i want, because is a new instance and not the first created Login in main method.
Now I have a question, How can i connect these two class to each other?
Of course I can make a static method to do my job ! But i do not want to do that in this way.
I think because of this class loading and art of programming the frameworks and design patterns like OSGi and MVC and others has created, to mange loading and accessing services and objects and other things more dynamically, am i right?
Now the reply to these answers are really appreciate !
In Login you could do:
MainTabbedForm mtf = MainTabbedForm(); //create
//set the required information using setters
//for example set userName which is defined in Login to MainTabbedForm
mtf.setUserName(this.userName);
//....
this.dispose(); //when no longer needed
I'm trying to set up a page view when a certain form is shown, and this is a GUI builder project. I initialized the AnalyticsService with the Google Analytics ID and my app name in the initVars method, and then when I want to fire a page view I used the AnalyticsService.visit(page name, referer). When I view the Google analytics data, is always shows no page info.
What needs to be done to get page view information sent to Google Analytics? Am I calling the visit method incorrectly?
Here's the initialization:
public StateMachine(String resFile) {
super(resFile);
// do not modify, write code in initVars and initialize class members
// there,
// the constructor might be invoked too late due to race conditions that
// might occur
}
/**
* this method should be used to initialize variables instead of the
* constructor/class scope to avoid race conditions
*/
protected void initVars(Resources res) {
Display.getInstance().lockOrientation(true);
AnalyticsService.init("(my Analytics ID)",
"rpcontrol.fastlaneinnovations.com");
AnalyticsService.setAppsMode(true);
AnalyticsService.setFailSilently(false):
....bunch more stuff}
And then elsewhere I try to trigger a page view:
#Override
protected void beforeDataLogs(Form f) {
logsContainer = findLogsContainer(f);
updateLogList();
AnalyticsService.visit("Logs", "");
}
It seems that the AnalyticsService class has two modes and if you created a mobile apps analytics you need to enable the apps mode using
setAppsMode.
This is probably better than the default behavior of using the old mobile website approach, unfortunately I don't think we can flip the default as this would break existing applications that might rely on this API.
Is there a way to get the xpath of different input/href/div of a page loaded in a javafx webview?
For example:
I want to be able to load google.com
Click search box
return xpath of the search box in system.out.
Well I dont have an working example, but I can give you all the neccessary hinds you need. I also used this several times to communicate between Java and Javascript. What happens next is that you specify an Java class which will be injected into the Javascript part and which acts like a bridge between the two languages. First you need a callback class, which is called whenever you want to pass something from the JavaScript side to Java
import netscape.javascript.JSObject;
JSObject window = (JSObject) webView.getEngine().executeScript("window");
window.setMember("jsCallBack", new JSCallBack());
The callback class need at least one method which can be called from the Javascript side. in this case it is the callback() method
public final class JSCallBack {
public JSCallBack() {}
public void callback(final String response) {
System.out.println(response) ; // this is the String which you passed on the JS side
}
}
Now it is possible to invoke the callback() method from the Javascript side and it is also possible to pass arguments.
On the Javascript side you can call the callback function of the previously injected object by
function myCallback(value){
jsCallBack.callback(value);
}
The next thing you need to do is to specify a listener in Javascript, which listens for mouse events. There is already an existing post which copes with the problem of assembling the xpath for a clicked elements. After the assembly you only need to pass the result to the callback. On this blog you can also find an exmaple for communicating between JavaFx and Javascrit via callbacks.
So fa I only have experience in passing Strings from JS to Java, which works perfectly, I don't know if it works for differnt kinds of objects.