selection and wizardAction

3 posts / 0 new
Last post
atao
Offline
Joined: 10/15/2008
selection and wizardAction

Vincent,

I need some help about wizardAction and selection from a table.

I put a button in a menu associated with a table. This button lauches a wizardAction with only one step to get a date.

As final action I use an AbstractCollectionAction instance, as I want to iterate on the selected items. See code below.

Then I get here a cast exception:

java.lang.ClassCastException: org.jspresso.framework.binding.model.ModelConnector cannot be cast to org.jspresso.framework.binding.ICollectionConnector at org.jspresso.framework.application.backend.action.AbstractCollectionAction.getModelConnector(AbstractCollectionAction.java:57) at org.popsuite.hr.backend.action.CreatePayslipForContractAction.execute(CreatePayslipForContractAction.java:24) at org.jspresso.framework.application.backend.AbstractBackendController.execute(AbstractBackendController.java:107) at org.jspresso.framework.application.frontend.controller.AbstractFrontendController.executeBackend(AbstractFrontendController.java:625) at org.jspresso.framework.application.frontend.controller.swing.DefaultSwingController.protectedExecuteBackend(DefaultSwingController.java:537) [...]

 

The question is: how to get the selected items in the final action?

 

Regards

Pierre

===================================================================

  <bean
    id="createPayslipFromContractFrontAction"
    parent="wizardAction"
    >
    <property name="firstWizardStep" ref="getCreatePaySlipDateWizardStep" />
    <property name="finishAction"    ref="createPayslipFromContractOkFrontAction" />
  </bean>
 
  <bean
    id="getCreatePaySlipDateWizardStep"
    class="org.jspresso.framework.application.frontend.action.wizard.StaticWizardStepDescriptor"
    >
    <property name="viewDescriptor">
      <bean
        class="org.jspresso.framework.view.descriptor.basic.BasicComponentViewDescriptor">
        <property name="modelDescriptor">
          <bean
            class="org.jspresso.framework.model.descriptor.basic.BasicComponentDescriptor">
            <property name="propertyDescriptors">
              <list>
                <bean class="org.jspresso.framework.model.descriptor.basic.BasicDatePropertyDescriptor">
                  <property name="name" value="refDate" />
                </bean>
              </list>
            </property>
          </bean>
        </property> 
      </bean>
    </property>
  </bean>

  <bean
    id="createPayslipFromContractOkFrontAction"
    class="org.jspresso.framework.application.frontend.action.WrappingAction">
    <property name="name" value="create.payslip.for.contracts" />
    <property name="wrappedAction">
      <bean class="org.popsuite.hr.backend.action.CreatePayslipForContractAction" />
    </property>
    <property
      name="iconImageURL"
      value="classpath:org/jspresso/framework/application/images/wizard-48x48.png" />
  </bean>
 
 public class CreatePayslipForContractAction extends AbstractCollectionAction {

    public final static String DATE_REF ="dateRef";
   
    @Override
    public boolean execute(
            IActionHandler actionHandler,
            Map<String, Object> context) {
       
        ICollectionConnector collectionConnector = getModelConnector(context);
        if (collectionConnector == null) return false;
        int[] selection = getSelectedIndices(context);
        if (null == selection) return false;
       
        Object result = context.get(ActionContextConstants.ACTION_PARAM);
        Date refDate = null;
        if (result != null) {
            if (result instanceof Map) {
                refDate = (Date) ((Map<?,?>) result).get("dateRef");
            } else if (result instanceof Date) {
                refDate = (Date) result;
            }
        }
        if (null == refDate) {
            refDate = new Date();
        }
       
        for (int i:selection) {
            Contract contract = (Contract) collectionConnector.getChildConnector(i).getConnectorValue();
            contract.createPayslips(refDate);
        }

        return super.execute(actionHandler, context);
    }

}

vvandens
Offline
Joined: 05/29/2008
selection and wizardAction

Pierre,

The problem is the following : whenever a action triggers a dialog pop-up (the wizard action for instance), the action context is backed-up in a special stack and a new one is created. When the dialog is disposed, the original context is restored for the action chain to proceed (only the ACTION_PARAM context value is preserved that, in your case, keeps the wizard model, i.e. a map containing your refDate).

The way you declare the createPayslipFromContractOkFrontAction makes it work on the dialog context instead of the original one (the dialog is not closed when the action actually executes). You should make the createPayslipFromContractOkFrontAction inherit (spring parent) from okDialogFrontAction that will take care of closing the dialog, restore the original context (thus making the collection connector available again), and trigger the CreatePayslipForContractAction execution.

Note that the okDialogFrontAction closes the current dialog (and pop the context stack) between its wrappedAction and its nextAction, i.e. wrappedAction will execute on the dialog context, whereas nextAction will execute on the original context. So the following declaration should fix your problem (of course, you can fine-tune it with a special icon as you did it) :

  <bean
    id="createPayslipFromContractOkFrontAction"
    parent="okDialogFrontAction">
    <property
      name="nextAction">
      <bean
        class="org.popsuite.hr.backend.action.CreatePayslipForContractAction" />
    </property>
  </bean>

Tell me if it doesn't work as expected.

 

Regards,

Vincent

atao
Offline
Joined: 10/15/2008
selection and wizardAction

Vincent,

Thanks, it runs fine.

Regards

Pierre