Skip to content

Conversation

@robotdan
Copy link
Member

@robotdan robotdan commented Jul 8, 2025

Summary

Support a default result mapping.

Details

The result workflow will default to FowardImpl if no annotation is found for the result code. This can be a problem at times because you don't always know ahead of time which result codes to expect.

Example, define the default result to be of type @Status.

@Action
@Status.List({
  @Status(code = "success", status = 200),
  @Status(code = "*")
})
public class FooAction {
   public String get() {
     return "success";
   } 
}

Reviewer Notes

Once this is merged and released into the 4.x line, I will merge it into the main line which is 5.x.

if (page == null) {
throw new PrimeException("Missing result for action class [" + actionInvocation.configuration.actionClass + "] URI [" +
actionInvocation.uri() + "] and result code [" + getCode(forward) + "]");
throw new PrimeException("Missing result for action class [" + actionInvocation.configuration.actionClass.getName() + "] URI [" +
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will mean the value inside of the square brackets is the fully qualified class name, but not prefixed with class since that is redundant.

@robotdan robotdan marked this pull request as ready for review July 9, 2025 20:18
@lyleschemmerling lyleschemmerling self-requested a review July 10, 2025 16:22
annotation = new ForwardImpl("", resultCode);
if (actionInvocation.action != null) {
// Note that if an action exists, a configuration exists, so we should not need to check for null on configuration.
annotation = actionInvocation.configuration.resultConfigurations.get("*");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only additional thing I can think of here is that this could lead to masking errors unless we explicitly look at the logs and see the exception. I am thinking we could use something similar to the allowUnknownParameters configuration that would allow this to succeed in "production" cases but explode at dev time. But then you would probably need an additional parameter on the result configuration that says "actually the wildcard is the intended result here" because you had a whole bunch of possible result codes that you didn't want to explicitly code for?

Since I am not sure about the impl for that maybe it should just be something to think about.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be true.

But today, we already fall back, it is just that the fallback isn't always what you want.

The fall back is generally what you want if you are going to render a template - in our case, likely an .ftl.

But you could make the argument that even in this case, the fall back is masking the fact that you don't have an explicit mapping.

It depends on how you look at it. You could always use the default mapping because you don't want to define explicit results. In that case, it isn't masking anything, but doing what you want.

If you do want to declare specific result mappings - then yes, this could mask the missing result code just as we do for FowardImpl today.

I could add a debug log when we hit a default condition like this in case someone wants to know when an explicit mapping was not found during the action result mapping workflow. I could see this being useful to someone.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this? There are two cases, we use the default defined by * or the fall back of FowardImpl.

Jul 10, 2025 10:45:11.900 AM DEBUG o.p.m.a.result.DefaultResultInvocationWorkflow - Missing result annotation for action class [org.example.action.SecureAction] URI [/secure] for result code [success]. The default mapping of [@Forward] was used. This message is provided in case you do wish to define an explicit mapping.

Jul 10, 2025 10:45:12.301 AM DEBUG o.p.m.a.result.DefaultResultInvocationWorkflow - Missing result annotation for action class [org.example.action.RequestedDefaultStatusResultAction] URI [/requested-default-status-result] for result code [foo]. A default mapping of [@Status] was configured using the [*] result code. This message is provided in case you do wish to define an explicit mapping.

@robotdan robotdan merged commit 19e1986 into 4.x_maintenance Jul 10, 2025
@robotdan robotdan deleted the degroff/add_default_result branch July 10, 2025 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants