SnapIns

From JVantage

Revision as of 22:08, 10 February 2009 by Admin (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

A snap-in is simply a mechanism that allows jVantage to pass control to your custom logic after it has generated a default view, or in cases where you want to programmatically generate a page rather than allow jVantage to generate the page for you. This is fundamentally different from a form validator in that it allows you to modify the contents of the page before jVantage displays it to the user. A view interceptor can be created for any view type, including lists, simple views and input forms. Snap-ins can be invoked using any of the triggers that begin with invoke snap in. There are several variations on the snap in triggers.

Trigger Name Usage
InvokeSnapIn_GenUI_PassPageContext Generates the default page view and passes a PageContext instance (which holds the state of the page) to your EJB instance.
InvokeSnapIn_GenUI_PassSessionID Generates the default page view and passes only the associated user's sessionID to your EJB instance.
InvokeSnapIn_GenUI_PassLoginID Generates the default page view and passes the associated user name to your EJB instance.
InvokeSnapIn_PassPageContext Does not generate a default page, but passes a PageContext instance to your EJB instance.
InvokeSnapIn_PassSessionID Does not generate default page view and passes only the associated user's sessionID to your EJB instance.
InvokeSnapIn_PassLoginID Does not generates a default page view and passes the associated user name to your EJB instance.

All of these triggers take the JDNI name of your EJB followed by the method name to execute on that EJB. The arguments to form:

JNDIName::MethodName

such as;

ejb/MyEJB::calculateTaxes

Given the above arguments, jVantage will look up and bind to an EJB at the namespace location of ejb/MyEJB and execute the method called calculateTaxes. Depending on which trigger you have chosen, jVantage will pass either a contextual PageContext instance, the current user session ID or the user's login ID. In most cases you'll probably elect to have jVantage pass a PageContext instance. A PageContext instance contains all of the data that jVantage plans to display to the user. From within your custom code you can easily override any data and pass control back to jVantage. From there, jVantage will continue processing the page and ultimately display it to the user, showing the changes you made.

public class TestSnapInBean implements javax.ejb.SessionBean {
    public void setSessionContext(javax.ejb.SessionContext sessionContext)
        throws javax.ejb.EJBException, java.rmi.RemoteException {
    }

    public void ejbActivate() throws javax.ejb.EJBException, java.rmi.RemoteException {
    }

    public void ejbCreate() {
    }

    public void ejbPassivate() throws javax.ejb.EJBException, java.rmi.RemoteException {
    }

    public void ejbRemove() throws javax.ejb.EJBException, java.rmi.RemoteException {
    }

    public SnapInResponse execute(PageContext pageContext)
        throws SnapInException {
        SnapInResponse siResponse = pageContext.getSnapInResponse();

        try {
            siResponse.addErrorMessage("This is my test error message");
            siResponse.setTagValue("MyTestTag", "This is my test tag value.");
            siResponse.setFormDisplayLabel("phoneW", "--SnapIn DisplayLabel--");
            siResponse.setFormValue("name", "--SnapIn Name Value--");
            siResponse.setFormValue("firstName", "--SnapIn Name Value--");
        } catch (Exception e) {
            throw new SnapInException("Exception", e);
        }

        return siResponse;
    }
}