External application open with post method

I have used Vaadin 7.6.6 version.

I want, from my dashboard screen open external application with post method.
Vaadin forum say that FormSender can be used for this , but for me it isn’t work.

I tryed to wrote next code for testing solution with form sender :

final FormSender formSender = new FormSender();
Window mainWindow = new Window();
formSender.setFormMethod(Method.POST);
formSender.setFormTarget(“http://localhost:8080/birt/frameset”);
mainWindow.setImmediate(true);
mainWindow.setContent((Component) formSender);
formSender.submit();
getUI().addWindow(mainWindow);

but I get next error when on code execution:
java.lang.ClassCastException: org.vaadin.risto.formsender.FormSender cannot be cast to com.vaadin.ui.Component

Thanks for help

Hi Angela,
as stated in
addon page
on directory it has been changed into extension, so you can’t add it as a component.
See the code example on the same page.

HTH
Marco

Thanks Marco

I corrected my code , but it doesn’t worke and further

final Button b = new Button(“Research Library”, new ClickListener() {

@Override

public void buttonClick(final ClickEvent event) {

final FormSender formSender = new FormSender();

formSender.setFormMethod(Method.POST);

formSender.setFormTarget(“https://vaadin.com/forum#!/thread/13868183”);

formSender.extend(UI.getCurrent());

formSender.submit();

}

});

Hi Angela,
did you notice some kind of errors on logs or browser console?
Have you correctly recompiled your widgetset?

Hi Marco

I don’t have any error on browser consola.
Maybe my servlet doesn’t set correct for this.

What do you mena ?

I have thise code in servlet

public class DashboardServlet extends VaadinServlet {

private static final long serialVersionUID = -4651908737680452459L;

public static String username = null;

public static String password =null;

@Override

protected void servletInitialized() throws ServletException {

super.servletInitialized();

getService().setSystemMessagesProvider(

new SystemMessagesProvider() {

private static final long serialVersionUID = 1649255971423583972L;

@Override

public SystemMessages getSystemMessages(

SystemMessagesInfo systemMessagesInfo) {

CustomizedSystemMessages messages = new CustomizedSystemMessages();

messages.setSessionExpiredNotificationEnabled(false);

return messages;

}

});

}

@Override

protected void service(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {

super.service(request, response);

if (username == null)

{

username= request.getParameter(“un”);

password= request.getParameter(“pw”);

}
}}

Hi Angela,
having a better look at your code I noticed that you set your url as
target
not as
action
of the from

Try use

formSender.setFormAction("http://localhost:8080/birt/frameset"); instead of

formSender.setFormTarget("http://localhost:8080/birt/frameset");

By the way, do not store user data in your servlet; the same servlet instance may serve different users

HTH
Marco

Marco,

I made solution with executing javascript from Vaadin. I think that 7.6.6 doesn’t suported formSender. It is solution :

              URL url = new URL(url);
        StringBuilder script = new StringBuilder();
       
               script.append("my_form=document.createElement('FORM');");
               script.append("my_form.name='myForm';");
               script.append("my_form.method='POST';  ");
               script.append("my_form.target='_blank';  ");
               script.append("my_form.action='" + url + "';");

               script.append("my_tb=document.createElement('INPUT'); ");
               script.append("my_tb.type='HIDDEN';  ");
              
               script.append("my_tb.id='" +  id + "';");
               script.append("my_tb.name='" +  name + "';");
               script.append("my_tb.value='" + value +"';");
               script.append("my_form.appendChild(my_tb); ");

               script.append("my_tb=document.createElement('INPUT'); ");
              script.append("my_tb.type='HIDDEN';  ");

               script.append("my_tb.id='" +  id + "';");
               script.append("my_tb.name='" +  name + "';");
               script.append("my_tb.value='" + value +"';");

              script.append("my_form.appendChild(my_tb); ");

               script.append("document.body.appendChild(my_form); ");
               script.append("my_form.submit();");
               JavaScript.getCurrent().execute(script.toString());

thanks
Angela