List of usage examples for org.apache.wicket.util.string StringValue toInteger
public final Integer toInteger() throws StringValueConversionException
From source file:org.jaulp.wicket.base.util.parameter.PageParametersUtils.java
License:Apache License
/** * Gets the Integer object or returns null if the given StringValue is null or empty. * * @param stringValue//from w w w .j av a2s.c om * the user id as StringValue object * @return the Integer object or null if the given StringValue is null or empty. */ public static Integer toInteger(StringValue stringValue) { Integer value = null; if (isNotNullOrEmpty(stringValue)) { try { value = stringValue.toInteger(); } catch (StringValueConversionException e) { LOGGER.error("Error by converting the given StringValue.", e); } } return value; }
From source file:org.projectforge.plugins.marketing.AddressCampaignValueEditPage.java
License:Open Source License
public AddressCampaignValueEditPage(final PageParameters parameters) { super(parameters, "plugins.marketing.addressCampaign"); StringValue sval = parameters.get(AbstractEditPage.PARAMETER_KEY_ID); final Integer id = sval.isEmpty() == true ? null : sval.toInteger(); if (id == null) { // Create new entry. sval = parameters.get(PARAMETER_ADDRESS_ID); final Integer addressId = sval.isEmpty() ? null : sval.toInteger(); sval = parameters.get(PARAMETER_ADDRESS_CAMPAIGN_ID); final Integer addressCampaignId = sval.isEmpty() ? null : sval.toInteger(); if (addressId == null || addressCampaignId == null) { throw new UserException("plugins.marketing.addressCampaignValue.error.addressOrCampaignNotGiven"); }/*from w w w . ja v a 2 s. co m*/ final AddressDO address = addressDao.getById(addressId); final AddressCampaignDO addressCampaign = addressCampaignDao.getById(addressCampaignId); if (address == null || addressCampaign == null) { throw new UserException("plugins.marketing.addressCampaignValue.error.addressOrCampaignNotGiven"); } AddressCampaignValueDO data = addressCampaignValueDao.get(addressId, addressCampaignId); if (data == null) { data = new AddressCampaignValueDO(); data.setAddress(address); data.setAddressCampaign(addressCampaign); } init(data); } else { init(); } }
From source file:org.projectforge.web.wicket.WicketUtils.java
License:Open Source License
public static Integer getAsInteger(final PageParameters parameters, final String name) { final StringValue sval = parameters.get(name); if (sval == null || sval.isNull() == true) { return null; } else {/* w ww.j av a2s. c o m*/ return sval.toInteger(); } }
From source file:org.projectforge.web.wicket.WicketUtils.java
License:Open Source License
/** * @param pageParameters/*from w ww . ja v a 2s .co m*/ * @param key * @param objectType * @see #putPageParameter(PageParameters, String, Object) */ public static Object getPageParameter(final PageParameters pageParameters, final String key, final Class<?> objectType) { if (objectType.isAssignableFrom(Date.class) == true) { final StringValue sval = pageParameters.get(key); if (sval.isNull() == true) { return null; } return new Date(sval.toLongObject()); } else if (objectType.isAssignableFrom(Boolean.class) == true) { return pageParameters.get(key).toBooleanObject(); } else if (objectType.isPrimitive() == true) { if (Boolean.TYPE.equals(objectType)) { return pageParameters.get(key).toBooleanObject(); } else if (Integer.TYPE.equals(objectType) == true) { return pageParameters.get(key).toInteger(); } else if (Long.TYPE.equals(objectType) == true) { return pageParameters.get(key).toLong(); } else if (Float.TYPE.equals(objectType) == true) { return new Float(pageParameters.get(key).toDouble()); } else if (Double.TYPE.equals(objectType) == true) { return pageParameters.get(key).toDouble(); } else if (Character.TYPE.equals(objectType) == true) { return pageParameters.get(key).toChar(); } else { log.warn("Primitive objectType '" + objectType + "' not yet implemented. Parameter type '" + key + "' is ignored."); } } else if (Enum.class.isAssignableFrom(objectType) == true) { final StringValue sval = pageParameters.get(key); if (sval.isNull() == true) { return null; } final String sValue = sval.toString(); @SuppressWarnings({ "unchecked", "rawtypes" }) final Enum<?> en = Enum.valueOf((Class<Enum>) objectType, sValue); return en; } else if (objectType.isAssignableFrom(Integer.class) == true) { final StringValue sval = pageParameters.get(key); if (sval.isNull() == true) { return null; } return sval.toInteger(); } else if (objectType.isAssignableFrom(String.class) == true) { return pageParameters.get(key).toString(); } else if (objectType.isAssignableFrom(TimePeriod.class) == true) { final String sValue = pageParameters.get(key).toString(); if (sValue == null) { return null; } final int pos = sValue.indexOf('-'); if (pos < 0) { log.warn("PageParameter of type TimePeriod '" + objectType.getName() + "' in wrong format: " + sValue); return null; } final Long fromTime = NumberHelper.parseLong(sValue.substring(0, pos)); final Long toTime = pos < sValue.length() - 1 ? NumberHelper.parseLong(sValue.substring(pos + 1)) : null; return new TimePeriod(fromTime != null ? new Date(fromTime) : null, toTime != null ? new Date(toTime) : null); } else { log.error("PageParameter of type '" + objectType.getName() + "' not yet supported."); } return null; }