This tag is used to conditional include a part of a JSP page.
This tag is used as follows:
<jee:includeIf [condition="some boolean value"] | [name="beanInstanceName" property="boolean property or property returning object"] | [name="beanInstanceName" property="some property" value="true value for property"] | [role="role name"] | [resource="resource name] >Elements included if tag is ‘true’</jee:includeIf>
condition – This attribute must be a boolean expression. If it equates to true, the conditional block is included.·
name & property – If these two attributes are set on the tag then the tag evaluates the property on the specified bean. This property should return a boolean or an object. If the property returns a boolean and it’s true the conditional block is included. If the property returns an object, the conditional block is included if the property does not return null.
name & property & value – If these three attributes are set on the tag then tag evaluates the property on the specified bean. If the property’s value matches the value specified in the value attribute then the conditional block is included.
role – If this attribute is set on the tag, then the tag queries the security provider to set if the current user has the specified role. If they do then the conditional block is included. This attribute requires that the user to be logged in. The enforceLogin tag should be used before an includeIf tag with a role attribute.
resource – If this attribute is set on the tag, then the tag queries the security provider to set if the current user has access to the specified resource. If they do then the conditional block is included. This attribute requires that the user to be logged in. The enforceLogin tag should be used before an includeIf tag with a resource attribute.
The following code shows an example of using this tag:
<%@ taglib uri="jeenius" prefix="jee" %> <jsp:enforceLogin redirectUrl="not_logged_in.jsp"/> <jsp:useBean id="myBean" class="example.MyBean"/> <html> <head> <title>includeIf example</title> <head> <body> <jee:includeIf condition="<%= 1=1 %>"> <p>One equals One !</p> </jee:includeIf> <jee:includeIf name="myBean" property="booleanValue"> <p>mybean.getBooleanValue() returned true !</p> </jee:includeIf> <jee:includeIf name="myBean" property="objectValue"> <p>mybean.getObjectValue() returned non null !</p> </jee:includeIf> <jee:includeIf name="myBean" property="someValue" value="xyz"> <p>mybean.getSomeValue() returned "xyz"</p> </jee:includeIf> <jee:includeIf role="xyz"> <p>Current user has role "xyz"</p> </jee:includeIf> <jee:includeIf resource="abc"> <p>Current user has access to resource "abc"</p> </jee:includeIf> </body> </html>