2 Replies Latest reply on Apr 23, 2010 12:31 PM by stani0

    Component.getInstance(String) for non-component (non-Seam component) value

    stani0

      The API documentation [1] lacks a formal contract and I haven't been able to find out elsewhere whether using org.jboss.seam.Component.getInstance("varName") is valid to lookup a non-Seam component value, e.g. there's a factory method defined as:


          @Factory("dataList")
          public List<String> initDataList() {
              List<String> dataList;
              // Initialize the list.
              return dataList;
          }



      Then somewhere else one invokes:


          List<String> dataList = (List<String>) Component.getInstance("dataList");



      Is the given usage o.k.?


      [1] http://docs.jboss.org/seam/2.0.2.SP1/api/org/jboss/seam/Component.html#getInstance(java.lang.String)

        • 1. Re: Component.getInstance(String) for non-component (non-Seam component) value
          stani0

          Just to clarify, I've tried and observed in the Seam sources the above usage works o.k.  I'm asking whether it is intended to work o.k. or is some major flaw in the usage which is not guaranteed to work in future versions?

          • 2. Re: Component.getInstance(String) for non-component (non-Seam component) value
            stani0

            The question could be stated also this way.  Could one just use Component.getInstance("varName") for values which are not Seam components, or one should do it more verbose and manually like:


                Object val = Contexts.lookupInStatefulContexts("varName");
                if (val == null) {
                    val = Component.getInstanceFromFactory("varName");
                }



            Then one could still argue because getInstanceFromFactory() is method of the Component class it should not be invoked for non-component values.