-
Notifications
You must be signed in to change notification settings - Fork 2
Support a default result mapping on a base action #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| 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 [" + |
There was a problem hiding this comment.
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.
| 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("*"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Summary
Support a default result mapping.
Details
The result workflow will default to
FowardImplif 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.Reviewer Notes
Once this is merged and released into the
4.xline, I will merge it into the main line which is5.x.