I have two buttons, in one I need <f:convertDateTime>
to work but in another I need to disable <f:convertDateTime>
on button click.
I tried the attributes rendered
and disabled
, but it didn't work, which was my mistake as it is not available as per the API docs.
Also, is there a way to override the class javax.faces.converter.DateTimeConverter
such that whenever f:convertDateTime
is triggered my class will be called?
I tried the attributes rendered and disabled, but it didn't work, which was my mistake as it is not available as per the API docs.
Indeed, this behavior is not supported. However, as to a possible solution, you basically already gave the answer yourself:
Also, is there a way to override the class
javax.faces.converter.DateTimeConverter
such that wheneverf:convertDateTime
is triggered my class will be called?
That is possible and will also solve your initial problem. Just register it as <converter>
in faces-config.xml
on exactly the same <converter-id>
as <f:convertDateTime>
.
<converter>
<converter-id>javax.faces.DateTime</converter-id>
<converter-class>com.example.YourDateTimeConverter</converter-class>
</converter>
Therein you could do additional conditional checking, such as checking if a certain button is pressed, or if a certain request parameter is present or absent. If you'd like to continue the default <f:convertDateTime>
job, just delegate to super
provided that your converter extends
from DateTimeConverter
.
E.g. in getAsObject()
:
public class YourDateTimeConverter extends DateTimeConverter {
@Override
public void getAsObject(FacesContext context, UIComponent component, String submittedValue) {
// ...
if (yourCondition) {
// Do your preferred way of conversion here.
// ...
return yourConvertedDateTime;
} else {
// Do nothing. Just let default f:convertDateTime do its job.
return super.getAsObject(context, component, submittedValue);
}
}
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With