@Test public void context_that_needs_to_be_encoded() throws Exception { ValueEncoderSource valueEncoderSource = mockValueEncoderSource(); TypeCoercer typeCoercer = getService(TypeCoercer.class); ContextValueEncoder contextValueEncoder = new ContextValueEncoderImpl(valueEncoderSource); ValueEncoder<Platform> platformEncoder = new ValueEncoder<SelectTest.Platform>() { @Override public Platform toValue(String clientValue) { return Platform.valueOf(clientValue.substring(10)); } @Override public String toClient(Platform value) { return "Platform: "+value.name(); } }; InternalComponentResources resources = mockInternalComponentResources(); expect(valueEncoderSource.getValueEncoder(Platform.class)).andReturn(platformEncoder).anyTimes(); expect(valueEncoderSource.getValueEncoder(String.class)).andReturn(new StringValueEncoder()).anyTimes(); expect(resources.triggerContextEvent(EasyMock.eq(EventConstants.VALUE_CHANGED), eqEventContext(null, Platform.LINUX), EasyMock.isA(ComponentEventCallback.class))).andReturn(true); Select select = new Select(); set(select, "resources", resources); set(select, "encoder", new StringValueEncoder()); set(select, "typeCoercer", typeCoercer); replay(); select.onChange(new URLEventContext(contextValueEncoder, new String[]{platformEncoder.toClient(Platform.LINUX)}), null); verify(); }
Object onChange(final EventContext context, @RequestParameter(value = "t:selectvalue", allowBlank = true) final String selectValue) throws ValidationException { final Object newValue = toValue(selectValue); CaptureResultCallback<Object> callback = new CaptureResultCallback<Object>(); EventContext newContext = new AbstractEventContext() { @Override public int getCount() { return context.getCount() + 1; } @Override public <T> T get(Class<T> desiredType, int index) { if (index == 0) { return typeCoercer.coerce(newValue, desiredType); } return context.get(desiredType, index-1); } }; this.resources.triggerContextEvent(EventConstants.VALUE_CHANGED, newContext, callback); this.value = newValue; return callback.getResult(); }
Select extends AbstractField { Object onChange(final EventContext context, @RequestParameter(value = "t:selectvalue", allowBlank = true) final String selectValue) throws ValidationException { final Object newValue = toValue(selectValue); CaptureResultCallback<Object> callback = new CaptureResultCallback<Object>(); EventContext newContext = new AbstractEventContext() { @Override public int getCount() { return context.getCount() + 1; } @Override public <T> T get(Class<T> desiredType, int index) { if (index == 0) { return typeCoercer.coerce(newValue, desiredType); } return context.get(desiredType, index-1); } }; this.resources.triggerContextEvent(EventConstants.VALUE_CHANGED, newContext, callback); this.value = newValue; return callback.getResult(); } }
Select extends AbstractField { Object onChange(final EventContext context, @RequestParameter(value = "t:selectvalue", allowBlank = true) final String selectValue) throws ValidationException { final Object newValue = toValue(selectValue); CaptureResultCallback<Object> callback = new CaptureResultCallback<Object>(); EventContext newContext = new AbstractEventContext() { @Override public int getCount() { return context.getCount() + 1; } @Override public <T> T get(Class<T> desiredType, int index) { if (index == 0) { return typeCoercer.coerce(newValue, desiredType); } return context.get(desiredType, index-1); } }; this.resources.triggerContextEvent(EventConstants.VALUE_CHANGED, newContext, callback); this.value = newValue; return callback.getResult(); }  }
Select extends AbstractField { Object onChange(final EventContext context, @RequestParameter(value = "t:selectvalue", allowBlank = true) final String selectValue) throws ValidationException { final Object newValue = toValue(selectValue); CaptureResultCallback<Object> callback = new CaptureResultCallback<Object>(); EventContext newContext = new AbstractEventContext() { @Override public int getCount() { return context.getCount() + 1; } @Override public <T> T get(Class<T> desiredType, int index) { if (index == 0) { return typeCoercer.coerce(newValue, desiredType); } return context.get(desiredType, index-1); } }; this.resources.triggerContextEvent(EventConstants.VALUE_CHANGED, newContext, callback); this.value = newValue; return callback.getResult(); }  @Override boolean isRequired(); }
Select extends AbstractField { Object onChange(final EventContext context, @RequestParameter(value = "t:selectvalue", allowBlank = true) final String selectValue) throws ValidationException { final Object newValue = toValue(selectValue); CaptureResultCallback<Object> callback = new CaptureResultCallback<Object>(); EventContext newContext = new AbstractEventContext() { @Override public int getCount() { return context.getCount() + 1; } @Override public <T> T get(Class<T> desiredType, int index) { if (index == 0) { return typeCoercer.coerce(newValue, desiredType); } return context.get(desiredType, index-1); } }; this.resources.triggerContextEvent(EventConstants.VALUE_CHANGED, newContext, callback); this.value = newValue; return callback.getResult(); }  @Override boolean isRequired(); static final String CHANGE_EVENT; }