Announcement Announcement Module
Collapse
No announcement yet.
Flow var of type 'int' Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Flow var of type 'int'

    I'm trying to define an int variable in my flow. Here's the var definition in my -flow.xml:
    Code:
        <var name="myInt" class="int" />
    The spring-webflow-2.0.xsd clearly states:
    Code:
    <xsd:attribute name="class" type="type" use="required">
        <xsd:annotation>
            <xsd:documentation>
                The name of this variable's implementation class.  The class name
                may be an alias (e.g 'int') or the fully-qualified class name (e.g.
                'java.lang.Integer').  The class must be a concrete class.
            </xsd:documentation>
        </xsd:annotation>
    </xsd:attribute>
    However, I'm getting this exception:
    Caused by: org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [int]: No default constructor found; nested exception is java.lang.NoSuchMethodException: int.<init>()

    What am I doing wrong?

  • #2
    Try "integer".

    Comment


    • #3
      I changed to class="integer". Now, I'm getting this exception:
      Caused by: org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [java.lang.Integer]: No default constructor found; nested exception is java.lang.NoSuchMethodException: java.lang.Integer.<init>()

      I get the same thing if I have class="java.lang.Integer".

      I'm deploying my war on Tomcat 6.0.18, if that means anything to anyone.

      Comment


      • #4
        Hmm...are you getting the same thing with other types ("string", "boolean", etc)?

        If so, have you added a custom conversion service?

        Comment


        • #5
          "string" and "java.lang.String" both work just fine. "boolean" gives me an exception just like "integer":
          Caused by: org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [java.lang.Boolean]: No default constructor found; nested exception is java.lang.NoSuchMethodException: java.lang.Boolean.<init>()

          I have NOT added a custom conversion service. My setup is very basic, following the defaults described in the Web Flow docs.

          I can post more code/config if there's something in particular that might help. But I didn't want to flood the thread with unnecessary details.

          BTW, thanks for your help!

          Comment


          • #6
            How is this working for others? I must be doing something wrong!

            I think this is failing because java.lang.Integer has no default constructor. That's why it works for java.lang.String...it has one.

            So, the question remains. How do I instantiate an integer flow variable?

            Comment


            • #7
              Ah, I see what's going on.

              I glossed past your example thinking you were trying to set a variable and make sure its type was int. Didn't realize you were trying to do this in a var element.

              You'll notice var elements instantiate a class and don't allow you to set its value. This is great for beans, but doesn't work for immutable objects requiring values like any Number subclass.

              What you want is to use the set element, probably on the start of a flow:

              Code:
              <on-start>
                <set name="flowScope.myInt" value="42" type="integer"/>
              </on-start>
              In this case, type really isn't needed, but you can use any full class name or alias (see DefaultConversionService or FacesConversionService) for the value of the type attribute.

              Comment


              • #8
                Makes perfect sense, now that you've shown it to me. I'm a little embarrassed I didn't figure that out on my own.

                Thank you!

                Comment


                • #9
                  OMG, i can't believe i was stuck with the same problem for so long!! and I know this post is like a year later, but THANX!

                  Comment

                  Working...
                  X