Dynamic View Panel日期格式化自定义Bean无效,求助排查及实现
I see the exact issue with your current code—you’ve defined a custom ViewColumnConverter, but you haven’t told the DominoViewCustomizer to actually use it! The customizer bean needs to override the createColumnConverter method to return your converter instance; without this step, the Dynamic View Panel will just stick to the default converter, ignoring your logic entirely.
Here’s a corrected, simplified version of your bean that will work, plus some robustness improvements:
import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.concurrent.ThreadLocal; import javax.faces.context.FacesContext; import javax.faces.component.UIComponent; import lotus.domino.DateTime; import com.ibm.xsp.extlib.component.dynamicview.DominoViewCustomizer; import com.ibm.xsp.extlib.component.dynamicview.ViewColumnConverter; public class DynamicViewCustomizerBean_Ben extends DominoViewCustomizer { // Use ThreadLocal to make SimpleDateFormat thread-safe (critical for server-side code) private static final ThreadLocal<SimpleDateFormat> DATE_FORMATTER = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH)); @Override protected ViewColumnConverter createColumnConverter() { // This is the missing piece: return our custom converter to the view panel return new ExtendedViewColumnConverter(); } public static class ExtendedViewColumnConverter extends ViewColumnConverter { @Override public String getValueAsString(final FacesContext context, final UIComponent component, final Object value) { // Handle Domino's native DateTime type first if (value instanceof DateTime) { DateTime dominoDateTime = (DateTime) value; return DATE_FORMATTER.get().format(dominoDateTime.toJavaDate()); } // Handle standard Java Date objects if (value instanceof Date) { return DATE_FORMATTER.get().format((Date) value); } // Fall back to default converter for all other data types return super.getValueAsString(context, component, value); } } }
Key Fixes & Notes:
- Added
createColumnConverteroverride: This is the critical missing step. Without it, your custom converter never gets passed to the Dynamic View Panel—so it was never being used at all. - Thread-safe formatting:
SimpleDateFormatis not thread-safe, so wrapping it inThreadLocalprevents race conditions when multiple requests hit your bean simultaneously. - Proper Domino DateTime handling: Converting the Domino
DateTimeto a JavaDatewithtoJavaDate()ensures the formatter works as expected (your original code tried to format the Domino DateTime directly, which can cause unexpected behavior). - Consistent date pattern: I’ve standardized on
yyyy-MM-ddfor both date types as per your requirement—adjust the pattern inSimpleDateFormatif you need to include time later.
Double-Check Your Setup:
Confirm your Dynamic View Panel’s customizerBean property still points to the full class name of your bean, like you had before:
<xe:dynamicViewPanel id="dynamicViewPanel1" showColumnHeader="true" customizerBean="com.videotron.xpages.DynamicViewCustomizerBean_Ben" var="rowData"> <!-- Your panel content --> </xe:dynamicViewPanel>
If you still don’t see changes after updating the code, try cleaning your project and restarting the Domino server to ensure the updated bean is deployed properly.
内容的提问来源于stack exchange,提问作者Ben Dubuc

