Hi Erik,
Sorry not to get back to you before now.
As you've probably realized, there's no particularly clean API here to
leverage, and what you've written is isn't too far off the mark from what I
would have written.
In the Wicket viewer itself the ActionPanel uses the ActionModel (which you
discovered), and it invokes the action through the model [1], ie:
final ObjectAdapter resultAdapter =
getActionModel().executeHandlingApplicationExceptions();
Otherwise, looks ok.
Thx
Dan
[1]
https://github.com/apache/isis/blob/ef96cc80fe89290d2be79f831eb354dc0d7f886c/core/viewer-wicket-ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/actions/ActionPanel.java#L257
On 22 December 2015 at 12:10, Erik de Hair <[email protected]> wrote:
> For now I've got it working. Is there a better way of executing the action
> and returning the correct page?
>
> final ObjectAdapter serviceAdapter =
> getServiceAdapter(SearchService.class.getName());
> final ObjectAction action =
> serviceAdapter.getSpecification().getObjectAction("find");
>
> ActionModel actionModel = ActionModel.create(serviceAdapter,
> action);
>
> List<ActionParameterMemento> parametersList =
> actionModel.primeArgumentModels();
>
> AdapterManager am = (AdapterManager)getPersistenceSession();
> for (ActionParameterMemento actionParameterMemento :
> parametersList)
> {
> ScalarModel arg =
> actionModel.getArgumentModel(actionParameterMemento);
> switch (actionParameterMemento.getNumber())
> {
> case 0:
> arg.setObject(am.adapterFor(this.query));
> break;
> case 1:
> if(this.preference != null)
> {
> arg.setObject(am.adapterFor(SearchService.Type.valueOf(this.preference)));
> }
> break;
> case 2:
> arg.setObject(am.adapterFor(boost));
> break;
> default:
> break;
> }
> }
>
> ObjectAdapter resultAdapter = action.execute(serviceAdapter,
> actionModel.getArgumentsAsArray(), InteractionInitiatedBy.USER);
>
> ActionResultResponse resultResponse =
> ActionResultResponseType.COLLECTION.interpretResult(actionModel, null,
> resultAdapter);
> resultResponse.getHandlingStrategy().handleResults(this,
> resultResponse);
>
>
> On 12/21/2015 09:10 AM, Erik de Hair wrote:
>
>> Hi,
>>
>> I'm trying to create a generic search component that should show up in
>> the footer bar. Creating the component itself is not a problem but
>> returning the results is. The component is calling a service like this:
>>
>> final SearchService searchService = lookupService(SearchService.class);
>> SortedSet<SearchResult> results = searchService.find(this.query, null, 1);
>>
>> I was thinking about returning a StandaloneCollectionPage or ViewModel by
>> using ActionResultResponseType but I can't figure out to create the model
>> right. So how to set the response page with the right parameters?
>>
>> Thanks,
>> Erik
>>
>
>