struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lukasz Lenart (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (WW-4161) Incorporate tiles3 into conventions, tutorial (and add code to tiles3 plugin)
Date Wed, 03 Feb 2016 10:16:39 GMT

    [ https://issues.apache.org/jira/browse/WW-4161?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15130185#comment-15130185
] 

Lukasz Lenart commented on WW-4161:
-----------------------------------

I have developed the following {{UnknownHandler}} and using it in one of my project (Struts
+ Convention), I can donate it to Struts Convention plugin, wdyt?
{code:java}
public class TilesUnknownHandler implements UnknownHandler {

    private static Logger LOG = LogManager.getLogger(TilesUnknownHandler.class);

    @Override
    public ActionConfig handleUnknownAction(String namespace, String actionName) throws XWorkException
{
        return null;
    }

    @Override
    public Result handleUnknownResult(ActionContext actionContext, String actionName, ActionConfig
actionConfig, String resultCode) throws XWorkException {

        ServletContext servletContext = ServletActionContext.getServletContext();
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpServletResponse response = ServletActionContext.getResponse();

        TilesContainer container = TilesAccess.getContainer(servletContext);

        String namespace = ServletActionContext.getActionMapping().getNamespace();
        Set<String> definitions = buildDefinitionNames(namespace, actionName, resultCode);

        for (String definition : definitions) {
            LOG.debug("Looking for tiles definition: {}", definition);

            if (container.isValidDefinition(definition, request, response)) {
                return new TilesResult(definition);
            }
        }

        LOG.warn("Couldn't find tiles definition for namespace {}, action name {} and result
code {}", namespace, actionName, resultCode);
        return null;
    }

    protected Set<String> buildDefinitionNames(String namespace, String actionName,
String resultCode) {
        Set<String> definitions = new LinkedHashSet<>();

        if (namespace.startsWith("/")) {
            namespace = namespace.substring(1);
        }

        if (!Objects.equals(namespace, "") && !Objects.equals(namespace, "/")){
            if (namespace.endsWith("/")) {
                definitions.add(namespace + actionName);
                definitions.add(namespace + actionName + "-" + resultCode);
                definitions.add(namespace + resultCode);
            } else {
                definitions.add(namespace + "/" + actionName);
                definitions.add(namespace + "/" + actionName + "-" + resultCode);
                definitions.add(namespace + "/" + resultCode);
            }
        }

        definitions.add(actionName);
        definitions.add(actionName + "-" + resultCode);

        LOG.debug("Possible definition's names {}", definitions);

        return definitions;
    }

    @Override
    public Object handleUnknownActionMethod(Object action, String methodName) {
        return null;
    }
}
{code}

> Incorporate tiles3 into conventions, tutorial (and add code to tiles3 plugin)
> -----------------------------------------------------------------------------
>
>                 Key: WW-4161
>                 URL: https://issues.apache.org/jira/browse/WW-4161
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Plugin - Tiles
>            Reporter: Ken McWilliams
>             Fix For: 2.5
>
>         Attachments: struts2-tiles-annotations.patch, struts2-tiles-annotations.patch
>
>
> There is a description found here: http://stackoverflow.com/questions/11161194/freemarker-and-struts2-tags
> It would be good if the struts2 website could turn the following into a tutorial, possibly
some of the code could be included into the tile3 plugin but I'm not convinced at this time
that should be done. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message