views:

284

answers:

1

I am trying to reset some values in a form using the a4j:actionParam tag. But it seams that null values never arrive in the target bean. The converter receives it correctly, returns null, but it is never set in the bean.

The target is to fill in the start and endDate for different predefined values (last week, last month etc). For the "This week" value, the endDate must be reset to 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  A: 

I've just found this out too. The processAction method of UIActionParameter in A4J ignores null values.

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

Currently thinking about the best way to get round this!

bravocharlie
passing dates with a specific value and ignore them in the setter of the backing bean could be a workaround. (date 0-0-0 0:0:0 for example). But this smells bad
Jurgen H