001// Licensed under the Apache License, Version 2.0 (the "License");
002// you may not use this file except in compliance with the License.
003// You may obtain a copy of the License at
004//
005//     http://www.apache.org/licenses/LICENSE-2.0
006//
007// Unless required by applicable law or agreed to in writing, software
008// distributed under the License is distributed on an "AS IS" BASIS,
009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010// See the License for the specific language governing permissions and
011// limitations under the License.
012
013package org.apache.tapestry5.services;
014
015import java.util.Collection;
016
017/**
018 * Defines how changes to fields (within components, within pages) may have their values persisted between requests.
019 * Different implementations store the field values {@linkplain org.apache.tapestry5.internal.services.SessionPersistentFieldStrategy
020 * in the session}, {@linkplain org.apache.tapestry5.internal.services.ClientPersistentFieldStrategy on the client}, or
021 * elsewhere.
022 */
023public interface PersistentFieldStrategy
024{
025    /**
026     * Posts a change of a persistent property.
027     *
028     * @param pageName    the name of the page containing the component
029     * @param componentId the nested id path of the component (or null for the page's root component)
030     * @param fieldName   the name of the field whose persistent value has changed
031     * @param newValue    the new value for the field, possibly null
032     */
033    void postChange(String pageName, String componentId, String fieldName, Object newValue);
034
035    /**
036     * Finds all persistent changes previously stored for the named page (for the current active session or client).
037     */
038    Collection<PersistentFieldChange> gatherFieldChanges(String pageName);
039
040    /**
041     * Discards any saved changes for the name page. There is no expectation that data already gathered from the
042     * strategy and presumably dumped into component instance fields will be affected, but future field access (within
043     * this request or a later one) will show no data for the indicated page.
044     *
045     * @param pageName logical name of page whose field persistent data should be discarded
046     */
047    void discardChanges(String pageName);
048}