use of org.apache.wicket.markup.html.form.FormComponent in project wicket by apache.
the class AjaxFormComponentUpdatingBehavior method onBind.
/**
* @see org.apache.wicket.behavior.AbstractAjaxBehavior#onBind()
*/
@Override
protected void onBind() {
super.onBind();
Component component = getComponent();
if (!(component instanceof FormComponent)) {
throw new WicketRuntimeException("Behavior " + getClass().getName() + " can only be added to an instance of a FormComponent");
}
checkComponent((FormComponent<?>) component);
}
use of org.apache.wicket.markup.html.form.FormComponent in project wicket by apache.
the class BaseWicketTester method serializeFormToRequest.
/**
* Puts all not already scheduled (e.g. via {@link FormTester#setValue(String, String)}) form
* component values in the post parameters for the next form submit
*
* @param form
* the {@link Form} which components should be submitted
*/
private void serializeFormToRequest(final Form<?> form) {
final MockRequestParameters postParameters = request.getPostParameters();
final Set<String> currentParameterNamesSet = postParameters.getParameterNames();
form.visitFormComponents(new IVisitor<FormComponent<?>, Void>() {
@Override
public void component(final FormComponent<?> formComponent, final IVisit<Void> visit) {
final String inputName = formComponent.getInputName();
if (!currentParameterNamesSet.contains(inputName)) {
String[] values = FormTester.getInputValue(formComponent);
for (String value : values) {
postParameters.addParameterValue(inputName, value);
}
}
}
});
}
use of org.apache.wicket.markup.html.form.FormComponent in project wicket by apache.
the class FormTester method setValue.
/**
* Simulates filling in a field on a <code>Form</code>.
*
* @param formComponentId
* relative path (from <code>Form</code>) to the selectable
* <code>FormComponent</code> or <code>IFormSubmittingComponent</code>
* @param value
* the field value
* @return This
*/
public FormTester setValue(final String formComponentId, final String value) {
Component component = workingForm.get(formComponentId);
Assert.assertNotNull("Unable to set value. Couldn't find component with name: " + formComponentId, component);
return setValue(component, value);
}
use of org.apache.wicket.markup.html.form.FormComponent in project wicket by apache.
the class AjaxEditableTest method testUpdateValue.
/**
* A test that changes the value of the {@link AjaxEditableLabel}
*/
@SuppressWarnings({ "unchecked" })
@Test
public void testUpdateValue() {
Page page = tester.getLastRenderedPage();
AjaxEditableLabel<String> ajaxLabel = (AjaxEditableLabel<String>) page.get("ajaxLabel");
tester.assertInvisible("ajaxLabel:editor");
tester.assertVisible("ajaxLabel:label");
// assert the initial value
tester.assertLabel("ajaxLabel:label", "ajaxTest");
// click on the label to go to edit mode
tester.executeAjaxEvent("ajaxLabel:label", "click");
tester.assertVisible("ajaxLabel:editor");
tester.assertInvisible("ajaxLabel:label");
FormComponent<?> editor = (FormComponent<?>) ajaxLabel.get("editor");
// set some new value and submit it
tester.getRequest().setParameter(editor.getInputName(), "something");
tester.getRequest().setParameter("save", "true");
tester.executeBehavior((AbstractAjaxBehavior) editor.getBehaviorById(0));
tester.assertInvisible("ajaxLabel:editor");
tester.assertVisible("ajaxLabel:label");
tester.assertLabel("ajaxLabel:label", "something");
}
use of org.apache.wicket.markup.html.form.FormComponent in project wicket by apache.
the class FormGroup method onConfigure.
@Override
protected void onConfigure() {
super.onConfigure();
// set all components visible
help.setVisible(true);
label.setVisible(true);
feedback.setVisible(true);
// clear feedback message and current state
stateClassName = "";
feedback.setDefaultModelObject("");
final List<FormComponent<?>> formComponents = findFormComponents();
for (final FormComponent<?> fc : formComponents) {
final FeedbackMessages messages = fc.getFeedbackMessages();
if (!messages.isEmpty()) {
final FeedbackMessage worstMessage = getWorstMessage(messages);
worstMessage.markRendered();
feedback.setDefaultModelObject(worstMessage.getMessage());
// render worst message of first found child component with feedback message
break;
}
}
}
Aggregations