Example usage for org.apache.wicket Session setAttribute

List of usage examples for org.apache.wicket Session setAttribute

Introduction

In this page you can find the example usage for org.apache.wicket Session setAttribute.

Prototype

public final Session setAttribute(String name, Serializable value) 

Source Link

Document

Adds or replaces the attribute with the given name and value.

Usage

From source file:almira.sample.web.AdminPage.java

License:Apache License

/**
 * Constructor./*from  w  ww  .j a va2  s.  com*/
 */
public AdminPage() {
    super();

    final Label counterLabel = new Label(COUNTER_LABEL_ID, "0");
    add(counterLabel);

    final Label feedbackLabel = new Label(FEEDBACK_LABEL_ID);
    add(feedbackLabel);

    add(new Link<String>("increment_counter_link") {
        @Override
        public void onClick() {
            final Session session = AdminPage.this.getSession();
            int counterValue = 0;
            synchronized (session) {
                AtomicInteger counter = (AtomicInteger) session.getAttribute(COUNTER_LABEL_ID);
                if (counter == null) {
                    counter = new AtomicInteger();
                }
                counterValue = counter.incrementAndGet();
                // trigger replication to other cluster nodes
                session.setAttribute(COUNTER_LABEL_ID, counter);
            }
            counterLabel.setDefaultModel(new Model<Integer>(counterValue));
            LOG.fine("*** Catapult counter value=" + counterValue + " ***");
            feedbackLabel.setDefaultModel(new Model<String>());
        }
    });

    add(new Link<String>("rebuild_index") {
        @Override
        public void onClick() {
            try {
                indexService.rebuildIndex();
                feedbackLabel.setDefaultModel(new Model<String>("Rebuilding index."));
            } catch (Exception e) {
                feedbackLabel.setDefaultModel(new Model<String>("Error rebuilding index!"));
                LOG.log(Level.SEVERE, "Error rebuilding", e);
            }
        }
    });
}

From source file:com.mastfrog.acteur.wicket.ActeurSessionStore.java

License:Apache License

/**
 * @see org.apache.wicket.session.ISessionStore#bind(Request, Session)
 *///from w  ww .  jav  a2s  . co m
@Override
public final void bind(final Request request, final Session newSession) {
    if (getAttribute(request, Session.SESSION_ATTRIBUTE_NAME) != newSession) {
        // call template method
        onBind(request, newSession);
        for (BindListener listener : getBindListeners()) {
            listener.bindingSession(request, newSession);
        }

        Session httpSession = getHttpSession(request, false);

        if (httpSession != null) {
            // register an unbinding listener for cleaning up
            String applicationKey = Application.get().getName();
            httpSession.setAttribute("Wicket:SessionUnbindingListener-" + applicationKey,
                    new SessionBindingListener(applicationKey, newSession));

            // register the session object itself
            setAttribute(request, Session.SESSION_ATTRIBUTE_NAME, newSession);
        }
    }
}

From source file:de.alpharogroup.wicket.base.util.parameter.PageParametersExtensions.java

License:Apache License

/**
 * Copies all given source {@link org.apache.wicket.request.mapper.parameter.PageParameters} to
 * the given session {@link org.apache.wicket.Session}.
 * //w  w w .  j  a v  a 2s. co m
 * @param source
 *            The source {@link org.apache.wicket.request.mapper.parameter.PageParameters}.
 * @param session
 *            The session where the
 *            {@link org.apache.wicket.request.mapper.parameter.PageParameters} are stored.
 */
public static void copyToWicketSession(final PageParameters source, final Session session) {
    final List<INamedParameters.NamedPair> namedPairs = source.getAllNamed();
    for (final INamedParameters.NamedPair namedPair : namedPairs) {
        session.setAttribute(namedPair.getKey(), namedPair.getValue());
    }
}