I work on a Java project with Echo Studio 3.
I have a servlet that display a Pdf file.
I call this servlet with a button that open a new window with this code:
Command open = new BrowserOpenWindowCommand("http://localhost:8080/MyApp/app/DisplayFile", "_blank");
Application.getActive().enqueueCommand(open);
I would like to allow the access to this servlet only to users who clicked on this button, but I don't know how to handle this.
Any idea?
Pass an additional parameter in the link to identify the click.
Or else capture the click event in javascript and add additional parameter to the server url to inform that the button has been pressed.
Related
I have a form with many data. In this form the user can click on "view report" button which will load a pdf file from the folder, if the report exists.
I'm trying to find a way that the button will appear flat and won't be able to click it if there is no report to load and the button will appear regular and will be abled to click on if the report exists and can be load.
basically i'm trying to avoid clicking on the button in any case and if the report exists it will be loaded and if not it will gives an error msg.
The goal is that just by looking at the button the user will know if there is a report or if there isn't.
How can I make it possible assuming I have 2 images ready (flat and regular).
if (fileExists)
JButton.setEnabled(true):
else
JButton.setEnabled(false);
Have you thought of just using:
myButton.setEnabled(false);
and later when it's ok to use the button:
myButton.setEnabled(true);
I want to have something like this:
public void setButton(){
document.getElementById('scan').disabled=false;
}
scan is the ID of the button in the JSP.
What you are dealing here is html and javascript and not java. Java based systems at the server will generate the html/css/js based code (after executing the JSP) and send it to browser. For enable/disabling and disabling the buttons, use javascript.
Not sure what you use case is, but you can use following javascript code code to enable/disable the buttons
document.getElementById("scan").disabled = true;
This can be called on any event (like page load etc)..
EDIT:
In light of new requirement (Capture USB events), this may not be as straightforward as it seemed. I would suggest following approach.
Write a signed Java Applet. This Applet will use some USB interfacing APIs (e.g jUSB) to listen to the USB plugin events.
Then, from this Applet use Applet Javascript interaction to call the javascript function to enable the button (assuming that the button is disabled when the page loaded).
So it works as follows
When you hit the URL, browser loads the page and Applet (with Scan button disabled by default)
You plugin the USB device
Java code in the applet listens to this event
The listener calls the Javascript function in the page which enables the Scan button.
All the HTML in JSP compiles on server side and comes to Client.
If you want to do something you need to make a request.
You can do it directly with html in your jsp
<input type="button" name=myButton id="scan" value="disable" disabled>
If javascript
document.getElementById("scan").disabled=true; //not false
maybe you can use this
document.getElementById("scan").disabled = true;
or jquery
$("#scan").disable = true;
I need to read the content of a website via MATLAB but the problem is when I load the website as:
URL = java.net.URL(UrlNew);
urlConnection = URL.openConnection();
urlConnection.connect();
str = regexprep(fileread(filename),'\s*',' ');
The website redirects me to a page which I have first to press "I agree" button and then it goes to the requested page.
How can I handle this situation in MATLAB. I need to somehow click the "Agree" button in MATLAB to have access to the original webpage.
Thx
First you need to find out the value of the action attribute of the form on your original page. You can do this by examining the source code of the page, looking for the form tag containing the Agree button, or by manually clicking on the button and looking at the Network activity tab in the Chrome Developer Tools or Firebug in Firefox.
Once you find this, find out how to send POST requests in Java and simulate the clicking of the button by sending a POST request to the action URL of the form. If you collect the output from the socket after that, it should correspond to the page you want.
Here is my situation: the user selects a section (for example from a dropdown) such as "Section1," "Section2" or "Section3." Then he clicks the OK button (or some link).
What I need to happen: after he clicks on that button/link, he will be redirected to the selected section, e.g. www.homepage.com/docs#section2.
So far, I have not been able to process the form from Link's onClick method, nor have I been able to call some clickLink on Link from the Button method onSubmit().
I would prefer not to use AJAX or JavaScript. How can I do this?
That's because a Link doesn't submit the form. It just acts as a link to somewhere. To access your formdata you'll need to submit the form first. Try using a SubmitLink instead of a Link and call
getRequestCycle().setRequestTarget
(new RedirectRequestTarget("www.homepage.com/docs#section2"));
from the onSubmit function of the SubmitLink.
Judging from the Javadoc this should work but I can't test it right now.
A RequestTarget that will send a redirect url to the browser. Use this if you
want to direct the browser to some external URL, like Google etc, immediately.
Or if you want to redirect to a Wicket page. If you want to redirect with a
delay the RedirectPage will do a meta tag redirect with a delay.
Did you try Link.setAnchor(Component)?
I have jquery pop form to upload a file, after on submit (the page refresh and the pop close) i check something about the file and then if there's something wrong i need to pop up that form again (from the java code?), how could i do that ?
You should use ( or must be using) ajax in jquery with a popup.
When the user hits "submit", control goes to server side code.
The code runs to upload the file.
Whatever the result of upload (success/failure), that message is sent to the popup with ajax automatically.
In case, there is problem in uploading the file then, along with the failure message, you can send in the div which contains your form.
I think rather than refreshing the page to close the popup, allow the user to close the popup with close button.
When "something is wrong" the server-side code (this applies to any language) should include within the HTML content Javascript that will trigger the "form" to be displayed again.
As I feel dizzy presently,can't write the code,but will try to break whole procedure in multiple steps:-
On Trigger(by some event) a pop up form will open from submission,which will have a button which will be calling a OnClick Event,which will be containing an Ajax call for client server communication
till the response don't close or fade out the Pop up box.
from server expect two tags SUCCESS or ERROR
a) On SUCCESS, remove form DIV and fade out/close the pop up
with a success message b)On Error,display a refreshed form DIV
And so on