2010-03-10 65 views
0

我想重置窗体中的一些值使用a4j:actionParam标记。但它接缝的空值永远不会到达目标bean。转换器正确接收它,返回null,但它从不在bean中设置。Richfaces a4j achtionparam设置空值

目标是填写不同预定义值(上周,上个月等)的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> 

回答

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}); 
     } 
    } 
} 

目前想着最好的方法来绕过这个!

+0

传递具有特定值的日期并在后台bean的setter中忽略它们可能是一种解决方法。 (例如,日期0-0-0 0:0:0)。但是这味道不好 – 2010-04-26 09:56:20

相关问题