Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a simpler alternative to ApplicationContext.TransactionListener #903

Closed
vaadin-bot opened this issue Nov 19, 2009 · 3 comments
Closed

Comments

@vaadin-bot
Copy link
Collaborator

Originally by @Artur-


The context level transaction listener is too complex for most cases.

  • It is hard to grasp that the transaction listener is called for all applications belonging to the session.
  • The user must manually compare the application parameter to verify the call is relevant for the application
  • The transaction listener is called after init and not before which makes it impossible to init an application based on something passed in the servlet request.

Proposed solution:

  • Create an additional application level transaction listener
  • public interface ApplicationTransactionListener extends Serializable
  • public void transactionStart(Object transactionData);
  • public void transactionEnd(Object transactionData);
  • The transaction listener is called at the start of every request
  • If application implements the interface
  • Before init() in first UIDL request

Imported from https://dev.vaadin.com/ issue #3731

@vaadin-bot
Copy link
Collaborator Author

Originally by @Artur-


Might make it into 6.2

@vaadin-bot
Copy link
Collaborator Author

Originally by @mstahv


in [10107] added a derived solution of Artus proposition.

Added added HttpServletRequestListener and PortletRequestListener which can be implemented by Application. Application implementing those interfaces will be called with both request and response before "payload" is applied to application and after terminal is done with its response.

With these interfaces it should be easier to implement common TransactionListener tasks + we have better typed arguments for developers. Still we are not polluting basic application with terminal dependent stuff. An example of using cookies below:


public class CookieExample extends com.vaadin.Application implements
        HttpServletRequestListener, PortletRequestListener {

    private HttpServletResponse response;
    private HttpServletRequest request;

    @Override
    public void init() {
        setMainWindow(new Window());

        Button b = new Button("Set cookie");

        b.addListener(new Button.ClickListener() {

            public void buttonClick(ClickEvent event) {
                Cookie cookie = new Cookie("foo", "bar");
                cookie.setMaxAge(60);
                response.addCookie(cookie);
            }
        });

        Button bs = new Button("Get cookie");

        bs.addListener(new Button.ClickListener() {

            public void buttonClick(ClickEvent event) {
                Cookie[] cookies = request.getCookies();
                for (int i = 0; i < cookies.length; i++) {
                    Cookie cookie = cookies[i];
                    if (cookie.getName().equals("foo")) {
                        getMainWindow().showNotification(
                                cookie.getName() + " : " + cookie.getValue());
                    }
                }
            }
        });

        getMainWindow().addComponent(b);
        getMainWindow().addComponent(bs);

    }

    public void onRequestEnd(HttpServletRequest request,
            HttpServletResponse response) {
        this.response = null;
        this.request = null;
    }

    public void onRequestStart(HttpServletRequest request,
            HttpServletResponse response) {
        this.response = response;
        this.request = request;
    }

    public void onRequestEnd(PortletRequest request, PortletResponse response) {

    }

    public void onRequestStart(PortletRequest request, PortletResponse response) {
        // TODO Auto-generated method stub

    }

}


@vaadin-bot
Copy link
Collaborator Author

Originally by @mstahv


in [10114] ensured start/end to happen in pairs for both new interfaces + transaction listeners

@vaadin-bot vaadin-bot added this to the Vaadin 6.2.0-pre1 milestone Dec 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant