selected items

6 posts / 0 new
Last post
atao
Offline
Joined: 10/15/2008
selected items

Vincent,

 

What is the best way to get the list of selected items inside an AbstractBackendAction launched from a view created with BasicTableViewDescriptor.

 

Regards

Pierre

vvandens
Offline
Joined: 05/29/2008
selected items

Hi Pierre,

Basically, you have to wrap your backend action into a frontend action and install the latest into your table view. This will create a button in the view toolbar (as well as a popup menu whenever the technology supports it). Whenever the user triggers the action, the action sets up its initial context (a map of objects keyed by strings) that will be forwarded all along the action chain. A collection type view action (on table and list) will therefore setup the context with the selected view indices. Then, the context is passed to the wrapped backend action and you can use the indices to retrieve the model objects and work on them.

As an entry point, have a look to how things are achieved in the standard Jspresso duplicate action (used to clone one or more selected elements in a collection view) :

org.jspresso.framework.application.backend.action.AbstractCloneCollectionAction
.execute(IActionHandler , Map<String, Object>)

And how a backend action is wrapped into a frontend action that can later be installed in views; in commons-frontend.xml :

 

  <bean
    id="cloneEntityCollectionFrontAction"
    class="org.jspresso.framework.application.frontend.action.WrappingAction">
    ...
    <property name="wrappedAction">
      <bean
        class="org.jspresso.framework.application.backend.action.CloneEntityCollectionAction">
        <property
          name="entityCloneFactory"
          ref="smartEntityCloneFactory" />
      </bean>
    </property>
    ...
  </bean>

 

You can also see how the initial action context is built for instance in swing :

org.jspresso.framework.view.swing.SwingActionFactory
.ActionAdapter.actionPerformed(ActionEvent)

Some big principles to catch (the doc is not finished on these) are :

  • Views and models are abstracted by what we call connectors. Connectors know how to bind together and they make possible different kind of views and models to work together without knowing eachother in advance (the adaptor pattern). you have view connectors that adapt to the view components and model connectors that adapt to the model.
  • You should never work on your domain objects from a frontend action. The frontend actions are only related to the view and its state. They should be kept as minimal as possible and delegate to backend actions, passing everything needed regarding the view state. This will make most of your backend code re-usable from different frontend technologies.
  • The backend actions are completely view agnostic. They work from their execution context that are most of the time inited by frontend actions.

Tell me if you need more infos on any special subject.

Regards,

Vincent

atao
Offline
Joined: 10/15/2008
selected items

Vincent,

ATM  AbstractCollectionAction is enough to make me happy!

Thanks

Pierre

atao
Offline
Joined: 10/15/2008
selected items

Vincent,

 

From a list of entity (a BasicTableViewDescriptor), I want:

- to select one of them

- to show its attributes

- to return to the list

I don't need any interaction with a module.

Is there already an action to do it? Or what is the simplest way?

 

Regards

Pierre

vvandens
Offline
Joined: 05/29/2008
selected items

Hi Pierre,

I've just done some refactoring on actions so that what you want to achieve will be quite straightforward. As usual, I've updated the maven repository with the updated maven artifacts. The action you need to define is then (update what's in bold to meet your needs):

<bean
parent="abstractCollectionAction">
<property
name="name"
value="action.name" />
<property
name="description"
value="action.description" />
<property
name="iconImageURL"
value="classpath:org/jspresso/framework/application/images/view-48x48.png" />
<property
name="nextAction">
<bean
parent="editComponentAction">
<property
name="viewDescriptor"
ref="Employee.pane" />
</bean>
</property>
</bean>

Once installed on a collection view, it will get the selected element, build a view based on the view descriptor and pop it up in a dialog until the user closes it.

BTW, you could also have built a "master-detail" view that would have make this useless.

Tell me if it fits.

Regards,

Vincent

 

atao
Offline
Joined: 10/15/2008
selected items

Vincent

[quote]

I've just done some refactoring on actions so that what you want to achieve will be quite straightforward

[/quote]

Thanks. It's just what I want!

 

[quote]

BTW, you could also have built a "master-detail" view that would have make this useless.

[/quote]

It's a view with already 3 chained lists (workers->contracts->payslips). I don't want to split it again with a fourth pane. To get detail view in a modal window  seems better here. By the way, the user usually doesn't need the all the details of a payslip (or worker, contract...).

Regards

Pierre