| 1 |
|
package org.trails.component.search; |
| 2 |
|
|
| 3 |
|
import java.lang.reflect.Constructor; |
| 4 |
|
|
| 5 |
|
import org.apache.commons.lang.ClassUtils; |
| 6 |
|
|
| 7 |
|
import org.apache.tapestry.form.translator.NumberTranslator; |
| 8 |
|
import org.hibernate.criterion.Restrictions; |
| 9 |
|
import org.trails.exception.TrailsRuntimeException; |
| 10 |
|
|
| 11 |
8 |
public abstract class NumberSearchField extends SimpleSearchField |
| 12 |
|
{ |
| 13 |
|
|
| 14 |
|
public Object getTypeSpecificValue() |
| 15 |
|
{ |
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
try |
| 23 |
|
{ |
| 24 |
8 |
Class type = ClassUtils.primitiveToWrapper(getPropertyDescriptor().getPropertyType()); |
| 25 |
8 |
Constructor cons = type.getConstructor(new Class[]{String.class}); |
| 26 |
8 |
return cons.newInstance(getValue().toString()); |
| 27 |
|
} |
| 28 |
0 |
catch (Exception ex) |
| 29 |
|
{ |
| 30 |
0 |
throw new TrailsRuntimeException(ex); |
| 31 |
|
} |
| 32 |
|
} |
| 33 |
|
|
| 34 |
|
public NumberTranslator getTranslator() |
| 35 |
|
{ |
| 36 |
0 |
NumberTranslator numberTranslator = (NumberTranslator) getValidatorTranslatorService().getTranslator(getPropertyDescriptor()); |
| 37 |
0 |
numberTranslator.setOmitZero(true); |
| 38 |
0 |
return numberTranslator; |
| 39 |
|
} |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
@Override |
| 43 |
|
public void buildCriterion() |
| 44 |
|
{ |
| 45 |
0 |
if (getValue() != null) |
| 46 |
|
{ |
| 47 |
0 |
getCriteria().add(Restrictions.eq(getPropertyDescriptor().getName(), getTypeSpecificValue())); |
| 48 |
|
} |
| 49 |
0 |
} |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
} |