I must be missing something simple, but I'm stuck.
I created a FormPanel in gwt that, according to firebug sends the request.
the link works, as I copied the requestlink from firebug and tried it natively in a browser window.
Yes, client and server host are the same --> localhost.
But the answer doesn't arrive at gwt. Not even the client browser - firebug shows no result eighter.
This is my little form:
Button form = new Button ("SendForm", new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
logger.log(Level.FINER, "Creating SubmitForm...");
TextBox cmd = new TextBox();
cmd.setName("cmd");
cmd.setText("GetMenuitemList");
Button sendbutton = new Button("Senden");
logger.log(Level.FINEST, "Creating grid...");
Grid grid = new Grid(1, 2);
grid.setWidget(0, 0, new Label("Command"));
grid.setWidget(0, 1, cmd);
VerticalPanel vPan = new VerticalPanel();
//vPan.add(grid);
vPan.add(sendbutton);
logger.log(Level.FINEST, "Creating FormPanel...");
final FormPanel formPan = new FormPanel();
formPan.setMethod(FormPanel.METHOD_POST);
formPan.setAction(RequestHelper.getLink("Menu.php"));
logger.log(Level.FINEST, "Binding Send button...");
logger.log(Level.FINEST, "Binding SubmitHandler...");
formPan.addSubmitHandler(new SubmitHandler() {
#Override
public void onSubmit(SubmitEvent event) {
OptionPane.showMessageDialog("Form submit", event.toDebugString(), MessageType.INFO, true);
}
});
logger.log(Level.FINEST, "Binding SubmitCompleteHandler...");
formPan.addSubmitCompleteHandler(new SubmitCompleteHandler() {
#Override
public void onSubmitComplete(SubmitCompleteEvent event) {
OptionPane.showMessageDialog("Form SubmitComplete", event.toDebugString(), MessageType.INFO, true);
}
});
logger.log(Level.FINEST, "Adding grid to formpan...");
formPan.add(grid);
formPan.add(vPan);
logger.log(Level.FINEST, "Creating DialogBox...");
final DialogBox box = OptionPane.createClosableBox("TestForm", true);
sendbutton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
formPan.submit();
box.hide();
}
});
box.add(formPan);
box.center();
}
});
The expected answer looks like this:
{"sessionid":"6dbqibo25e0bn46fldqh37psj5","data":[{"title":"Start","Controller":"Start","Action":"Index","tooltip":"Startseite, Begr\u00fc\u00dfung","prefetch":"1"},{"title":"Register","Controller":"Person","Action":"Index","tooltip":"Neue Benutzer registrieren","prefetch":"0"},{"title":"Daten","Controller":"Contact","Action":"Index","tooltip":"Die eigenen Daten bearbeiten","prefetch":"1"},{"title":"Teilnehmerlisten","Controller":"Lists","Action":"Index","tooltip":"Listen der registrierten Benutzer","prefetch":"0"},{"title":"Suche","Controller":"Search","Action":"Index","tooltip":"Namenssuche nach Benutzer mit Kontaktm\u00f6glichkeit","prefetch":"1"},{"title":"Kalender","Controller":"Calendar","Action":"Index","tooltip":"Termine","prefetch":"1"},{"title":"Newsletter","Controller":"Newsletter","Action":"Index","tooltip":"Verschicken von Newslettern","prefetch":"1"},{"title":"Wettk\u00e4mpfer","Controller":"Competitor","Action":"Index","tooltip":"Zugriff auf Wettk\u00e4mpfer","prefetch":"1"},{"title":"Upload","Controller":"Upload","Action":"Index","tooltip":"Bilder, Videos o.\u00e4. hochladen","prefetch":"0"},{"title":"Administration","Controller":"Admin","Action":"Index","tooltip":"Datenbankfunktionen und Benutzerrechte","prefetch":"1"}]}
So, what is going wrong here?
BTW, I'll use this technique for a login form. I read, its better to do this in a form than via RequestBuilder (that worked already). File upload will come later, so the form question needs an answer in any case...
Thank you in advance.
Markus
Edit: ok, I tested on Chromium, Konqueror and Opera also - the code works. It's just firefox. Ideas to get it going with firefox?
I'm a total newby in eclipse and gwt... maybe some compiler option?
I found and solved the problem myself: after the form.submit was executed, I hid the form Panel.
That is not allowed as javadoc says:
The FormPanel must not be detached (i.e. removed from its parent or otherwise disconnected from a RootPanel) until the submission is complete. Otherwise, notification of submission will fail.
Related
How to defeat IE and Firefox dialog popup when trying to setResponsePage() from a wicket modalWindow per below. Dialog popup demands an answer to: "This page is asking you to confirm that you want to leave - data you have entered may not be saved."
AjaxLink signInContainer = new AjaxLink("signInContainer") {
#Override
public void onClick(AjaxRequestTarget target) {
target.appendJavascript("Wicket.Window.unloadConfirmation = false;");
modalWindow.close(target);
setResponsePage(SignInPage.class);
modalWindow.close(target);
}
};
-Rich
In wicket 6.x and above you can simply set showUnloadConfirmation to false:
final ModalWindow modalWindow = new ModalWindow("modalWindow");
modalWindow.showUnloadConfirmation(false);
target.appendJavascript("Wicket.Window.unloadConfirmation = false;"); doesn't work because it must run before modal.show(target);.
You could either prepend, instead of append, the script, when opening the window:
add(new AjaxLink<Void>("show") {
#Override
public void onClick(AjaxRequestTarget target) {
target.prependJavascript("Wicket.Window.unloadConfirmation = false;");
modal.show(target);
}
});
or add a behavior, to execute it on onload:
modal.add(new AbstractBehavior() {
#Override
public void renderHead(IHeaderResponse response) {
response.renderOnLoadJavascript("Wicket.Window.unloadConfirmation = false;");
}
});
But, it must be called before opening the modal window, not when navigating away from the page (setResponsePage()).
I believe setResponsePage() should be accompanied by some other methods to behave properly. For example, I often include setRedirect(true) when using this technique. I'm not sure what all is going on behind the scenes there, but perhaps try that.
EDIT: This is a hack, use the alternative described in my other answer.
Try this:
public void onClick(AjaxRequestTarget target) {
modal.close(target);
CharSequence url = urlFor(HomePage.class, new PageParameters("gone=true"));
target.appendJavascript("window.location='" + url + "';");
}
I am adding a file upload functionality to an application.
I'm following some tutorials, so far I get something like this:
final FormPanel form = new FormPanel();
form.setAction(GWT.getModuleBaseURL() + "fileupload");
form.setEncoding(FormPanel.ENCODING_MULTIPART);
form.setMethod(FormPanel.METHOD_POST);
final FileUpload fileUpload = new FileUpload();
submit.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
String filename = fileUpload.getFilename();
if (filename.length() == 0) {
} else {
form.submit();
}
}
});
I've made the fileupload servlet, and I guess it's okay. The problem is, after the form.submit() the page gets reloaded, but I would like to send it asynchronously instead.
Something like that is dead simple in php and jquery.
Could anybody help?
Best regards.
For submitting arbitrary data (objects) use GWT-RPC. For file upload take a look at gwtupload.
Is it possible to nest forms in Wicket that are independent of each other? I want to have a form with a submit button and a cancel button. Both buttons should direct the user to the same page (let's call it Foo). The submit button should send some info to the server first; the cancel button should do nothing.
Here's a really simplified version of my existing code:
Form form = new Form() {
public void onSubmit()
{
PageParameters params = new PageParameters();
params.put("DocumentID", docID);
setResponsePage(Foo.class, params);
}
};
DropDownChoice<String> ddc = new DropDownChoice<String>("name", new PropertyModel<String>(this, "nameSelection"), names);
ddc.setRequired(true);
final Button submitButton = new Button("Submit") {
public void onSubmit() { doSubmitStuff(true); }
};
final Button cancelButton = new Button("Cancel") {
public void onSubmit() { doSubmitStuff(false); }
};
form.add(ddc);
form.add(submitButton);
form.add(cancelButton);
form.add(new FeedbackPanel("validationMessages"));
The problem is, I just added a validator, and it fires even if I press the cancel button, since the cancel button is attached to the same form as everything else. This could be avoided if the cancel button were in a separate form. As far as I know, I can't create a separate form because — due to the structure of the HTML — the separate form would be under the existing form in the component hierarchy.
Can I make the forms separate somehow in spite of the hierarchy? Or is there some other solution I can use?
EDIT:
In response to Don Roby's comment, this is a bit closer to what my code looked like back when I was trying setDefaultFormProcessing():
Form<Object> theForm = new Form<Object>("theForm") {
public void onSubmit()
{
PageParameters params = new PageParameters();
params.put("DocumentID", docID);
setResponsePage(Foo.class, params);
}
};
final CheckBox checkbox = new CheckBox("checkbox", new PropertyModel<Boolean>(this, "something"));
checkbox.add(new PermissionsValidator());
theForm.add(checkbox);
final Button saveButton = new Button("Save") {
public void onSubmit()
{ someMethod(true); }
};
final Button cancelButton = new Button("Cancel") {
public void onSubmit()
{ someMethod(false); }
};
cancelButton.setDefaultFormProcessing(false);
theForm.add(saveButton);
theForm.add(cancelButton);
theForm.add(new FeedbackPanel("validationMessages"));
There is an even simpler solution: call the setDefaultFormProcessing method on the cancel button with false as a parameter:
cancelButton.setDefaultFormProcessing(false);
This way, clicking the cancel button will bypass the form validation (and model updating), directly calling the onSubmit function.
It is possible to "nest" forms in wicket.
See this wiki entry
for some notes on how it works and this wiki entry for how it interacts with validation.
But for what you're after, the answer from Jawher should have worked and is much simpler.
Look at this example code for hints on getting that working.
I'm wondering if you've simplified your code too far in this posting. Can you produce a sample small enough to post that definitely has the problem?
Label label1 = new Label(container, SWT.NULL);
label1.setText("Enter the Password ");
text1 = new Text(container, SWT.BORDER | SWT.PASSWORD);
text1.setText("");
text1.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
if (!text5.getText().isEmpty()) {
setPageComplete(false);
}
}
});
hi, i am creating form using SWT in eclipse can anyone tell me how to validate that form entry above is the sample code of that..actually i want to validate password field it should be minimum length of 6.How to do this please reply.
You can use a Message Manager, as described in Eclipse Form article.
As discussed above, support has been added to show messages in the form heading. To make the handling of multiple messages within a form easier, a message manager has been made available in 3.3 through the IManagedForm interface. The manager is provided as an interface (IMessageManager).
The message manager will track multiple messages for the user at a time and will show text-based on the most severe message present at any given time (ERROR > WARNING > INFO).
It also provides the ability, when adding a message, to associate a control with it. If this is done, the message manager will decorate the specified control with an image appropriate to the message type.
Regarding the specific issue, you can look at similar implementations of this problem, like the org.eclipse.team.internal.ccvs.ui.wizards.ConfigurationWizardMainPage class:
// Password
createLabel(g, CVSUIMessages.ConfigurationWizardMainPage_password);
passwordText = createPasswordField(g);
passwordText.addListener(SWT.Modify, listener);
Listener listener = new Listener() {
public void handleEvent(Event event) {
if (event.widget == passwordText) {
// check its length
I have a Page with a Wizard component. The user can navigate the panels of the wizard by using the next and previous buttons which I have performing full (non-ajax) form submissions so that the app is back-button friendly.
When the next button is clicked, I would like to attempt ajax form validation (if javascript is enabled). I tried doing:
nextButton.add( new AjaxFormValidatingBehavior( form, "onsubmit") );
to add such validation. The behaviour works - however, when validation errors occur the browser still submits the entire form.
What is the Wicket way to prevent the browser from submitting the form in this case?
Override the onError() method on either the form or the AjaxFormValidatingBehavior. If you do it on the behavior, I am not sure if that will prevent the form from submitting or not.
new AjaxFormValidatingBehavior( form, "onsubmit") {
public void onSubmit() {}
public void onError() {}
}
Maybe a bit to late but here is the answer:
public class SomePage extends WebPage {
private FeedbackPanel feedbackMessageError = new FeedbackPanel("feedbackTabAddEmpMesError", new ExactLevelFeedbackMessageFilter(FeedbackMessage.ERROR));
public SomePage(String id) {
final Form<Void> form = new Form<>("tabFormAddEmp");
add(form);
//Name textfield cannot be empty
final FormComponent<String> tabAddEmpName = new RequiredTextField<>("tabAddEmpName", Model.of(""));
tabAddEmpName.setLabel(Model.of("Name"));
tabAddEmpName.setOutputMarkupId(true);
//Salarynumber has to be minimal 10 char long
final FormComponent<String> tabAddEmpLoon = new RequiredTextField<>("tabAddEmpLoon", Model.of(""));
tabAddEmpLoon.add(new StringValidator(10, null)).setLabel(Model.of("Salarynumber"));
tabAddEmpLoon.setOutputMarkupId(true);
final Button button = new Button("tabFormAddEmpBut");
form.add(tabAddEmpName , tabAddEmpLoon, button);
button.add(new AjaxFormValidatingBehavior(form, "onclick") {
#Override
public void onError(AjaxRequestTarget target) {
//Add feedbackpanel to your html and voila!
target.add(feedbackMessageError);
}
#Override
protected void onSubmit(AjaxRequestTarget target) {
//Do some logic over here
}
}
}
}