Sumit Sundriyal Sumit Sundriyal - 1 month ago 16
Java Question

How to check active and inactive status of a togglz in a jsp?

I want to check active and inactive status of a toggle in a jsp.

Answer

Here is the complete example.

1. Download togglz-jsp-x.x.x.jar and put it into the classpath of your project OR copy togglz.tld to /WEB-INF/tld directory.

2. web.xml.

    <jsp-config>
       <taglib>
            <taglib-uri>
                /togglz
            </taglib-uri>
            <taglib-location>
                /WEB-INF/tld/togglz.tld
            </taglib-location>
        </taglib>
    </jsp-config>

3. Add taglib in the jsp.

<%@ taglib prefix="togglz" uri="/togglz" %>

4. Test feature class.

public enum TestFeatures implements Feature {
  @Label("Test togglz")
  TEST_TOGGLZ;
  public boolean isActive() {
    return FeatureContext.getFeatureManager().isActive(this);
  }
}

5. test.jsp.

<togglz:feature name="TEST_TOGGLZ">
  Test Toggle enabled
</togglz:feature>
<togglz:feature name="!TEST_TOGGLZ">
  Test Toggle disabled
</togglz:feature>
Comments