@Test public void submitted_option_matches_against_value_encoded_option_model_value() throws ValidationException { ValueEncoder<Integer> encoder = getService(ValueEncoderSource.class).getValueEncoder(Integer.class); ValidationTracker tracker = mockValidationTracker(); Request request = mockRequest(); Messages messages = mockMessages(); FieldValidationSupport fvs = mockFieldValidationSupport(); TypeCoercer typeCoercer = mockTypeCoercer(); InternalComponentResources resources = mockInternalComponentResources(); Binding selectModelBinding = mockBinding(); expect(request.getParameter("xyz")).andReturn("5"); expect(messages.contains(EasyMock.anyObject(String.class))).andReturn(false).anyTimes(); expect(resources.getBinding("model")).andReturn(selectModelBinding); final Holder<SelectModel> modelHolder = Holder.create(); expect(typeCoercer.coerce(EasyMock.or(EasyMock.isA(SelectModel.class), EasyMock.isNull()), EasyMock.eq(SelectModel.class) )) .andAnswer(new IAnswer<SelectModel>() { @Override public SelectModel answer() throws Throwable { return modelHolder.get(); } }); expect(selectModelBinding.get()).andAnswer(new IAnswer<SelectModel>() { @Override public SelectModel answer() throws Throwable { return modelHolder.get(); } }); Select select = new Select(); tracker.recordInput(select, "5"); fvs.validate(5, resources, null); replay(); modelHolder.put(getService(TypeCoercer.class).coerce("1,5,10,20", SelectModel.class)); set(select, "encoder", encoder); set(select, "model", modelHolder.get()); set(select, "request", request); set(select, "secure", SecureOption.ALWAYS); set(select, "beanValidationDisabled", true); set(select, "tracker", tracker); set(select, "fieldValidationSupport", fvs); set(select, "typeCoercer", typeCoercer); set(select, "resources", resources); select.processSubmission("xyz"); verify(); assertEquals(get(select, "value"), 5); }
@SuppressWarnings( {"unchecked"}) @Override protected void processSubmission(String controlName) { String submittedValue = request.getParameter(controlName); tracker.recordInput(this, submittedValue); Object selectedValue; try { selectedValue = toValue(submittedValue); } catch (ValidationException ex) { tracker.recordError(this, ex.getMessage()); return; } putPropertyNameIntoBeanValidationContext("value"); try { fieldValidationSupport.validate(selectedValue, resources, validate); value = selectedValue; } catch (ValidationException ex) { tracker.recordError(this, ex.getMessage()); } removePropertyNameFromBeanValidationContext(); }
Select extends AbstractField { @SuppressWarnings( {"unchecked"}) @Override protected void processSubmission(String controlName) { String submittedValue = request.getParameter(controlName); tracker.recordInput(this, submittedValue); Object selectedValue; try { selectedValue = toValue(submittedValue); } catch (ValidationException ex) { tracker.recordError(this, ex.getMessage()); return; } putPropertyNameIntoBeanValidationContext("value"); try { fieldValidationSupport.validate(selectedValue, resources, validate); value = selectedValue; } catch (ValidationException ex) { tracker.recordError(this, ex.getMessage()); } removePropertyNameFromBeanValidationContext(); } }
Select extends AbstractField { @SuppressWarnings( {"unchecked"}) @Override protected void processSubmission(String controlName) { String submittedValue = request.getParameter(controlName); tracker.recordInput(this, submittedValue); Object selectedValue; try { selectedValue = toValue(submittedValue); } catch (ValidationException ex) { tracker.recordError(this, ex.getMessage()); return; } putPropertyNameIntoBeanValidationContext("value"); try { fieldValidationSupport.validate(selectedValue, resources, validate); value = selectedValue; } catch (ValidationException ex) { tracker.recordError(this, ex.getMessage()); } removePropertyNameFromBeanValidationContext(); }  }
Select extends AbstractField { @SuppressWarnings( {"unchecked"}) @Override protected void processSubmission(String controlName) { String submittedValue = request.getParameter(controlName); tracker.recordInput(this, submittedValue); Object selectedValue; try { selectedValue = toValue(submittedValue); } catch (ValidationException ex) { tracker.recordError(this, ex.getMessage()); return; } putPropertyNameIntoBeanValidationContext("value"); try { fieldValidationSupport.validate(selectedValue, resources, validate); value = selectedValue; } catch (ValidationException ex) { tracker.recordError(this, ex.getMessage()); } removePropertyNameFromBeanValidationContext(); }  @Override boolean isRequired(); }
Select extends AbstractField { @SuppressWarnings( {"unchecked"}) @Override protected void processSubmission(String controlName) { String submittedValue = request.getParameter(controlName); tracker.recordInput(this, submittedValue); Object selectedValue; try { selectedValue = toValue(submittedValue); } catch (ValidationException ex) { tracker.recordError(this, ex.getMessage()); return; } putPropertyNameIntoBeanValidationContext("value"); try { fieldValidationSupport.validate(selectedValue, resources, validate); value = selectedValue; } catch (ValidationException ex) { tracker.recordError(this, ex.getMessage()); } removePropertyNameFromBeanValidationContext(); }  @Override boolean isRequired(); static final String CHANGE_EVENT; }