@Override protected void didReadChange(Session session, String attributeName) { // For flash persistence, after reading a value, get rid of it. session.setAttribute(attributeName, null); }
public void set(Object instance, InstanceContext context, Object newValue) { request.getSession(true).setAttribute(key, newValue); }
public void discardChanges(String pageName) { Session session = request.getSession(false); if (session == null) return; String fullPrefix = prefix + pageName + ":"; for (String name : session.getAttributeNames(fullPrefix)) { session.setAttribute(name, null); } }
public String find(String path) { Session session = request.getSession(false); if(session != null){ String script = (String) session.getAttribute(path); session.setAttribute(path, null); return script; } return null; }
public <T> void set(Class<T> ssoClass, T sso) { String key = buildKey(ssoClass); getSession().setAttribute(key, sso); }
@Override public <T> void set(Class<T> ssoClass, T sso) { final String key = buildKey(ssoClass); if (sso == null) { getSession().setAttribute(key, null); return; } Object persistable = delegate.convertApplicationValueToPersisted(sso); getSession().setAttribute(key, persistable); }
private void clearSession() { Session session = request.getSession(false); if (session != null) { for (String name : session.getAttributeNames()) { session.setAttribute(name, null); } } }
@Override public <T> void set(Class<T> ssoClass, T sso) { final String key = buildKey(ssoClass); if (sso == null) { getSession().setAttribute(key, null); return; } Object persistable = delegate.convertApplicationValueToPersisted(sso); getSession().setAttribute(key, persistable); }
public final void postChange(String pageName, String componentId, String fieldName, Object newValue) { assert InternalUtils.isNonBlank(pageName); assert InternalUtils.isNonBlank(fieldName); Object persistedValue = newValue == null ? null : convertApplicationValueToPersisted(newValue); StringBuilder builder = new StringBuilder(prefix); builder.append(pageName); builder.append(':'); if (componentId != null) builder.append(componentId); builder.append(':'); builder.append(fieldName); Session session = request.getSession(persistedValue != null); // TAPESTRY-2308: The session will be false when newValue is null and the session // does not already exist. if (session != null) { session.setAttribute(builder.toString(), persistedValue); } }
public String store(final String script) { Session session = request.getSession(true); String key = createKey(script); Integer max = 0; if ( session.getAttribute(key) != null ) { List<String> names = session.getAttributeNames(prefix); for ( String name : names ) { String[] parts = name.split("-"); Integer seq = new Integer(parts[1]); if ( seq > max ) { max = seq; } } } final String fkey = key + "-" + (max+1); session.setAttribute(fkey, script); return keyToUrl(fkey); }
@Override public <T> void set(final Class<T> ssoClass, final T sso) { final String key = buildKey(ssoClass); Object entity; if (sso != null) { try { entity = JpaInternalUtils.convertApplicationValueToPersisted(entityManagerManager, sso); } catch (final RuntimeException ex) { // if entity not attached to an EntityManager yet, store it as usual sso entity = sso; } } else { entity = sso; } getSession().setAttribute(key, entity); }
@Override public <T> void set(final Class<T> ssoClass, final T sso) { final String key = buildKey(ssoClass); Object entity; if (sso != null) { try { entity = JpaInternalUtils.convertApplicationValueToPersisted(entityManagerManager, sso); } catch (final RuntimeException ex) { // if entity not attached to an EntityManager yet, store it as usual sso entity = sso; } } else { entity = sso; } getSession().setAttribute(key, entity); }
@Test public void post_change_to_root_component() { Session session = mockSession(); Request request = mockRequest(); Object value = new Object(); train_getSession(request, true, session); session.setAttribute("flash:foo.Bar::field", value); replay(); PersistentFieldStrategy strategy = new FlashPersistentFieldStrategy(request); strategy.postChange("foo.Bar", null, "field", value); verify(); }
@Test public void post_change_to_nested_component() { Session session = mockSession(); Request request = mockRequest(); Object value = new Object(); train_getSession(request, true, session); session.setAttribute("state:foo.Bar:fee.fum:field", value); replay(); SessionPersistentFieldStrategy strategy = new SessionPersistentFieldStrategy(request); strategy.postChange("foo.Bar", "fee.fum", "field", value); verify(); }
@Test public void post_change_to_root_component() { Session session = mockSession(); Request request = mockRequest(); Object value = new Object(); train_getSession(request, true, session); session.setAttribute("state:foo.Bar::field", value); replay(); SessionPersistentFieldStrategy strategy = new SessionPersistentFieldStrategy(request); strategy.postChange("foo.Bar", null, "field", value); verify(); }
@SuppressWarnings("unchecked") @Test public void set_aso() { Request request = mockRequest(); Session session = mockSession(); Class asoClass = ReadOnlyBean.class; Object aso = new ReadOnlyBean(); String key = "sso:" + asoClass.getName(); train_getSession(request, true, session); session.setAttribute(key, aso); replay(); ApplicationStatePersistenceStrategy strategy = new SessionApplicationStatePersistenceStrategy(request); strategy.set(asoClass, aso); verify(); } }
/** * TAPESTRY-1475 */ @Test public void discard_changes() { Session session = mockSession(); Request request = mockRequest(); train_getSession(request, false, session); train_getAttributeNames(session, "state:foo.Bar:", "state:foo.Bar:baz:field"); session.setAttribute("state:foo.Bar:baz:field", null); replay(); SessionPersistentFieldStrategy strategy = new SessionPersistentFieldStrategy(request); strategy.discardChanges("foo.Bar"); verify(); }
session.setAttribute("flash:foo.Bar::root", null); session.setAttribute("flash:foo.Bar:nested:down", null);
session.setAttribute(key, aso);