Skip to content
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

WW-5379 Add one more method to provide Velocity directives with ValueStack #840

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.struts2.views.velocity.components;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.ServletActionContext;
Expand Down Expand Up @@ -59,11 +60,7 @@ public int getType() {
protected abstract Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res);

public boolean render(InternalContextAdapter ctx, Writer writer, Node node) throws IOException, ResourceNotFoundException, ParseErrorException, MethodInvocationException {
ValueStack stack = extractValueStack(ctx);
if (stack == null) {
// Fallback to assuming the ValueStack was put into the Velocity context (as is by default)
stack = (ValueStack) ctx.get(ContextUtil.STACK);
}
ValueStack stack = getValueStack(ctx);
HttpServletRequest req = (HttpServletRequest) stack.getContext().get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse res = (HttpServletResponse) stack.getContext().get(ServletActionContext.HTTP_RESPONSE);
Component bean = getBean(stack, req, res);
Expand All @@ -84,6 +81,19 @@ public boolean render(InternalContextAdapter ctx, Writer writer, Node node) thro
return true;
}

protected ValueStack getValueStack(Context context) {
ValueStack stack = extractValueStack(context);
if (stack == null) {
// Fallback to assuming the ValueStack was put into the Velocity context (as is by default)
stack = (ValueStack) context.get(ContextUtil.STACK);
}
if (stack == null) {
// Fallback to current ActionContext
stack = ActionContext.getContext().getValueStack();
}
return stack;
}

private ValueStack extractValueStack(Context context) {
do {
if (context instanceof ValueStackProvider) {
Expand Down