In Form.onSubmit can I add a SimpleAttributeModifier to that form? Actually I have a situation where the onSubmit method of the form look like this:
#Override
public void onSubmit() {
//some code
if (some_condition) {
//here I want to show Javascript confirm box or wicket modal window
//but I can not get any AjaxRequestTarget here to show that modal
add(new SimpleAttributeModifier("onSubmit", "return confirm('confirm msg')"));
}
//some code
}
It is not working. Is there any way to achieve this? Thank you.
What you're trying will definitely not work, as the onSubmit() method is not called in time. It is a server-side method called when the form is submitted. In order to show a confirm dialogue, you want some javascript executed on the client before the form is sent back from the client to the server.
You need the attachment of javascript to happen when the html is rendered, so that it's there to be called when the user clicks the submit button.
It can of course be done. I don't have my own code for it handy, but I think this example should get you pointed in the right direction.
Related
enter image description hereI am using bootstrap modal plugin for an inquiry form and am using "ng-submit" directive to save the details of the form, but when i click on the submit button the form gets submitted but the modal window does not gets closed. How can i close the modal when details have been submitted.
Please find the image for modal reference.
Thanks for help in advance
For a quick hack around, in your callBackUser() method in controller add the below piece of code,
$('#exampleModal').modal('hide');
Again not advisable to mix jQuery and Angular.
EDIT As per your comments, clear all your form data like this,
$scope.callback.firstName = "";
$scope.callback.useremail= ""
And so on.. for all the fields!
I have a button through which i INVOKE a java method :
<h:commandButton value="My Schedule" action="#{empDutySchedBean.viewMyTask}" rendered="#{welcomeBean.workSchedule}" class="mainLinks"/>
now through this method viewMyTask() i get a List of values returned from the database.
public List viewMyTask()
{
setEmpID((String) session.getAttribute("userName"));
setEmpDuty(ts.getMyTask(getEmpID()));
return empDuty;
}
From here i want tht with the click of a button, the user is redirected to another page and the List data shows up.
I dont understand how to REDIRECT to another HTML page and display the LIST data.
NOTE: --> this button is basically a menu on my webpage. For the other menus i have used an anchor tag. However as you cannot invoke a method using anchor tag, i have used button tag. But because of this, I am not being able to redirect
Some Ways that i think it can be solved are:
use anchor tag instead on button to redirect to the other page AND then use onLoad method of javascript to INVOKE java method
invoke another method after viewMyTask() to perform the redirection.
I dont kw how these methods would work though.
First off, I assume you already know how to return the data Java side, in which case this is really just a javascript question. To do simple post-gets, I usually use Ajax, like so:
new Ajax.Request(myUrlToCall, {
method:'POST',
onComplete: function(transport) {
window.location.replace(theRedirectUrl);
}
});
This will call whatever url you wanted to call Java side, then on the completion of this call, will redirect you to whatever url you want to go to. If you need to send some parameters to the java side, all you need to add is:
parameters:myParamVar,
after the method:'POST' line, and if you want your java side to return the url, then all you'd need to do is send it as json or similar in the response, then do:
window.location.replace(transport.responseJSON["theRedirectUrl"])
Hope that helped!
I'm currently trying to implement an "import wizard" for an application using JFace Wizard.
Basically I have to add the next page "just in time" based upon the input from the user, as each "step" within the wizard is depends upon the previous ones.
So, in the constructor of WizardImport I would add the first page, using:
addPage(new WizardImportSourcePage(data));
Within this page (WizardImportSourcePage) I would then like to add the next page, depending upon the chosen source, e.g.:
btnCsv.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent arg0) {
data.getWizard().addPage(new WizardImportSourcePage(data));
setPageComplete(true);
}
});
As you can see all of this happens in the appropriate Listener. Unfortunately this doesn't work. The Wizard is missing the "Next" button, but only shows the "Finish" button, as it doesn't know anything about the next page until the button is actually being pressed. I've already tried to invoke updateButtons(), but it didn't change anything.
So, any suggestions how to make it work? What would be the right way to build the wizard pages dynamically? Most tutorials seem to assume that the pages are created in the beginning and only the ordering is changed using getNextPage().
In your code extending Wizard you can override
public IWizardPage getNextPage(IWizardPage page)
which lets you decide which page to return next given the current wizard page (there is also a getPreviousPage.
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