...
MyFaces
...
Commons
...
Converters
...
contains
...
some
...
useful
...
converters
...
not
...
provided
...
by
...
the
...
spec,
...
and
...
a
...
base
...
class
...
for
...
create
...
custom
...
converters
...
using
...
myfaces-builder-plugin.
...
This
...
base
...
class
...
(
...
org.apache.myfaces.commons.converter.ConverterBase
...
)
...
allow
...
use
...
ValueExpressions
...
and
...
in
...
2.0
...
version
...
provides
...
an
...
implementation
...
of
...
StateHelper.
...
This
...
is
...
useful
...
in
...
cases
...
where
...
parameters
...
for
...
the
...
converter
...
are
...
bound
...
to
...
ValueExpression
...
instance
...
that
...
are
...
evaluated
...
at
...
runtime.
...
By
...
default,
...
converter
...
parameters
...
are
...
evaluated
...
on
...
build
...
time
...
(the
...
first
...
time
...
the
...
view
...
is
...
built),
...
so
...
they
...
cannot
...
change
...
over
...
the
...
time
...
(further
...
web
...
postback
...
requests).
...
To
...
understand
...
this,
...
take
...
a
...
look
...
at
...
this
...
example:
Code Block | ||||
---|---|---|---|---|
| ||||
{code:xml} <h:form id="form1"> <h:messages showDetail="false" showSummary="true" ></h:messages> <h:panelGrid columns="3"> <h:outputLabel for="type" value="Insert a type" /> <h:selectOneMenu id="type" immediate="true" value="#{numberBean.type}" > <f:selectItem itemLabel="number" itemValue="number"/> <f:selectItem itemLabel="currency" itemValue="currency"/> <f:selectItem itemLabel="percent" itemValue="percent"/> </h:selectOneMenu> <h:message for="type" styleClass="error" /> <h:outputLabel for="number1" value="Insert a number" /> <h:inputText id="number1" value="#{numberBean.numberMap['number1']}" required="true"> <mcc:convertNumber destType="java.lang.Double" type="#{mc:findComponent('form1:type').value}"/> </h:inputText> <h:message for="number1" styleClass="error" /> <h:commandButton id="validateButton" value="#{example_messages['button_submit']}" action="#{numberBean.submit}" /> </h:panelGrid> </h:form> {code} |
It
...
is
...
a
...
<h:
...
selectOneMenu>
that
...
allows
...
you
...
to
...
choose
...
a
...
type
...
that
...
is
...
then
...
read
...
by
...
a
...
converter.
...
This
...
can't
...
work
...
with
...
<f:
...
convertNumber>
,
...
because
...
the
...
ValueExpression
...
on
...
type
...
is
...
evaluated
...
at
...
build
...
time.
...
But
...
in
...
this
...
case,
...
<mcc:
...
convertNumber>
evaluate
...
them
...
each
...
time
...
the
...
conversion
...
occur.
...
Note
...
the
...
immediate="true"
...
in
...
<h:
...
selectOneMenu>
makes
...
the
...
value
...
of
...
the
...
component
...
be
...
evaluated
...
before
...
the
...
conversion
...
over
...
the
...
input
...
text.
...
Also,
...
in
...
this
...
project
...
you
...
can
...
found:
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...