Hey guys, im new to vaadin i am trying to submit a simple form with FormSender, but it does not seem to redirect me to my page while submitting it…
here is all my code:
the code for my first Window
package com.example.formsenderexample;
import org.vaadin.risto.formsender.FormSender;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Window;
import com.vaadin.ui.Button.ClickEvent;
public class FirstWindow extends Window{
Label l1 = new Label("I am a main window");
TextField t1 = new TextField("Enter anything");
Button btn = new Button("Press me after entering the value");
final FormSender formSender = new FormSender();
String url;
public FirstWindow(final Window SecondWindow) {
// TODO Auto-generated constructor stub
addComponent(l1);
addComponent(t1);
addComponent(btn);
formSender.setFormMethod(FormSender.Method.POST);
url = (String)SecondWindow.getURL().toString();
formSender.setFormTarget(url);
btn.addListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
// TODO Auto-generated method stub
formSender.addValue("value", (String)t1.getValue());
System.out.println(url);
formSender.submit();
}
});
}
}
The code for my Second Window
package com.example.formsenderexample;
import java.util.Map;
import com.vaadin.terminal.ParameterHandler;
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;
public class SecondWindow extends Window
implements ParameterHandler{
Label l1 = new Label();
public SecondWindow() {
// TODO Auto-generated constructor stub
l1.setValue("I am a 2nd Window");
addComponent(l1);
}
@Override
public void handleParameters(Map<String, String[]> parameters) {
// TODO Auto-generated method stub
//super.handleParameters(parameters);
if(parameters.containsKey("value")){
String value = parameters.get("value")[0]
;
Label l2 = new Label("Value from the 1st window: " + value);
addComponent(l2);
}
}
}
and here is the main application
package com.example.formsenderexample;
import com.vaadin.Application;
import com.vaadin.ui.*;
public class FormsenderexampleApplication extends Application {
@Override
public void init() {
final Window secondWindow = new SecondWindow();
secondWindow.setName("secondWindow");
addWindow(secondWindow);
final Window mainWindow = new FirstWindow(secondWindow);
addWindow(mainWindow);
setMainWindow(mainWindow);
}
}