use of org.apache.wicket.markup.html.form.TextField in project wicket by apache.
the class OnChangeAjaxBehavior method updateAjaxAttributes.
@Override
protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
super.updateAjaxAttributes(attributes);
Component component = getComponent();
// all the other components will use just 'change'
if (!(component instanceof TextField || component instanceof TextArea)) {
attributes.setEventNames(EVENT_CHANGE);
}
}
use of org.apache.wicket.markup.html.form.TextField in project wicket by apache.
the class WicketTesterTest method executeAjaxEvent_ajaxFormSubmitLink.
/**
* Test that the executeAjaxEvent "submits" the form if the event is a AjaxFormSubmitBehavior.
*/
@Test
public void executeAjaxEvent_ajaxFormSubmitLink() {
tester.startPage(MockPageWithFormAndAjaxFormSubmitBehavior.class);
// Get the page
MockPageWithFormAndAjaxFormSubmitBehavior page = (MockPageWithFormAndAjaxFormSubmitBehavior) tester.getLastRenderedPage();
Pojo pojo = page.getPojo();
assertEquals("Mock name", pojo.getName());
TextField<?> name = (TextField<?>) tester.getComponentFromLastRenderedPage("form:name");
assertEquals("Mock name", name.getValue());
assertFalse(page.isExecuted());
tester.getRequest().getPostParameters().setParameterValue(name.getInputName(), "Mock name");
// Execute the ajax event
tester.executeAjaxEvent(MockPageWithFormAndAjaxFormSubmitBehavior.EVENT_COMPONENT, "click");
assertTrue("AjaxFormSubmitBehavior.onSubmit() has not been executed in " + MockPageWithFormAndAjaxFormSubmitBehavior.class, page.isExecuted());
assertEquals("Mock name", ((TextField<?>) tester.getComponentFromLastRenderedPage("form:name")).getValue());
// The name of the pojo should still be the same. If the
// executeAjaxEvent weren't submitting the form the name would have been
// reset to null, because the form would have been updated but there
// wouldn't be any data to update it with.
assertNotNull("executeAjaxEvent() did not properly submit the form", pojo.getName());
assertEquals("Mock name", pojo.getName());
}
use of org.apache.wicket.markup.html.form.TextField in project wicket by apache.
the class AuthorizationTest method testEnabledDisallowedComponent.
/**
* Test that a component will update it's model when authorization is ok.
*
* @throws Exception
*/
@Test
public void testEnabledDisallowedComponent() throws Exception {
tester.getApplication().getSecuritySettings().setAuthorizationStrategy(new IAuthorizationStrategy.AllowAllAuthorizationStrategy() {
/**
* @see org.apache.wicket.authorization.IAuthorizationStrategy#isActionAuthorized(org.apache.wicket.Component,
* org.apache.wicket.authorization.Action)
*/
@Override
public boolean isActionAuthorized(Component c, Action action) {
if (action == Component.ENABLE && c instanceof TextField && c.getId().equals("stringInput")) {
return false;
}
return true;
}
});
tester.startPage(AuthTestPage1.class);
tester.assertRenderedPage(AuthTestPage1.class);
tester.getRequest().getPostParameters().setParameterValue("form:stringInput", "test");
try {
tester.submitForm("form");
Component component = tester.getComponentFromLastRenderedPage("form:stringInput");
assertEquals("", component.getDefaultModelObjectAsString());
} catch (WicketRuntimeException e) {
// good
}
}
use of org.apache.wicket.markup.html.form.TextField in project midpoint by Evolveum.
the class TextFormGroup method initLayout.
private void initLayout(IModel<String> label, final String tooltipKey, String labelCssClass, String textCssClass, final boolean required, final boolean markAsRequired, boolean isSimilarAsPropertyPanel) {
WebMarkupContainer labelContainer = new WebMarkupContainer(ID_LABEL_CONTAINER);
add(labelContainer);
Label l = new Label(ID_LABEL, label);
if (StringUtils.isNotEmpty(labelCssClass)) {
labelContainer.add(AttributeAppender.prepend("class", labelCssClass));
}
if (isSimilarAsPropertyPanel) {
labelContainer.add(AttributeAppender.prepend("class", " col-xs-2 prism-property-label "));
} else {
labelContainer.add(AttributeAppender.prepend("class", " control-label "));
}
labelContainer.add(l);
Label tooltipLabel = new Label(ID_TOOLTIP, new Model<>());
tooltipLabel.add(new AttributeAppender("data-original-title", new IModel<String>() {
@Override
public String getObject() {
return getString(tooltipKey);
}
}));
tooltipLabel.add(new InfoTooltipBehavior());
tooltipLabel.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return tooltipKey != null;
}
});
tooltipLabel.setOutputMarkupId(true);
tooltipLabel.setOutputMarkupPlaceholderTag(true);
labelContainer.add(tooltipLabel);
WebMarkupContainer requiredContainer = new WebMarkupContainer(ID_REQUIRED);
requiredContainer.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
return markAsRequired;
}
});
labelContainer.add(requiredContainer);
WebMarkupContainer propertyLabel = new WebMarkupContainer(ID_PROPERTY_LABEL);
WebMarkupContainer rowLabel = new WebMarkupContainer(ID_ROW);
WebMarkupContainer textWrapper = new WebMarkupContainer(ID_TEXT_WRAPPER);
if (StringUtils.isNotEmpty(textCssClass)) {
textWrapper.add(AttributeAppender.prepend("class", textCssClass));
}
if (isSimilarAsPropertyPanel) {
propertyLabel.add(AttributeAppender.prepend("class", " col-md-10 prism-property-value "));
rowLabel.add(AttributeAppender.prepend("class", " row "));
}
propertyLabel.add(rowLabel);
rowLabel.add(textWrapper);
add(propertyLabel);
TextField text = createText(getModel(), label, required);
text.setLabel(label);
textWrapper.add(text);
FeedbackPanel feedback = new FeedbackPanel(ID_FEEDBACK, new ContainerFeedbackMessageFilter(this));
feedback.setOutputMarkupId(true);
textWrapper.add(feedback);
}
use of org.apache.wicket.markup.html.form.TextField in project midpoint by Evolveum.
the class MultiValueChoosePanel method initLayout.
private void initLayout(final IModel<List<T>> chosenValues, final List<PrismReferenceValue> filterValues, final boolean required, final boolean multiselect) {
AjaxLink<String> addButton = new AjaxLink<String>(ID_ADD_BUTTON) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
editValuePerformed(chosenValues.getObject(), filterValues, target, multiselect);
}
};
addButton.setOutputMarkupPlaceholderTag(true);
add(addButton);
ListView<T> selectedRowsList = new ListView<T>(ID_SELECTED_ROWS, chosenValues) {
@Override
protected void populateItem(ListItem<T> item) {
WebMarkupContainer textWrapper = new WebMarkupContainer(ID_TEXT_WRAPPER);
textWrapper.setOutputMarkupPlaceholderTag(true);
// was value
TextField<String> text = new TextField<>(ID_TEXT, createTextModel(item.getModel()));
text.add(new AjaxFormComponentUpdatingBehavior("blur") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
}
});
text.setRequired(required);
text.setEnabled(false);
text.setOutputMarkupPlaceholderTag(true);
textWrapper.add(text);
FeedbackPanel feedback = new FeedbackPanel(ID_FEEDBACK, new ComponentFeedbackMessageFilter(text));
feedback.setOutputMarkupPlaceholderTag(true);
textWrapper.add(feedback);
initButtons(item, item);
item.add(textWrapper);
}
};
selectedRowsList.setReuseItems(true);
add(selectedRowsList);
}
Aggregations