/** Will add the specified type - value metadata as a property to the selected resource. */ public void processAction(ActionEvent actionEvent) throws AbortProcessingException { UIComponent comp = actionEvent.getComponent(); String id = comp.getId(); UIComponent superParent = comp; WebDAVCategories realCategories = null; while (superParent.getParent() != null) { superParent = superParent.getParent(); if (superParent instanceof WebDAVCategories) { realCategories = (WebDAVCategories) superParent; } } if (realCategories == null) { realCategories = (WebDAVCategories) superParent.findComponent(getId()); } if (id.equalsIgnoreCase(getAddButtonId())) { // Add a category to the list of selectable categories // This is input for adding a category HtmlInputText newCategoryInput = (HtmlInputText) comp.getParent().findComponent(getAddCategoryInputId()); String newCategoryName = newCategoryInput.getValue().toString(); CategoryBean.getInstance().addCategory(newCategoryName); if (realCategories != null) { realCategories.reset(); } return; } else if (id.equalsIgnoreCase(getSaveButtonId())) { realCategories.saveCategoriesSettings(); } }
// 编写处理Action事件的方法 public void process(ActionEvent ae) { if (name.equals("疯狂Java讲义")) { price.setValue(ae.getComponent()); price.setSize(60); price.setStyle("background-color:#1111ff;" + "font-weight:bold"); } }
/* (non-Javadoc) * @see org.ajax4jsf.tests.AbstractAjax4JsfTestCase#setUp() */ public void setUp() throws Exception { super.setUp(); uiMessages = new MockRichMessages(); uiMessages.setId(MESSAGES_ID); List<UIComponent> children = facesContext.getViewRoot().getChildren(); children.add(uiMessages); HtmlInputText inputText = new HtmlInputText(); inputText.setId(INPUT_ID); children.add(inputText); }
@Override public void encodeEnd(FacesContext context) throws IOException { super.encodeEnd(context); AliasVariableMapper alias = getAliasVariableMapper(context); if (alias != null) { AliasVariableMapper.removeAliasesExposedToRequest(context, alias.getId()); } }
@Override public void restoreState(FacesContext context, Object state) { Object[] values = (Object[]) state; super.restoreState(context, values[0]); var = (String) values[1]; submitValue = (Boolean) values[2]; submittedValue = values[3]; }
// 编写处理Action事件的方法 public void processAction(ActionEvent event) { // 获取当前的FacesContext对象 FacesContext context = FacesContext.getCurrentInstance(); // 获取JSF页面中<f:view.../>元素 UIViewRoot viewRoot = context.getViewRoot(); // 通过ID获取<f:view.../>内的<h:form.../>子元素。 UIComponent comp = viewRoot.findComponent("addForm"); // 通过ID获取<h:form.../>内的第一个<h:inputText.../>子元素。 UIInput input = (UIInput) comp.findComponent("name"); // 通过ID获取<h:form.../>内的第二个<h:inputText.../>子元素。 HtmlInputText price = (HtmlInputText) comp.findComponent("price"); if (input.getValue().equals("疯狂Java讲义")) { price.setSize(60); price.setValue("99.0元"); price.setStyle("background-color:#9999ff;" + "font-weight:bold"); } }
/** * Returns a container with "add category" UI * * @return WFContainer */ private WFContainer getAddCategoryContainer() { WFContainer container = new WFContainer(); WFResourceUtil localizer = WFResourceUtil.getResourceUtilContent(); // Text HtmlOutputText addText = localizer.getTextVB("new_category"); container.add(addText); // Input HtmlInputText newCategoryInput = new HtmlInputText(); newCategoryInput.setSize(40); newCategoryInput.setId(getAddCategoryInputId()); container.add(newCategoryInput); // Button HtmlCommandButton addCategoryButton = localizer.getButtonVB(getAddButtonId(), "add", this); container.add(addCategoryButton); return container; }
/** * 检验网站缩写是否在数据库中存在 * * @param event */ public void checkSiteCode(ActionEvent event) { HtmlInputText inputText = (HtmlInputText) event.getComponent().findComponent("siteCode"); String siteCode = (String) inputText.getValue(); if (siteCode == null || "".equals(siteCode)) { this.setSiteType(""); return; } String sql = "select siteCode,siteType from ledadsource where siteCode='" + siteCode + "'"; ExeSQL tExeSQL = new ExeSQL(); SSRS tSSRS = new SSRS(); tSSRS = tExeSQL.execSQL(sql); int row = tSSRS.getMaxRow(); if (row > 0) { this.setSiteType(tSSRS.GetText(1, 2)); return; } this.setSiteType(""); }
@Override public void validate(FacesContext facesContext, UIComponent uiComponent, Object userInput) throws ValidatorException { HtmlInputText htmlInputText = (HtmlInputText) uiComponent; String label; if (htmlInputText.getLabel() == null || htmlInputText.getLabel().trim().equals("")) { label = htmlInputText.getId(); } else { label = htmlInputText.getLabel(); } if ((Integer) userInput < 0) { FacesMessage facesMessage = new FacesMessage(label + ": the number can not be minus"); throw new ValidatorException(facesMessage); } }
@Override public void validate(FacesContext facesContext, UIComponent uIComponent, Object value) throws ValidatorException { Pattern pattern = Pattern.compile("\\b\\d{1,8}[K|k|0-9]"); // Long valor=(Long)value; String cadena = String.valueOf(value); Matcher matcher = pattern.matcher((CharSequence) cadena); HtmlInputText htmlInputText = (HtmlInputText) uIComponent; String label; if (htmlInputText.getLabel() == null || htmlInputText.getLabel().trim().equals("")) { label = htmlInputText.getId(); } else { label = htmlInputText.getLabel(); } if (!matcher.matches()) { if ((CharSequence) value == "") { FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_ERROR, "", label + ": Campo Obligatorio Vacío"); throw new ValidatorException(facesMessage); } else { FacesMessage facesMessage = new FacesMessage( FacesMessage.SEVERITY_ERROR, "", label + ": no presenta formato permitido. Reingrese rut sin puntos ni guión (ej: 171233496)"); throw new ValidatorException(facesMessage); } } else { /*si no es vacío y cumple el patron regular, se revisa la validez del rut*/ if (!validateRut((String) cadena)) { FacesMessage facesMessage = new FacesMessage( FacesMessage.SEVERITY_ERROR, "", label + ": el RUT ingresado no es válido"); throw new ValidatorException(facesMessage); } } }
@Override public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { String label; HtmlInputText htmlinputtext = (HtmlInputText) component; if (htmlinputtext.getLabel() == null || htmlinputtext.getLabel().trim().equals("")) { label = htmlinputtext.getId(); } else { label = htmlinputtext.getLabel(); } Pattern pattern = Pattern.compile("([a-zA-Z0-9\\.\\/-_]+\\@[a-zA-Z-]+\\.[a-zA-Z]+)*"); Matcher matcher = pattern.matcher((CharSequence) value); if (!matcher.matches()) { throw new ValidatorException( new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", label + ": no valido")); } }
public String getNextRunNumberAction() { String msg = "0"; try { msg = String.valueOf( getServiceLocator() .getRunSeqService() .getNextRunNumber((String) nameNextInputText.getValue())); } catch (RunSeqException re) { msg = re.getMessage(); } catch (Exception e) { msg = e.getMessage(); } nextRunNumberText.setValue(msg); return "#"; }
public String createRunSequenceAction() { String msg = "Sequence Created successfully"; try { getServiceLocator() .getRunSeqService() .createRunSequence((String) nameCreateInputText.getValue(), 0, 0); } catch (DuplicateRunSeqException dre) { msg = dre.getMessage(); } catch (RunSeqException re) { msg = re.getMessage(); } catch (Exception e) { msg = e.getMessage(); } createRunSequenceText.setValue(msg); return "#"; }
@Override public void broadcast(FacesEvent event) { if (event instanceof AliasEvent) { FacesContext context = getFacesContext(); AliasVariableMapper alias = getAliasVariableMapper(context); try { AliasVariableMapper.exposeAliasesToRequest(context, alias); FacesEvent origEvent = ((AliasEvent) event).getOriginalEvent(); origEvent.getComponent().broadcast(origEvent); } finally { if (alias != null) { AliasVariableMapper.removeAliasesExposedToRequest(context, alias.getId()); } } } else { super.broadcast(event); } }
@SuppressWarnings("deprecation") public void testWidgetProcessor() throws Exception { StandardConverterProcessor processor = new StandardConverterProcessor(); HtmlInputText htmlInputText = new HtmlInputText(); // Actions get no Converters processor.processWidget(htmlInputText, ACTION, null, null); assertEquals(null, htmlInputText.getConverter()); // Empty attributes get no Converters Map<String, String> attributes = CollectionUtils.newHashMap(); attributes.put(NAME, "foo"); processor.processWidget(htmlInputText, PROPERTY, attributes, null); assertEquals(null, htmlInputText.getConverter()); assertEquals(null, htmlInputText.getLabel()); // Explicit converter attributes.put(FACES_CONVERTER, "fooConverter"); processor.processWidget(htmlInputText, PROPERTY, attributes, null); assertEquals("fooConverter", htmlInputText.getConverter().toString()); // Explicit EL-based converter attributes.put(FACES_CONVERTER, "#{foo.converter}"); htmlInputText = new HtmlInputText(); processor.processWidget(htmlInputText, PROPERTY, attributes, null); assertEquals( "#{foo.converter}", htmlInputText.getValueBinding("converter").getExpressionString()); attributes.remove(FACES_CONVERTER); // Implicit DateTimeConverter attributes.put(TYPE, Date.class.getName()); htmlInputText = new HtmlInputText(); processor.processWidget(htmlInputText, PROPERTY, attributes, new HtmlMetawidget()); assertTrue(htmlInputText.getConverter() instanceof DateTimeConverter); htmlInputText = new HtmlInputText(); // DateTimeConverter attributes.put(DATE_STYLE, "full"); attributes.put(TIME_STYLE, "medium"); attributes.put(LOCALE, "UK"); attributes.put(DATETIME_PATTERN, "dd/MM/yyyy"); attributes.put(TIME_ZONE, "Australia/Sydney"); attributes.put(DATETIME_TYPE, "date"); processor.processWidget(htmlInputText, PROPERTY, attributes, new HtmlMetawidget()); assertEquals(null, htmlInputText.getLabel()); DateTimeConverter dateTimeConverter = (DateTimeConverter) htmlInputText.getConverter(); assertEquals("full", dateTimeConverter.getDateStyle()); assertEquals("medium", dateTimeConverter.getTimeStyle()); assertEquals("uk", dateTimeConverter.getLocale().getLanguage()); assertEquals("dd/MM/yyyy", dateTimeConverter.getPattern()); assertEquals("Australia/Sydney", dateTimeConverter.getTimeZone().getID()); assertEquals("date", dateTimeConverter.getType()); // NumberConverter attributes.clear(); attributes.put(CURRENCY_CODE, "AUD"); attributes.put(CURRENCY_SYMBOL, "$"); attributes.put(NUMBER_USES_GROUPING_SEPARATORS, TRUE); attributes.put(LOCALE, "AU"); attributes.put(MINIMUM_FRACTIONAL_DIGITS, "0"); attributes.put(MAXIMUM_FRACTIONAL_DIGITS, "1"); attributes.put(MINIMUM_INTEGER_DIGITS, "2"); attributes.put(MAXIMUM_INTEGER_DIGITS, "5"); attributes.put(NUMBER_PATTERN, "#0.00"); attributes.put(NUMBER_TYPE, "currency"); // (should not overwrite existing Converter) processor.processWidget(htmlInputText, PROPERTY, attributes, null); assertEquals(dateTimeConverter, htmlInputText.getConverter()); htmlInputText.setConverter(null); processor.processWidget(htmlInputText, PROPERTY, attributes, null); NumberConverter numberConverter = (NumberConverter) htmlInputText.getConverter(); assertEquals("AUD", numberConverter.getCurrencyCode()); assertEquals("$", numberConverter.getCurrencySymbol()); assertTrue(numberConverter.isGroupingUsed()); assertEquals("au", numberConverter.getLocale().getLanguage()); assertEquals(0, numberConverter.getMinFractionDigits()); assertEquals(1, numberConverter.getMaxFractionDigits()); assertEquals(2, numberConverter.getMinIntegerDigits()); assertEquals(5, numberConverter.getMaxIntegerDigits()); assertEquals("#0.00", numberConverter.getPattern()); assertEquals("currency", numberConverter.getType()); }
@Override public void queueEvent(FacesEvent event) { event = new AliasEvent(this, event); super.queueEvent(event); }
@Override public void setValue(Object value) { super.setValue(value); saveToBean(value); }
@Override public void encodeBegin(FacesContext context) throws IOException { AliasVariableMapper alias = getAliasVariableMapper(context); AliasVariableMapper.exposeAliasesToRequest(context, alias); super.encodeBegin(context); }
public UIComponent buildWidget( String elementName, Map<String, String> attributes, UIMetawidget metawidget) { FacesContext context = FacesContext.getCurrentInstance(); Application application = context.getApplication(); Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, null); if (clazz == null) { return null; } // Colors (as of RichFaces 3.3.1) if (Color.class.equals(clazz)) { if (WidgetBuilderUtils.isReadOnly(attributes)) { return FacesContext.getCurrentInstance() .getApplication() .createComponent(HtmlOutputText.COMPONENT_TYPE); } return application.createComponent("org.richfaces.ColorPicker"); } // Suggestion box // // Note: for suggestion box to work in table column footer facets, you need // https://jira.jboss.org/jira/browse/RF-7700 if (String.class.equals(clazz)) { String facesSuggest = attributes.get(FACES_SUGGEST); if (facesSuggest != null) { UIComponent stubComponent = application.createComponent(UIStub.COMPONENT_TYPE); List<UIComponent> children = stubComponent.getChildren(); // Standard text box HtmlInputText inputText = (HtmlInputText) application.createComponent(HtmlInputText.COMPONENT_TYPE); inputText.setStyle(((HtmlMetawidget) metawidget).getStyle()); inputText.setStyleClass(((HtmlMetawidget) metawidget).getStyleClass()); children.add(inputText); UISuggestionBox suggestionBox = (UISuggestionBox) application.createComponent(HtmlSuggestionBox.COMPONENT_TYPE); // Lock the 'id's so they don't get changed. This is important for the // JavaScript getElementById that RichFaces generates. Also, do not just use // 'viewRoot.createUniqueId' because, as per the RenderKit specification: // // "If the value returned from component.getId() is non-null and does not start // with UIViewRoot.UNIQUE_ID_PREFIX, call component.getClientId() and render // the result as the value of the id attribute in the markup for the component." // // Therefore the 'id' attribute is never rendered, therefore the JavaScript // getElementById doesn't work. Add our own prefix instead inputText.setId("suggestionText_" + FacesUtils.createUniqueId()); suggestionBox.setId("suggestionBox_" + FacesUtils.createUniqueId()); // Suggestion box suggestionBox.setFor(inputText.getId()); suggestionBox.setVar("_internal"); children.add(suggestionBox); try { // RichFaces 3.2/JSF 1.2 mode // // Note: we wrap the MethodExpression as an Object[] to stop link-time // dependencies on javax.el.MethodExpression, so that we still work with // JSF 1.1 // // Note: according to JavaDocs returnType is only important when literal // (i.e. without #{...}) expression is used, otherwise Object.class is fine // (http://community.jboss.org/message/516830#516830) Object[] methodExpression = new Object[] { application .getExpressionFactory() .createMethodExpression( context.getELContext(), facesSuggest, Object.class, new Class[] {Object.class}) }; ClassUtils.setProperty(suggestionBox, "suggestionAction", methodExpression[0]); } catch (Exception e) { // RichFaces 3.1/JSF 1.1 mode MethodBinding methodBinding = application.createMethodBinding(facesSuggest, new Class[] {Object.class}); suggestionBox.setSuggestionAction(methodBinding); } // Column // // Note: this must be javax.faces.component.html.HtmlColumn, not // org.richfaces.component.html.HtmlColumn. The latter displayed okay, but when // a value was selected it did not populate back to the HtmlInputText UIColumn column = (UIColumn) application.createComponent(javax.faces.component.html.HtmlColumn.COMPONENT_TYPE); column.setId(FacesUtils.createUniqueId()); suggestionBox.getChildren().add(column); // Output text box UIComponent columnText = application.createComponent(HtmlOutputText.COMPONENT_TYPE); columnText.setId(FacesUtils.createUniqueId()); ValueBinding valueBinding = application.createValueBinding("#{_internal}"); columnText.setValueBinding("value", valueBinding); column.getChildren().add(columnText); return stubComponent; } } return null; }
/** * Takes a parent UIComponent and adds all UIComponents which are required for configuring a * metric. i.e. metric name, math expression, value, etc. * * @param metric * @param parent */ private void helperCreateUICompsForMetricConfig(MetricBean metric, UIComponent parent) { // 1)remove all existing child elements that may have been created previously from ALL // pConfigVeryGood, pConfigGood, etc. removeAllInputHelpersForMetricConfig(); // 2) now build the gui elements for building a metric configuration // 2a) Add an output text with the metric's name HtmlOutputText mnameText = new HtmlOutputText(); mnameText.setId("metricName" + metric.getInternalID()); mnameText.setValue(metric.getName()); // add on parent parent.getChildren().add(mnameText); // 2b) Select a math expression HtmlSelectOneMenu select2 = new HtmlSelectOneMenu(); select2.setId("mathSelect" + metric.getInternalID()); UISelectItems items2 = new UISelectItems(); items2.setId("mathvals" + metric.getInternalID()); items2.setValue(metric.getAllAvailableTypes()); Class[] parms2 = new Class[] {ValueChangeEvent.class}; ExpressionFactory ef = FacesContext.getCurrentInstance().getApplication().getExpressionFactory(); MethodExpression mb = ef.createMethodExpression( FacesContext.getCurrentInstance().getELContext(), "#{AutoEvalSerUserConfigBean.processMathExprChange}", null, parms2); MethodExpressionValueChangeListener vcl = new MethodExpressionValueChangeListener(mb); select2.addValueChangeListener(vcl); select2.getChildren().add(items2); select2.setImmediate(true); // place an ajax support on the selectonemenu field HtmlAjaxSupport ajaxSupport2 = new HtmlAjaxSupport(); // Class[] parms = new Class[]{ActionEvent.class}; // ajaxSupport.setAction(FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{AutoEvalSerUserConfigBean.sliderValue}", parms)); ajaxSupport2.setEvent("onchange"); // to add multiple ids for rerendering, separate them with a "," ajaxSupport2.setReRender(select2.getId()); ajaxSupport2.setEventsQueue("foo"); select2.getFacets().put("a4jsupport2", ajaxSupport2); // add to parent parent.getChildren().add(select2); // 2c) For all input types except boolean values: if (metric.isHtmlInputTextUsed()) { // enter a boundary value for a specific added metric HtmlInputText inputText = new HtmlInputText(); inputText.setId("metricBoundary" + metric.getInternalID()); inputText.setValue(metric.getEvalBoundary()); inputText.setSize(10); Class[] parms = new Class[] {ValueChangeEvent.class}; MethodExpression mb2 = ef.createMethodExpression( FacesContext.getCurrentInstance().getELContext(), "#{AutoEvalSerUserConfigBean.processMetricBoundaryValueChange}", null, parms); MethodExpressionValueChangeListener vcl2 = new MethodExpressionValueChangeListener(mb2); inputText.addValueChangeListener(vcl2); inputText.setImmediate(true); // place an ajax support on the InputText field HtmlAjaxSupport ajaxSupport = new HtmlAjaxSupport(); // Class[] parms = new Class[]{ActionEvent.class}; // ajaxSupport.setAction(FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{AutoEvalSerUserConfigBean.sliderValue}", parms)); ajaxSupport.setEvent("onchange"); // to add multiple ids for rerendering, separate them with a "," ajaxSupport.setReRender(inputText.getId()); ajaxSupport.setEventsQueue("foo"); inputText.getFacets().put("a4jsupport", ajaxSupport); // add to parent parent.getChildren().add(inputText); } else { // add a drop-down box for boolean values HtmlSelectOneMenu select = new HtmlSelectOneMenu(); select.setId("booleanSelect" + metric.getInternalID()); UISelectItems items = new UISelectItems(); items.setId("vals" + metric.getInternalID()); List<SelectItem> l = new ArrayList<SelectItem>(); l.add(new SelectItem("true")); l.add(new SelectItem("false")); items.setValue(l); Class[] parms = new Class[] {ValueChangeEvent.class}; MethodExpression mb3 = ef.createMethodExpression( FacesContext.getCurrentInstance().getELContext(), "#{AutoEvalSerUserConfigBean.processMetricBoundaryValueChange}", null, parms); MethodExpressionValueChangeListener vcl3 = new MethodExpressionValueChangeListener(mb3); select.addValueChangeListener(vcl3); select.getChildren().add(items); select.setImmediate(true); // place an ajax support on the selectonemenu field HtmlAjaxSupport ajaxSupport = new HtmlAjaxSupport(); // Class[] parms = new Class[]{ActionEvent.class}; // ajaxSupport.setAction(FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{AutoEvalSerUserConfigBean.sliderValue}", parms)); ajaxSupport.setEvent("onchange"); // to add multiple ids for rerendering, separate them with a "," ajaxSupport.setReRender(select.getId()); ajaxSupport.setEventsQueue("foo"); select.getFacets().put("a4jsupport", ajaxSupport); // add to parent parent.getChildren().add(select); } // 2d) finally the submit button for saving the configuration HtmlCommandButton button_save = new HtmlCommandButton(); button_save.setId("buttonSave" + metric.getInternalID()); button_save.setValue("add config"); Class[] parms3 = new Class[] {ActionEvent.class}; MethodExpression mb4 = ef.createMethodExpression( FacesContext.getCurrentInstance().getELContext(), "#{AutoEvalSerUserConfigBean.command_saveMetricConfiguration}", null, parms3); MethodExpressionActionListener vcl4 = new MethodExpressionActionListener(mb4); button_save.addActionListener(vcl4); UIParameter p = new UIParameter(); p.setId("param_save_button" + metric.getInternalID()); p.setName("pConfigPanel"); p.setValue(parent.getId()); button_save.getChildren().add(p); parent.getChildren().add(button_save); HtmlOutputText message = new HtmlOutputText(); message.setId("message" + metric.getInternalID()); message.setStyle("color:red;"); parent.getChildren().add(message); }
public void editUrl() { HtmlInputText text = (HtmlInputText) inputText; text.setDisabled(false); }