List of usage examples for org.apache.wicket Component getDefaultModel
public final IModel<?> getDefaultModel()
From source file:com.comcast.cdn.traffic_control.traffic_monitor.wicket.behaviors.MultiUpdatingTimerBehavior.java
License:Apache License
protected void onPostProcessTarget(final AjaxRequestTarget target) { final JSONObject jo = new JSONObject(); // final StringBuilder sb = new StringBuilder(); // sb.append("["); for (Component c : components) { // sb.append("\"").append(c.getMarkupId()).append("\","); final JSONObject jo2 = new JSONObject(); try {/*from w w w. jav a 2 s.co m*/ boolean hasB = false; final List<UpdatingAttributeAppender> blist = c.getBehaviors(UpdatingAttributeAppender.class); for (UpdatingAttributeAppender b : blist) { jo2.put(b.getAttribute(), b.getAttributeValue(c)); hasB = true; } if (!hasB) { jo2.put("v", String.valueOf(c.getDefaultModel().getObject())); } jo.put(c.getMarkupId(), jo2); } catch (JSONException e) { LOGGER.warn(e, e); } } target.appendJavaScript("updateAjaxComponents(" + jo.toString() + ");"); }
From source file:com.evolveum.midpoint.web.component.util.FutureUpdateBehavior.java
License:Apache License
@Override protected void onTimer(final AjaxRequestTarget target) { if (future == null || !future.isDone()) { return;/*from w w w. j a v a 2 s . com*/ } try { T data = future.get(); Component component = getComponent(); if (component instanceof BaseSimplePanel) { BaseSimplePanel<T> panel = (BaseSimplePanel<T>) component; panel.getModel().setObject(data); } else { if (component.getDefaultModel() == null) { component.setDefaultModel(new Model()); } component.setDefaultModelObject(data); } stop(target); onPostSuccess(target); } catch (InterruptedException ex) { handleError(ex, target); } catch (ExecutionException ex) { handleError(ex, target); } }
From source file:com.evolveum.midpoint.web.util.SchrodingerComponentInitListener.java
License:Apache License
private void handleLocalization(Component component) { if (component instanceof PrismPropertyPanel) { PrismPropertyPanel ppp = (PrismPropertyPanel) component; ItemWrapper iw = (ItemWrapper) ppp.getModel().getObject(); String key = iw.getDisplayName(); QName qname = iw.getName(); writeDataAttribute(component, ATTR_RESOURCE_KEY, key); writeDataAttribute(component, ATTR_QNAME, qnameToString(qname)); return;/* ww w . j ava 2s. co m*/ } if (component instanceof PrismHeaderPanel) { PrismHeaderPanel php = (PrismHeaderPanel) component; String key = php.getLabel(); writeDataAttribute(component, ATTR_RESOURCE_KEY, key); return; } StringResourceModel model = null; if (component.getDefaultModel() instanceof StringResourceModel) { model = (StringResourceModel) component.getDefaultModel(); } else if (component.getInnermostModel() instanceof StringResourceModel) { model = (StringResourceModel) component.getInnermostModel(); } if (model == null) { return; } try { String key = (String) FieldUtils.readField(model, "resourceKey", true); if (key != null) { writeDataAttribute(component, ATTR_RESOURCE_KEY, key); } } catch (Exception ex) { // we don't care, should be all right, unless selenium tests starts failing } }
From source file:com.fortuityframework.wicket.WicketFortuityTest.java
License:Apache License
/** * Test Wicket component event responses *///from w w w. j a v a2 s .com @SuppressWarnings("unchecked") @Test public void testEvents() { tester.startPage(FortuityTestIndexPage.class); tester.clickLink("next"); tester.assertRenderedPage(StatefulComponentPage.class); Component component = tester.getComponentFromLastRenderedPage("counter"); IModel<Integer> cModel = (IModel<Integer>) component.getDefaultModel(); assertEquals(1, cModel.getObject().intValue()); tester.clickLink("up", true); cModel = (IModel<Integer>) component.getDefaultModel(); assertEquals(2, cModel.getObject().intValue()); EventReceivingPanel receiver = (EventReceivingPanel) tester.getComponentFromLastRenderedPage("receiver"); assertEquals(2, receiver.getValue()); }
From source file:com.googlecode.wicketwebbeans.containers.BeanForm.java
License:Apache License
/** * Refresh the targetComponent, in addition to any components that need to be updated * due to property change events./*from w ww . j a v a2s.c om*/ * * @param target * @param targetComponent the targetComponent, may be null. */ public void refreshComponents(final AjaxRequestTarget target, Component targetComponent) { if (targetComponent != null) { refreshComponent(target, targetComponent); } if (!refreshComponents.isEmpty()) { // Refresh components fired from our PropertyChangeListener. // Visit all children and see if they match the fired events. form.visitChildren(new IVisitor<Component>() { public Object component(Component component) { Object model = component.getDefaultModel(); if (model instanceof BeanPropertyModel) { BeanPropertyModel propModel = (BeanPropertyModel) model; ElementMetaData componentMetaData = propModel.getElementMetaData(); for (ComponentPropertyMapping mapping : refreshComponents) { if (mapping.elementMetaData == componentMetaData) { refreshComponent(target, component); break; } } } return IVisitor.CONTINUE_TRAVERSAL; } }); refreshComponents.clear(); } }
From source file:com.googlecode.wicketwebbeans.containers.ContainerModelTest.java
License:Apache License
/** * Tests BeanForm with a LoadableDetachableModel instead of a direct bean. *///from w w w . ja v a 2 s . c o m public void testBeanFormWithLoadableDetachableModel() { WicketTester tester = new WicketTester(); final ContainerModelTestPage page = new ContainerModelTestPage(); TestLoadableDetachableObjectModel nestedModel = new TestLoadableDetachableObjectModel(); BeanMetaData meta = new BeanMetaData(nestedModel.getObject().getClass(), null, page, null, false); BeanForm form = new BeanForm("beanForm", nestedModel, meta); page.add(form); tester.startPage(new ITestPageSource() { private static final long serialVersionUID = 1L; public Page getTestPage() { return page; } }); //tester.debugComponentTrees(); // Check elements, labels. String firstRowPath = "beanForm:f:tabs:r:0"; String namePath = firstRowPath + ":c:0:c"; String nameFieldPath = namePath + ":c"; tester.assertLabel(namePath + ":l", "Name"); tester.assertComponent(nameFieldPath, InputField.class); Component nameField = tester.getComponentFromLastRenderedPage(nameFieldPath); String serialNumPath = firstRowPath + ":c:1:c"; String serialNumFieldPath = serialNumPath + ":c"; tester.assertLabel(serialNumPath + ":l", "Serial Number"); tester.assertComponent(serialNumFieldPath, InputField.class); Component serialNumField = tester.getComponentFromLastRenderedPage(serialNumFieldPath); // Check attaching/detaching component's model (BeanPropertyModel). BeanPropertyModel nameFieldModel = (BeanPropertyModel) nameField.getDefaultModel(); assertFalse(nestedModel.isAttached()); // Should attach the nested model's object. nameFieldModel.getObject(); assertTrue(nestedModel.isAttached()); NonSerializableBean firstBean = (NonSerializableBean) nestedModel.getObject(); // Make the first bean detach. This also tests that the model is attached somewhere below the page. //page.detachModels(); // TODO 1.3 doesn't work detachModels(page); assertFalse(nestedModel.isAttached()); NonSerializableBean secondBean = (NonSerializableBean) nestedModel.getObject(); // Should be different and attached now. assertNotSame(firstBean, secondBean); assertTrue(nestedModel.isAttached()); // Assert PropertyChangeListener on BeanForm is called. assertFalse(form.isComponentRefreshNeeded()); nameFieldModel.setObject("test"); assertTrue(form.isComponentRefreshNeeded()); // Clear the refresh components. form.clearRefreshComponents(); // Assert PropertyChangeListener on BeanForm is called after detach()/attach(). //page.detachModels(); // TODO 1.3 doesn't work detachModels(page); assertFalse(nestedModel.isAttached()); assertFalse(form.isComponentRefreshNeeded()); nameFieldModel.setObject("test"); assertTrue(form.isComponentRefreshNeeded()); // Clear the refresh components. form.clearRefreshComponents(); }
From source file:com.googlecode.wicketwebbeans.containers.ContainerModelTest.java
License:Apache License
/** * Checks a page that uses a List.//from w w w .j a v a 2 s. com * * @param tester * @param page * @param beans */ private void checkListPage(WicketTester tester, final ContainerModelTestPage page, SerializableBean[] beans) { // Check that we have a data grid view and repeating fields. String tablePath = "beanForm:f:tabs:t:body:rows"; tester.assertComponent(tablePath, DataGridView.class); for (int i = 1; i <= 10; i++) { String rowPath = tablePath + ":" + i; tester.assertComponent(rowPath, OddEvenItem.class); String firstCellPath = rowPath + ":cells:1:cell"; tester.assertComponent(firstCellPath, InputField.class); Component nameField = tester.getComponentFromLastRenderedPage(firstCellPath); assertEquals(beans[i - 1].getName(), nameField.getDefaultModel().getObject()); String secondCellPath = rowPath + ":cells:2:cell"; tester.assertComponent(secondCellPath, InputField.class); Component serailNumField = tester.getComponentFromLastRenderedPage(secondCellPath); assertEquals(beans[i - 1].getSerialNumber(), serailNumField.getDefaultModel().getObject()); } }
From source file:com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor.java
License:Open Source License
/** * @param component/*from w w w . ja va 2s . co m*/ */ @SuppressWarnings("nls") public static boolean setSelectedIndex(Component component, AjaxRequestTarget target, int modifiers, boolean bHandleMultiselect) { WebForm parentForm = component.findParent(WebForm.class); WebCellBasedView tableView = null; if (parentForm != null) { int parentFormViewType = parentForm.getController().getForm().getView(); if (parentFormViewType == FormController.TABLE_VIEW || parentFormViewType == FormController.LOCKED_TABLE_VIEW || parentFormViewType == IForm.LIST_VIEW || parentFormViewType == FormController.LOCKED_LIST_VIEW) { tableView = component.findParent(WebCellBasedView.class); if (tableView == null) { // the component is not part of the table view (it is on other form part), so ignore selection change return true; } else tableView.setSelectionMadeByCellAction(); if (parentFormViewType == IForm.LIST_VIEW || parentFormViewType == FormController.LOCKED_LIST_VIEW) { if (component instanceof WebCellBasedViewListViewItem) { ((WebCellBasedViewListViewItem) component).markSelected(target); } else { WebCellBasedViewListViewItem listViewItem = component .findParent(WebCellBasedView.WebCellBasedViewListViewItem.class); if (listViewItem != null) { listViewItem.markSelected(target); } } } } } //search for recordItem model Component recordItemModelComponent = component; IModel<?> someModel = recordItemModelComponent.getDefaultModel(); while (!(someModel instanceof RecordItemModel)) { recordItemModelComponent = recordItemModelComponent.getParent(); if (recordItemModelComponent == null) break; someModel = recordItemModelComponent.getDefaultModel(); } if (someModel instanceof RecordItemModel) { if (!(component instanceof WebCellBasedViewListViewItem)) { // update the last rendered value for the events component (if updated) ((RecordItemModel) someModel).updateRenderedValue(component); } IRecordInternal rec = (IRecordInternal) someModel.getObject(); if (rec != null) { int index; IFoundSetInternal fs = rec.getParentFoundSet(); if (someModel instanceof FoundsetRecordItemModel) { index = ((FoundsetRecordItemModel) someModel).getRowIndex(); } else { index = fs.getRecordIndex(rec); // this is used only on "else", because a "plugins.rawSQL.flushAllClientsCache" could result in index = -1 although the record has not changed (but record & underlying row instances changed) } if (fs instanceof FoundSet && ((FoundSet) fs).isMultiSelect()) { //set the selected record ClientProperties clp = ((WebClientInfo) Session.get().getClientInfo()).getProperties(); String navPlatform = clp.getNavigatorPlatform(); int controlMask = (navPlatform != null && navPlatform.toLowerCase().indexOf("mac") != -1) ? Event.META_MASK : Event.CTRL_MASK; boolean toggle = (modifiers != MODIFIERS_UNSPECIFIED) && ((modifiers & controlMask) != 0); boolean extend = (modifiers != MODIFIERS_UNSPECIFIED) && ((modifiers & Event.SHIFT_MASK) != 0); boolean isRightClick = (modifiers != MODIFIERS_UNSPECIFIED) && ((modifiers & Event.ALT_MASK) != 0); if (!isRightClick) { if (!toggle && !extend && tableView != null && tableView.getDragNDropController() != null && Arrays.binarySearch(((FoundSet) fs).getSelectedIndexes(), index) > -1) { return true; } if (toggle || extend) { if (bHandleMultiselect) { if (toggle) { int[] selectedIndexes = ((FoundSet) fs).getSelectedIndexes(); ArrayList<Integer> selectedIndexesA = new ArrayList<Integer>(); Integer selectedIndex = new Integer(index); for (int selected : selectedIndexes) selectedIndexesA.add(new Integer(selected)); if (selectedIndexesA.indexOf(selectedIndex) != -1) { if (selectedIndexesA.size() > 1) selectedIndexesA.remove(selectedIndex); } else selectedIndexesA.add(selectedIndex); selectedIndexes = new int[selectedIndexesA.size()]; for (int i = 0; i < selectedIndexesA.size(); i++) selectedIndexes[i] = selectedIndexesA.get(i).intValue(); ((FoundSet) fs).setSelectedIndexes(selectedIndexes); } else if (extend) { int anchor = ((FoundSet) fs).getSelectedIndex(); int min = Math.min(anchor, index); int max = Math.max(anchor, index); int[] newSelectedIndexes = new int[max - min + 1]; for (int i = min; i <= max; i++) newSelectedIndexes[i - min] = i; ((FoundSet) fs).setSelectedIndexes(newSelectedIndexes); } } } else if (index != -1 || fs.getSize() == 0) { fs.setSelectedIndex(index); } } } else if (!isIndexSelected(fs, index)) fs.setSelectedIndex(index); if (!isIndexSelected(fs, index) && !(fs instanceof FoundSet && ((FoundSet) fs).isMultiSelect())) { // setSelectedIndex failed, probably due to validation failed, do a blur() if (target != null) target.appendJavascript("var toBlur = document.getElementById(\"" + component.getMarkupId() + "\");if (toBlur) toBlur.blur();"); return false; } } } return true; }
From source file:com.userweave.components.valueListPanel.ValueListPanel.java
License:Open Source License
private void addListRow(final RepeatingView repeating, final T value) { final WebMarkupContainer item = new WebMarkupContainer(repeating.newChildId()); repeating.add(item);//w ww. j a va 2 s .c o m Component listComponent = getListComponent("rowDisplay", value); item.add(listComponent); final IModel model = listComponent.getDefaultModel(); item.add(new Link("delete") { @Override public void onClick() { repeating.remove(item); controller.removeValue((T) model.getObject()); } }); }
From source file:com.visural.wicket.behavior.jsr303.JSR303AnnotatedPropertyModelBehavior.java
License:Apache License
private boolean addValidators(Component component) { if (FormComponent.class.isAssignableFrom(component.getClass())) { FormComponent fc = (FormComponent) component; Object model = component.getDefaultModel(); if (model != null) { if (AbstractPropertyModel.class.isAssignableFrom(model.getClass())) { AbstractPropertyModel apm = (AbstractPropertyModel) model; if (apm.getPropertyField() != null) { Annotation[] annots = apm.getPropertyField().getAnnotations(); Long min = null; Long max = null; for (Annotation a : annots) { if (a.annotationType().getName().equals("javax.validation.constraints.NotNull")) { IValidator v = newNotNullValidator(); if (v == null) { fc.setRequired(true); } else { fc.add(v); }/*from w w w . ja v a 2 s .co m*/ } else if (a.annotationType().getName().equals("javax.validation.constraints.Min")) { min = ((Min) a).value(); } else if (a.annotationType().getName().equals("javax.validation.constraints.Max")) { max = ((Max) a).value(); } else if (a.annotationType().getName().equals("javax.validation.constraints.Past")) { fc.add(newPastValidator()); } else if (a.annotationType().getName().equals("javax.validation.constraints.Future")) { fc.add(newFutureValidator()); } else if (a.annotationType().getName() .equals("javax.validation.constraints.Pattern")) { Pattern pattern = (Pattern) a; fc.add(newPatternValidator(pattern.regexp())); } else if (a.annotationType().getName().equals("javax.validation.constraints.Size")) { Size size = (Size) a; fc.add(newSizeValidator(size.min(), size.max())); } else if (a.annotationType().getName().equals(getEmailAnnotationClassName())) { fc.add(newEmailValidator()); } } if (max != null || min != null) { fc.add(newMinMaxValidator(min, max)); } } } return true; } } return false; }