Reset/Refresh Application Based on User Button Push

Here is the scenario:

I have a data entry form that has a jCaptcha (from the Vaadin add-ons library) and a submit button. When the user presses the submit button, the software does calculations and displays a modal dialog box with the results.

The modal dialog has a close button as one would expect. What I want to do is reset the data entry form to the initial state (with prompting text boxes, etc.) and with a reset captcha image.

How can I force the application to refresh or reset?

If I have to reset all of the components manually, how do I rest the jCaptcha field. Once the image is validated, it cannot be used again and I can’t figure out how to force it to generate a new image value. Thoughts?

Thanks,
Tom

The normal way to reset a Vaadin application is to call Application.close(). This closes the current session, forgets ALL data, and essentially makes the page behave as the user is just now seeing it for the first time. Just make sure you haven’t used setLogoutURL() in your application class so that the user won’t be forwarded to another page.

close() is a good way or then you can also reset a part of the app by recreating a layout, window or the fields themselves. This will leave the application instance intact, if there is something that you want to save.

I have a similar kind of requirement but I need to refresh couple of panels and all its related layouts and components. I tried to used application.close in the cancelButtonListner but when I do so it closes complete application context and I got the below exception. I believe Exception is because application does not exist any more but not sure how to recreate the application again.

16:10:55,919 SEVERE [Application]
Terminal error:
java.lang.NullPointerException
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.endApplication(AbstractCommunicationManager.java:1801)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.paintAfterVariableChanges(AbstractCommunicationManager.java:804)
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:767)
at com.vaadin.terminal.gwt.server.PortletCommunicationManager.handleUidlRequest(PortletCommunicationManager.java:242)
at com.vaadin.terminal.gwt.server.AbstractApplicationPortlet.handleRequest(AbstractApplicationPortlet.java:465)
at com.vaadin.terminal.gwt.server.AbstractApplicationPortlet.serveResource(AbstractApplicationPortlet.java:740)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:118)
at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:71)
at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:93)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:444)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310)
at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:636)
at com.liferay.portlet.InvokerPortletImpl.invokeResource(InvokerPortletImpl.java:750)
at com.liferay.portlet.InvokerPortletImpl.serveResource(InvokerPortletImpl.java:505)
at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:927)
at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:660)
at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:240)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:170)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:516)
at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:493)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:113)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:113)
at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:121)

In your case I’d go with Jens’ suggestion: instead of closing the application, recreate the Panels (and other layouts you wish to change) and use replaceComponent() or removeAllComponents() and addComponent().