【问题标题】:Richfaces a4j achtionparam set null valueRichfaces a4j achtionparam 设置空值
【发布时间】:2010-03-10 09:55:34
【问题描述】:

我正在尝试使用 a4j:actionParam 标记重置表单中的一些值。但它接缝的是空值永远不会到达目标 bean。转换器正确接收它,返回 null,但它从未在 bean 中设置。

目标是为不同的预定义值(上周、上个月等)填写 start 和 endDate。对于“本周”值,endDate 必须重置为 null。

 <rich:menuItem value="Last week">
   <a4j:support event="onclick" reRender="criteriaStartCalendar,criteriaEndCalendar">
    <a4j:actionparam name="startDate" value="#{dateBean.lastWeekStart}" assignTo="#{targetBean.startDate}" />
    <a4j:actionparam name="endDate" value="#{dateBean.lastWeekEnd}" assignTo="#{targetBean.endDate}" />
   </a4j:support>
  </rich:menuItem>

【问题讨论】:

    标签: null richfaces params ajax4jsf


    【解决方案1】:

    我也刚刚发现了这一点。 A4J中UIActionParameter的processAction方法忽略空值。

        public void processAction(ActionEvent actionEvent)
            throws AbortProcessingException {
        FacesContext context = getFacesContext();
        ELContext elContext = context.getELContext();
        ValueExpression updateBinding = getAssignToBinding();
        if (updateBinding != null && (!updateBinding.isReadOnly(elContext))) {
            Object requestValue = context.getExternalContext()
                    .getRequestParameterMap().get(getName());
            if (requestValue != null && requestValue instanceof String) {
                Class<?> type = updateBinding.getType(elContext);
                Converter converter = createConverter(context, type);
                if (null != converter) {
                    requestValue = converter.getAsObject(context, this,
                            (String) requestValue);
    
                }
            }
    
            // null is explicitly ignored!
            if (null != requestValue) {
                updateBinding.setValue(elContext, requestValue);
            }
    
    
            MethodExpression listener = getActionListener();
            if (listener != null) {
                listener.invoke(elContext, new Object[] {actionEvent});
            }
        }
    }
    

    目前正在考虑解决此问题的最佳方法!

    【讨论】:

    • 使用特定值传递日期并在支持 bean 的设置器中忽略它们可能是一种解决方法。 (例如日期 0-0-0 0:0:0)。但这闻起来很糟糕
    猜你喜欢
    • 2013-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-15
    • 1970-01-01
    • 2011-02-12
    • 2012-01-03
    相关资源
    最近更新 更多