|
18 | 18 | import java.util.List; |
19 | 19 |
|
20 | 20 | import javax.faces.context.FacesContext; |
| 21 | +import javax.faces.convert.Converter; |
21 | 22 |
|
22 | 23 | import org.apache.commons.logging.Log; |
23 | 24 | import org.apache.commons.logging.LogFactory; |
|
31 | 32 | import com.ocpsoft.pretty.faces.url.URL; |
32 | 33 | import com.ocpsoft.pretty.faces.util.FacesElUtils; |
33 | 34 | import com.ocpsoft.pretty.faces.util.FacesStateUtils; |
| 35 | +import com.ocpsoft.pretty.faces.util.NullComponent; |
34 | 36 |
|
35 | 37 | /** |
36 | 38 | * @author Lincoln Baxter, III <lincoln@ocpsoft.com> |
@@ -69,10 +71,25 @@ private void injectPathParams(final FacesContext context, final URL url, final U |
69 | 71 | String el = param.getExpression().getELExpression(); |
70 | 72 | if ((el != null) && !"".equals(el.trim())) |
71 | 73 | { |
72 | | - String value = param.getValue(); |
| 74 | + String valueAsString = param.getValue(); |
73 | 75 | try |
74 | 76 | { |
75 | | - elUtils.setValue(context, el, value); |
| 77 | + |
| 78 | + // get the type of the referenced property and try to obtain a converter for it |
| 79 | + Class<?> expectedType = elUtils.getExpectedType(context, el); |
| 80 | + Converter converter = context.getApplication().createConverter(expectedType); |
| 81 | + |
| 82 | + // Use the convert to create the correct type |
| 83 | + if (converter != null) |
| 84 | + { |
| 85 | + Object convertedValue = converter.getAsObject(context, new NullComponent(), valueAsString); |
| 86 | + elUtils.setValue(context, el, convertedValue); |
| 87 | + } |
| 88 | + else |
| 89 | + { |
| 90 | + elUtils.setValue(context, el, valueAsString); |
| 91 | + } |
| 92 | + |
76 | 93 | } |
77 | 94 | catch (Exception e) |
78 | 95 | { |
@@ -112,8 +129,24 @@ private void injectQueryParams(final FacesContext context, final UrlMapping mapp |
112 | 129 | } |
113 | 130 | else |
114 | 131 | { |
115 | | - String value = queryString.getParameter(name); |
116 | | - elUtils.setValue(context, el, value); |
| 132 | + |
| 133 | + String valueAsString = queryString.getParameter(name); |
| 134 | + |
| 135 | + // get the type of the referenced property and try to obtain a converter for it |
| 136 | + Class<?> expectedType = elUtils.getExpectedType(context, el); |
| 137 | + Converter converter = context.getApplication().createConverter(expectedType); |
| 138 | + |
| 139 | + // Use the convert to create the correct type |
| 140 | + if (converter != null) |
| 141 | + { |
| 142 | + Object convertedValue = converter.getAsObject(context, new NullComponent(), valueAsString); |
| 143 | + elUtils.setValue(context, el, convertedValue); |
| 144 | + } |
| 145 | + else |
| 146 | + { |
| 147 | + elUtils.setValue(context, el, valueAsString); |
| 148 | + } |
| 149 | + |
117 | 150 | } |
118 | 151 | } |
119 | 152 | catch (Exception e) |
|
0 commit comments