3 Replies Latest reply on May 29, 2007 5:13 PM by gavin.king

    evaluting s:hasPermission once only in a page

      i have a page with quite a few :

      <ice:inputText id="enterpriseName"
      value="#{enterpriseTreeManager.enterprise.name}" size="50"
      required="true"
      disabled="${!s:hasPermission('enterprise', 'edit', null}">

      i am using the RuleBasedIdentity, so I also have a security.drl file with all the premissions. my problem is that the Identity.hasPermission() method get called for each s:hasPermission. is there a way to store the result of s:hasPermission in a page scoped variable and then use that instead of s:hasPermission?

      i tried the following but it still calls Identity.hasPermission multiple times:
      <c:set var="editPermission" scope="page" value="${s:hasPermission('enterprise', 'edit', null)}"/>
      and then
      <ice:inputText id="enterpriseName"
      value="#{enterpriseTreeManager.enterprise.name}" size="50"
      required="true"
      disabled="${!editPermission}">


      thanks in advance

        • 1. Re: evaluting s:hasPermission once only in a page
          gavin.king

          I guess this is generally useful:

          @Name("cachedValue")
          @Install(false)
          public class CachedValue {
          
           private ValueBinding value; //Use ValueExpression in Seam 1.3
           private Object cachedValue;
          
           public void setValue(ValueBinding value) { this.value = value; }
          
           public ValueBinding getValue() { return value; }
          
           @Unwrap public Object get() {
           if (cachedValue==null) {
           cachedValue = getValue().getValue();
           }
           return cachedValue;
           }
          
          }


          Declare a cached value like this:

          <component name="hasPermission" class="CachedValue" scope="session">
           <property name="value">#{s:hasPermission('enterprise', 'edit', null)}</property>
          </component>


          (You can similarly declare any other cached values, and their scopes.)

          And use it like #{hasPermission}.

          • 2. Re: evaluting s:hasPermission once only in a page
            gavin.king

            Note that the class ValueBinding is a org.jboss.seam.core.Expressions.ValueBinding, not the JSF class.

            • 3. Re: evaluting s:hasPermission once only in a page
              gavin.king

              Of course, it would be easy to simplify the config to:

              <n:cachedValue scope="session" value="#{s:hasPermission('enterprise', 'edit', null)}"/>


              just by using @Namespace.