sitemesh / sitemesh3

SiteMesh 3: Official repository
https://sitemesh.github.io/sitemesh-website/
Apache License 2.0
480 stars 168 forks source link

Decorating with Parameters? #90

Closed zhang20084 closed 1 year ago

zhang20084 commented 9 years ago
http://www.easyapi.com/info/free?pjax=1

Do not use decorator What do I do

codeconsole commented 9 years ago

Parameters should not have any effect on page decorating. Are you trying to create a rule based on parameters or the file part of the url?

zhang20084 commented 9 years ago

But I can't, for example < mapping path="/ * pjax * " exclude="true" > It can't please write a example, how to make the parameter using another decorator. Thank you very much.

zhang20084 commented 8 years ago

lose hope

alexgaoyh commented 8 years ago

change web.xml file: filter part to my filter 'com.alexgaoyh.MutiModule.Dubbo.RWSeperate.consumer.web.util.sitemesh.filter.ParamConfigurableSiteMeshFilter'

`public class ParamConfigurableSiteMeshFilter extends ConfigurableSiteMeshFilter {

protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) {
    DecoratorSelector<WebAppContext> defaultDecoratorSelector = builder.getDecoratorSelector();
    builder.setCustomDecoratorSelector(new ParamDecoratorSelector(defaultDecoratorSelector));
}

}`

`public class ParamDecoratorSelector implements DecoratorSelector {

private DecoratorSelector<WebAppContext> defaultDecoratorSelector;

public ParamDecoratorSelector(DecoratorSelector<WebAppContext> defaultDecoratorSelector) {
    this.defaultDecoratorSelector = defaultDecoratorSelector;
}

@Override
public String[] selectDecoratorPaths(Content content, WebAppContext context) throws IOException {
    HttpServletRequest request = context.getRequest();
    String decorator = request.getParameter("decorator");
    if (StringUtilss.isNotBlank(decorator) && decorator.equals("true")) {
        return new String[] {};
    }
    // Otherwise, fallback to the standard configuration
    return defaultDecoratorSelector.selectDecoratorPaths(content, context);
}

}`

codeconsole commented 1 year ago

The reason in this particular case is you are using the wrong mime type. You should not be using text/html for ajax.

However, if this is still something you are interested in us addressing, we are happy to look into it.

codeconsole commented 1 year ago

This demonstrates that SiteMesh does not decorate json by default:

https://github.com/sitemesh/sitemesh3/commit/f68b087fd36928abe48bfc7595d946986c9e0917

If you want to decorate by parameters. The simplest way is to add a meta tag inside the page you wish to decorate that is dynamic based on the parameter being present.

Here is an example:

    <c:if test="${not empty param.bootstrap}">
      <meta name="decorator" content="bootstrap.jsp${not empty param.doubled?',chaining.html':''}" />
    </c:if>

If you can define a more specific need that can not be achieved with the current implementation, we are more than happy to offer a solution.