List of usage examples for org.apache.wicket.markup.html.form Form warn
@Override public final void warn(final Serializable message)
From source file:com.tysanclan.site.projectewok.pages.member.CreateGroupPage.java
License:Open Source License
/** *//*from w w w .j a v a 2 s. c o m*/ private Form<Group> createGamingGroupForm() { Form<Group> gamingGroupForm = new Form<Group>("creategaminggroupform") { private static final long serialVersionUID = 1L; @SpringBean private GroupService groupService; /** * @see org.apache.wicket.markup.html.form.Form#onSubmit() */ @SuppressWarnings("unchecked") @Override protected void onSubmit() { TextField<String> nameField = (TextField<String>) get("name"); TextArea<String> descriptionArea = (TextArea<String>) get("publicdescription"); TextArea<String> motivationArea = (TextArea<String>) get("motivation"); DropDownChoice<GameRealm> gameGroup = (DropDownChoice<GameRealm>) get("gamerealm"); String name = nameField.getModelObject(); String description = descriptionArea.getModelObject(); String motivation = motivationArea.getModelObject(); GameRealm gameRealm = gameGroup.getModelObject(); Game game = gameRealm.getGame(); Realm realm = gameRealm.getRealm(); if (name.isEmpty()) { error("Name must not be empty"); } else if (description.isEmpty()) { error("Description must not be empty"); } else if (motivation.isEmpty()) { error("Motivation must not be empty"); } else { groupService.createGamingGroupRequest(getUser(), game, realm, name, description, motivation); setResponsePage(new CreateGroupPage()); } } }; List<Game> games = gameService.getActiveGames(); List<GameRealm> grlms = new LinkedList<GameRealm>(); if (games.isEmpty()) { gamingGroupForm.setEnabled(false); gamingGroupForm.warn("No games available! Cannot create gaming group!"); } for (Game game : games) { for (Realm realm : game.getRealms()) { grlms.add(new GameRealm(game, realm)); } } if (grlms.isEmpty()) { gamingGroupForm.setEnabled(false); gamingGroupForm.warn("No realms available! Cannot create gaming group!"); } gamingGroupForm.add(new DropDownChoice<GameRealm>("gamerealm", new Model<GameRealm>(null), grlms, new GameRealmRenderer()).setRequired(true)); gamingGroupForm.add(new TextField<String>("name", new Model<String>("")).setRequired(true)); gamingGroupForm.add(new BBCodeTextArea("publicdescription", "").setRequired(true)); gamingGroupForm.add(new BBCodeTextArea("motivation", "").setRequired(true)); return gamingGroupForm; }
From source file:org.geoserver.wms.web.data.ExternalGraphicPanel.java
License:Open Source License
/** * @param id/*from w ww. ja va 2 s .c o m*/ * @param model Must return a {@link ResourceInfo} */ public ExternalGraphicPanel(String id, final CompoundPropertyModel<StyleInfo> styleModel, final Form styleForm) { super(id, styleModel); // container for ajax updates final WebMarkupContainer container = new WebMarkupContainer("container"); container.setOutputMarkupId(true); add(container); table = new WebMarkupContainer("list"); table.setOutputMarkupId(true); IModel<String> bind = styleModel.bind("legend.onlineResource"); onlineResource = new TextField<String>("onlineResource", bind); onlineResource.add(new StringValidator() { final List<String> EXTENSIONS = Arrays.asList(new String[] { "png", "gif", "jpeg", "jpg" }); protected void onValidate(IValidatable<String> input) { String value = input.getValue(); int last = value == null ? -1 : value.lastIndexOf('.'); if (last == -1 || !EXTENSIONS.contains(value.substring(last + 1).toLowerCase())) { ValidationError error = new ValidationError(); error.setMessage("Not an image"); error.addMessageKey("nonImage"); input.error(error); return; } URI uri = null; try { uri = new URI(value); } catch (URISyntaxException e1) { // Unable to check if absolute } if (uri != null && uri.isAbsolute()) { try { String baseUrl = baseURL(onlineResource.getForm()); if (!value.startsWith(baseUrl)) { onlineResource.warn("Recommend use of styles directory at " + baseUrl); } URL url = uri.toURL(); URLConnection conn = url.openConnection(); if ("text/html".equals(conn.getContentType())) { ValidationError error = new ValidationError(); error.setMessage("Unable to access image"); error.addMessageKey("imageUnavailable"); input.error(error); return; // error message back! } } catch (MalformedURLException e) { ValidationError error = new ValidationError(); error.setMessage("Unable to access image"); error.addMessageKey("imageUnavailable"); input.error(error); } catch (IOException e) { ValidationError error = new ValidationError(); error.setMessage("Unable to access image"); error.addMessageKey("imageUnavailable"); input.error(error); } return; // no further checks possible } else { GeoServerResourceLoader resources = GeoServerApplication.get().getResourceLoader(); try { File styles = resources.find("styles"); String[] path = value.split(File.separator); File test = resources.find(styles, path); if (test == null) { ValidationError error = new ValidationError(); error.setMessage("File not found in styles directory"); error.addMessageKey("imageNotFound"); input.error(error); } } catch (IOException e) { ValidationError error = new ValidationError(); error.setMessage("File not found in styles directory"); error.addMessageKey("imageNotFound"); input.error(error); } } } }); onlineResource.setOutputMarkupId(true); table.add(onlineResource); // add the autofill button autoFill = new GeoServerAjaxFormLink("autoFill", styleForm) { @Override public void onClick(AjaxRequestTarget target, Form form) { onlineResource.processInput(); if (onlineResource.getModelObject() != null) { URL url = null; try { String baseUrl = baseURL(form); String external = onlineResource.getModelObject().toString(); URI uri = new URI(external); if (uri.isAbsolute()) { url = uri.toURL(); if (!external.startsWith(baseUrl)) { form.warn("Recommend use of styles directory at " + baseUrl); } } else { url = new URL(baseUrl + "styles/" + external); } URLConnection conn = url.openConnection(); if ("text/html".equals(conn.getContentType())) { form.error("Unable to access url"); return; // error message back! } format.setModelValue(conn.getContentType()); BufferedImage image = ImageIO.read(conn.getInputStream()); width.setModelValue("" + image.getWidth()); height.setModelValue("" + image.getHeight()); } catch (FileNotFoundException notFound) { form.error("Unable to access " + url); } catch (Exception e) { e.printStackTrace(); form.error("Recommend use of styles directory at " + e); } } target.addComponent(format); target.addComponent(width); target.addComponent(height); } }; table.add(autoFill); format = new TextField("format", styleModel.bind("legend.format")); format.setOutputMarkupId(true); table.add(format); width = new TextField("width", styleModel.bind("legend.width"), Integer.class); width.add(NumberValidator.minimum(0)); width.setOutputMarkupId(true); table.add(width); height = new TextField("height", styleModel.bind("legend.height"), Integer.class); height.add(NumberValidator.minimum(0)); height.setOutputMarkupId(true); table.add(height); table.add(new AttributeModifier("style", true, showhideStyleModel)); container.add(table); showhideForm = new Form("showhide") { @Override protected void onSubmit() { super.onSubmit(); } }; showhideForm.setMarkupId("showhideForm"); container.add(showhideForm); show = new AjaxButton("show") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { updateVisibility(true); target.addComponent(ExternalGraphicPanel.this); } }; container.add(show); showhideForm.add(show); hide = new AjaxButton("hide") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { onlineResource.setModelObject(""); format.setModelObject(""); width.setModelObject("0"); height.setModelObject("0"); updateVisibility(false); target.addComponent(ExternalGraphicPanel.this); } }; container.add(hide); showhideForm.add(hide); String url = styleModel.getObject().getLegend().getOnlineResource(); boolean visible = url != null && !url.isEmpty(); updateVisibility(visible); }
From source file:org.xaloon.wicket.component.jquery.tab.JQueryTabForm.java
License:Apache License
public JQueryTabForm(String id, final IModel<T> model, Panel parent) { super(id, model); JQueryBehavior queryBehavior = new JQueryBehavior(); add(queryBehavior);/*from w w w .j a va 2s. c o m*/ final JQueryTabPanel queryTabPanel = new JQueryTabPanel("tbPanel"); queryTabPanel.setOutputMarkupId(true); queryTabPanel.init(getTabList(), queryBehavior); queryTabPanel.setSelectedTab(0); queryTabPanel.addOnShowFunction(0); add(queryTabPanel); final ComponentFeedbackPanel feedback = new ComponentFeedbackPanel("fp", this); feedback.setOutputMarkupId(true); parent.add(feedback); class JqueryAjaxButton extends AjaxButton { /** * */ private static final long serialVersionUID = 1L; public JqueryAjaxButton(String id) { super(id); } @Override protected void onError(AjaxRequestTarget target, Form<?> form) { int index = 0, firstFailure = -1; for (XTab tab : getTabList()) { if (!tab.isValidTab()) { if (firstFailure == -1) { firstFailure = index; } form.error("Tab '" + tab.getTitle().getObject() + "' has errors."); } else if (!tab.isVisibleTab() && tab.hasRequiredFields()) { form.warn("Tab '" + tab.getTitle().getObject() + "' may be not initialized."); } index++; tab.processNestedTabs(target); } target.addComponent(form); target.appendJavascript(queryTabPanel.getReloadTabsFunction(firstFailure)); target.addComponent(feedback); } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { target.addComponent(form); target.addComponent(feedback); target.appendJavascript(queryTabPanel.getReloadTabsFunction(0)); onFormSubmit(model, form); for (XTab tab : getTabList()) { tab.processNestedTabs(target); } } } add(new JqueryAjaxButton("check")); }