本文整理汇总了Java中javax.faces.component.StateHolder类的典型用法代码示例。如果您正苦于以下问题:Java StateHolder类的具体用法?Java StateHolder怎么用?Java StateHolder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StateHolder类属于javax.faces.component包,在下文中一共展示了StateHolder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValueBinding
import javax.faces.component.StateHolder; //导入依赖的package包/类
/**
* Given a ValueExpression <code>ve</code>, return a ValueBinding.
* The returned ValueBinding will implement StateHolder and Serializable interfaces if
* <code>ve</code> implements these interfaces.
* @param ve The ValueExpression
* @return a ValueBinding equivalent to the ValueExpression
*/
public static ValueBinding getValueBinding(ValueExpression ve)
{
// if we previously wrapped a ValueBinding, unwrap it and return it, otherwise create the
// correct subclass of ValueBinding
if (ve instanceof ValueBindingValueExpression)
return ((ValueBindingValueExpression)ve).getValueBinding();
else if (ve instanceof StateHolder)
{
if (ve instanceof Serializable)
return new SerializableStateHolderValueExpressionValueBinding(ve);
else
return new StateHolderValueExpressionValueBinding(ve);
}
else if (ve instanceof Serializable)
{
return new SerializableValueExpressionValueBinding(ve);
}
else
{
return new ValueExpressionValueBinding(ve);
}
}
示例2: getValueExpression
import javax.faces.component.StateHolder; //导入依赖的package包/类
/**
* Given a ValueBinding <code>binding</code>, return a ValueExpression.
* The returned ValueExpression will implement StateHolder and Serializable interfaces if
* <code>ve</code> implements these interfaces.
* @param binding The ValueBinding
* @return a ValueExpression equivalent to the ValueBinding
*/
public static ValueExpression getValueExpression(ValueBinding binding)
{
// if we previously wrapped a ValueExpression, unwrap it and return it, otherwise create the
// correct subclass of ValueBindingValueExpression
if (binding instanceof ValueExpressionValueBinding)
return ((ValueExpressionValueBinding)binding).getValueExpression();
else if (binding instanceof StateHolder)
{
if (binding instanceof Serializable)
return new SerializableStateHolderValueBindingValueExpression(binding);
else
return new StateHolderValueBindingValueExpression(binding);
}
else if (binding instanceof Serializable)
{
return new SerializableValueBindingValueExpression(binding);
}
else
{
return new ValueBindingValueExpression(binding);
}
}
示例3: doTestStateHolderSaveRestore
import javax.faces.component.StateHolder; //导入依赖的package包/类
@Override
protected void doTestStateHolderSaveRestore(
Converter conv1,
Converter conv2,
MockFacesContext context,
MockUIComponentWrapper wrapper
)
{
Object state = ((StateHolder)conv1).saveState(context);
((StateHolder)conv2).restoreState(context, state);
boolean isEqual = _isConvertersEqual((NumberConverter)conv1,
(NumberConverter)conv2);
assertEquals(true, isEqual);
wrapper.getMock().verify();
}
示例4: subscribeToEvent
import javax.faces.component.StateHolder; //导入依赖的package包/类
@Override
public void subscribeToEvent(Class<? extends SystemEvent> eventClass, ComponentSystemEventListener componentListener)
{
if (eventClass == null)
{
throw new NullPointerException("eventClass required");
}
if (componentListener == null)
{
throw new NullPointerException("componentListener required");
}
FacesBean bean = getFacesBean();
AttachedObjects<Class<? extends SystemEvent>, SystemEventListener> eventStorage =
(AttachedObjects<Class<? extends SystemEvent>, SystemEventListener>)bean.getProperty(_SYSTEM_EVENT_LISTENERS_KEY);
if (eventStorage == null)
{
eventStorage = new AttachedObjects<Class<? extends SystemEvent>, SystemEventListener>();
bean.setProperty(_SYSTEM_EVENT_LISTENERS_KEY, eventStorage);
}
if (componentListener instanceof SystemEventListener && componentListener instanceof StateHolder)
eventStorage.addAttachedObject(eventClass, (SystemEventListener) componentListener);
else
eventStorage.addAttachedObject(eventClass, new ComponentSystemEventListenerWrapper(componentListener, this));
}
示例5: unsubscribeFromEvent
import javax.faces.component.StateHolder; //导入依赖的package包/类
@Override
public void unsubscribeFromEvent(Class<? extends SystemEvent> eventClass,
ComponentSystemEventListener componentListener)
{
if (eventClass == null)
{
throw new NullPointerException("eventClass required");
}
if (componentListener == null)
{
throw new NullPointerException("componentListener required");
}
FacesBean bean = getFacesBean();
AttachedObjects<Class<? extends SystemEvent>, SystemEventListener> eventStorage =
(AttachedObjects<Class<? extends SystemEvent>, SystemEventListener>)bean.getProperty(_SYSTEM_EVENT_LISTENERS_KEY);
if (eventStorage == null)
{
return;
}
if (componentListener instanceof SystemEventListener && componentListener instanceof StateHolder)
{
eventStorage.removeAttachedObject(eventClass, (SystemEventListener) componentListener);
}
else
{
// ComponentSystemEventListenerWrapper implements equals() to compare listener and component
eventStorage.removeAttachedObject(eventClass, new ComponentSystemEventListenerWrapper(componentListener, this));
}
}
示例6: isTransient
import javax.faces.component.StateHolder; //导入依赖的package包/类
@Override
public boolean isTransient()
{
if (_delegate instanceof StateHolder)
{
return ((StateHolder)_delegate).isTransient();
}
return false;
}
示例7: setTransient
import javax.faces.component.StateHolder; //导入依赖的package包/类
@Override
public void setTransient(boolean isTransient)
{
if (_delegate instanceof StateHolder)
{
((StateHolder)_delegate).setTransient(isTransient);
}
}
示例8: saveStateHolder
import javax.faces.component.StateHolder; //导入依赖的package包/类
/**
* Saves an object that may implement StateHolder.
*/
static public Object saveStateHolder(
FacesContext context,
Object value)
{
if (value == null)
return null;
Saver saver = null;
if (value instanceof StateHolder)
{
if (((StateHolder) value).isTransient())
return null;
saver = new SHSaver();
}
else if (value instanceof Serializable)
{
return value;
}
else
{
saver = new Saver();
}
if (saver != null)
saver.saveState(context, value);
return saver;
}
示例9: restoreState
import javax.faces.component.StateHolder; //导入依赖的package包/类
@Override
public Object restoreState(FacesContext context)
{
Object o = super.restoreState(context);
if (o != null)
((StateHolder) o).restoreState(context, _save);
return o;
}
示例10: doTestStateHolderSaveRestore
import javax.faces.component.StateHolder; //导入依赖的package包/类
/**
* Test to check for Validators which implements the StateHolder interface
* @param thisValidator Source validator
* @param otherValidator The validator in which the state will be restored to
* @param context MockFaces context
* @param component MockFaces Component
*/
protected void doTestStateHolderSaveRestore(
Validator thisValidator,
Validator otherValidator,
MockFacesContext context,
MockUIComponentWrapper wrapper)
{
Object state = ((StateHolder)thisValidator).saveState(context);
((StateHolder)otherValidator).restoreState(context, state);
// do all actions of save and restore
doTestEquals(thisValidator, otherValidator, true);
wrapper.getMock().verify();
}
示例11: doTestStateHolderSaveRestore
import javax.faces.component.StateHolder; //导入依赖的package包/类
/**
* Test to check for Validators which implements the StateHolder interface
* @param thisValidator Source converter
* @param otherValidator The converter in which the state will be restored to
* @param context MockFaces context
* @param component MockFaces Component
*/
protected void doTestStateHolderSaveRestore(
Converter thisConverter,
Converter otherConverter,
MockFacesContext context,
MockUIComponentWrapper wrapper
)
{
Object state = ((StateHolder)thisConverter).saveState(context);
((StateHolder)otherConverter).restoreState(context, state);
// do all actions of save and restore
doTestEquals(thisConverter, otherConverter, true);
wrapper.getMock().verify();
}
示例12: getDescription
import javax.faces.component.StateHolder; //导入依赖的package包/类
@Override
public String getDescription() {
// test added because XspDateTimePicker was incorrectly generated
// with get/isTransient methods
return "no 'transient' property on generated components as it is used by "
+ XspTestUtil.getShortClass(StateHolder.class);
}
示例13: restoreState
import javax.faces.component.StateHolder; //导入依赖的package包/类
@Override
public void restoreState(FacesContext context, Object state)
{
Object[] wrappedState = (Object[]) state;
if (this.wrapped == null) //fallback for full state-saving
{
Class wrappedClass = ClassUtils.tryToLoadClassForName((String)wrappedState[0]);
T resolvedInstance = resolveInstanceForClass(context, wrappedClass);
//TODO re-visit logic for multiple (custom) wrappers
if (resolvedInstance instanceof AbstractContextualReferenceWrapper)
{
resolvedInstance = ((AbstractContextualReferenceWrapper<T>)resolvedInstance).getWrapped();
}
this.wrapped = resolvedInstance;
}
if (this.wrapped == null)
{
this.wrapped = (T)ClassUtils.tryToInstantiateClassForName((String)wrappedState[0]);
BeanProvider.injectFields(this.wrapped);
}
if (this.wrapped instanceof StateHolder)
{
((StateHolder) this.wrapped).restoreState(context, wrappedState[1]);
}
}
示例14: setTransient
import javax.faces.component.StateHolder; //导入依赖的package包/类
@Override
public void setTransient(boolean newTransientValue)
{
if (this.wrapped instanceof StateHolder)
{
((StateHolder) this.wrapped).setTransient(newTransientValue);
}
}
示例15: saveState
import javax.faces.component.StateHolder; //导入依赖的package包/类
@Override
public Object saveState(
FacesContext facesContext)
{
Map<K, Object[]> state = new HashMap<K, Object[]>(_objectMap.size());
for (Map.Entry<K, List<T>> e : _objectMap.entrySet())
{
List<T> l = e.getValue();
Object[] entryState = new Object[l.size()];
boolean stateWasSaved = false;
for (int i = 0, size = entryState.length; i < size; ++i)
{
T obj = l.get(i);
if (_initialStateMarked)
{
// JSF 2 state saving, only save the attched object's state if it is a state holder,
// otherwise the re-application of the template will handle the re-creation of the
// object in the correct state
if (obj instanceof StateHolder)
{
entryState[i] = ((StateHolder)obj).saveState(facesContext);
}
}
else
{
// Use JSF <= 1.2 state saving method as the initial state was not marked
entryState[i] = StateUtils.saveStateHolder(facesContext, obj);
}
stateWasSaved = (entryState[i] != null) ? true : stateWasSaved;
}
if (stateWasSaved)
{
state.put(e.getKey(), entryState);
}
}
Object [] savedState = null;
if (!state.isEmpty())
{
// Record whether we used full state saving. This is necessary because methods like addClientBehvior() force
// full state saving under certain circumstances.
// To avoid using partial state restoration with the fully-saved state during restoreView(), we will be using
// the saved flag instead of _initialStateMarked
savedState = new Object[2];
savedState[0] = _initialStateMarked;
savedState[1] = state;
}
return savedState;
}