2010-03-10 84 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

相關問題