You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "ir. ing. Jan Dockx" <ja...@mac.com> on 2005/09/18 21:26:37 UTC
param
After sweating, tearing my hair out, and debugging for hours, I must
come to the conclusion that we managed properties only seem to work
with Strings. Ok, but I just want to know why.
I'm trying to set a Long from HTTP request parameters. There is an
entry in the HTTP request parameter "myId", and I want to set it on
creation of a backing bean in the "id" property, which is of type Long:
...
<managed-property>
<property-name>id</property-name>
<value>#{param.myId}</value>
</managed-property>
...
Whatever I do (and I really tried tons of alternatives), I end up with
the id being the Long 0 (zero), whether there actually is a "myId"
request parameter (e.g. with value "4567") or not.
In the page I have
<h:outputText value="#{param.myId}" />
for debugging. Shows '0' (zero) always, whether there is a "myId" param
in the request or not. Not "", as expected when the request parameter
map would return null, but zero.
Now I switched to another strategy: pass the name of the HTTP request
parameter to the handler, and let it search the value:
...
<managed-property>
<property-name>idFromRequestParameterName</property-name>
<value>myId</value>
</managed-property>
...
and a new property setter:
public final void setIdFromRequestParameterName(String name) {
Map requestParameters =
FacesContext.getCurrentInstance().getExternalContext().getRequestParamet
erMap();
String idString = (String)requestParameters.get(name);
if (idString != null) {
try {
Long id = Long.valueOf(idString); // NumberFormatException
setId(id);
}
catch (NumberFormatException nfExc) {
RobustCurrent.fatalProblem("The id value in the request is not
a Long (" +
idString + ")",
nfExc,
LOG);
}
}
}
Nevermind that I don't do anything here if the parameter doesn't exist.
This works, and using the param stuff in the managed property
definition doesn't.
Ok. Why? I don't see it.
Met vriendelijke groeten,
Jan Dockx
PeopleWare NV - Head Office
Cdt.Weynsstraat 85
B-2660 Hoboken
Tel: +32 3 448.33.38
Fax: +32 3 448.32.66
PeopleWare NV - Branch Office Geel
Kleinhoefstraat 5
B-2440 Geel
Tel: +32 14 57.00.90
Fax: +32 14 58.13.25
http://www.peopleware.be/
http://www.mobileware.be/
Re: param
Posted by "ir. ing. Jan Dockx" <ja...@mac.com>.
BTW, I just got a little further. param DOES work for a String property:
<managed-property>
<property-name>viewMode</property-name>
<value>#{param['viewModeParamName']}</value>
</managed-property>
where viewMode is a String property on the handler. This works as
expected.
I'm getting the distinct impression that coercion on param is just
broken as hell. We've had previous problems with that, where we saw
that Converters are not used for managed properties. But this goes
further.
Is there a reason for this? Is this a (known) bug?
On 18 Sep 2005, at 21:26, ir. ing. Jan Dockx wrote:
> After sweating, tearing my hair out, and debugging for hours, I must
> come to the conclusion that we managed properties only seem to work
> with Strings. Ok, but I just want to know why.
>
> I'm trying to set a Long from HTTP request parameters. There is an
> entry in the HTTP request parameter "myId", and I want to set it on
> creation of a backing bean in the "id" property, which is of type
> Long:
> ...
> <managed-property>
> <property-name>id</property-name>
> <value>#{param.myId}</value>
> </managed-property>
> ...
>
> Whatever I do (and I really tried tons of alternatives), I end up
> with the id being the Long 0 (zero), whether there actually is a
> "myId" request parameter (e.g. with value "4567") or not.
>
>
> In the page I have
> <h:outputText value="#{param.myId}" />
> for debugging. Shows '0' (zero) always, whether there is a "myId"
> param in the request or not. Not "", as expected when the request
> parameter map would return null, but zero.
>
>
>
> Now I switched to another strategy: pass the name of the HTTP request
> parameter to the handler, and let it search the value:
>
> ...
> <managed-property>
> <property-name>idFromRequestParameterName</property-name>
> <value>myId</value>
> </managed-property>
> ...
>
> and a new property setter:
>
> public final void setIdFromRequestParameterName(String name) {
> Map requestParameters =
> FacesContext.getCurrentInstance().getExternalContext().getRequestParame
> terMap();
> String idString = (String)requestParameters.get(name);
> if (idString != null) {
> try {
> Long id = Long.valueOf(idString); // NumberFormatException
> setId(id);
> }
> catch (NumberFormatException nfExc) {
> RobustCurrent.fatalProblem("The id value in the request is not
> a Long (" +
> idString + ")",
> nfExc,
> LOG);
> }
> }
> }
>
> Nevermind that I don't do anything here if the parameter doesn't
> exist. This works, and using the param stuff in the managed property
> definition doesn't.
>
> Ok. Why? I don't see it.
>
>
>
> Met vriendelijke groeten,
>
> Jan Dockx
>
> PeopleWare NV - Head Office
> Cdt.Weynsstraat 85
> B-2660 Hoboken
> Tel: +32 3 448.33.38
> Fax: +32 3 448.32.66
>
> PeopleWare NV - Branch Office Geel
> Kleinhoefstraat 5
> B-2440 Geel
> Tel: +32 14 57.00.90
> Fax: +32 14 58.13.25
>
> http://www.peopleware.be/
> http://www.mobileware.be/
Met vriendelijke groeten,
Jan Dockx
PeopleWare NV - Head Office
Cdt.Weynsstraat 85
B-2660 Hoboken
Tel: +32 3 448.33.38
Fax: +32 3 448.32.66
PeopleWare NV - Branch Office Geel
Kleinhoefstraat 5
B-2440 Geel
Tel: +32 14 57.00.90
Fax: +32 14 58.13.25
http://www.peopleware.be/
http://www.mobileware.be/