7 Replies Latest reply on Jun 24, 2008 4:33 PM by gonzalad

    components.xml configuring a simple type component

    gonzalad

      Hello,


      I want to configure the default pageSize (type integer) for all dataTable in components.xml.


      Can I configure a simple type (type int or java.lang.Integer) in components.xml or are components just restricted to be full javabeans ?


      For the moment, I must create a javabean wrapper and configure it via :


      <component name="pageSettings" class="org.test.web.util.PageSettings" auto-create="true" scope="application">
        <property name="pageSize">10</property>
      </component>
      




      I use it in my Action class :


      @In("#{pageSettings.pageSize}")
      private int pageSize; 



      Is there a way to have something like this ?


      <component name="pageSettings" class="java.lang.Integer" auto-create="true" scope="application">
        10
      </component>
      



      Thank you !

        • 1. Re: components.xml configuring a simple type component
          wrzep
          <factory name="pageSize" value="10" scope="APPLICATION">



          btw .properties files are really handy to store properties. Then you don't have to search whole components.xml file to find a property :)


          -P

          • 2. Re: components.xml configuring a simple type component
            wrzep

            Oh, the above produced String :) To get Long, of course:


            <factory name="pageSize" value"#{10}" scope"APPLICATION" auto-create="true">




            Cheers, -Pawel

            • 3. Re: components.xml configuring a simple type component
              gonzalad

              Thanks,


              Just tested it and ran into the same Long and String troubles.


              One last question : is it possible to obtain an Integer with this solution ? [1]


              Thanks very much


              [1] I'm obtaining :


              java.lang.IllegalArgumentException: Could not set field value by reflection: RechercherInterlocuteurAction.pageSize on: com.xxx.RechercherInterlocuteurAction with value: class java.lang.Long)
              


              • 4. Re: components.xml configuring a simple type component
                wrzep

                Heh, don't know why it produces Long instead of Integer... Prolly it has something to do with EL conversions. If you happen to find the answer lemme know :D


                -Pawel

                • 5. Re: components.xml configuring a simple type component
                  gonzalad

                  Sorry Pawel, didn't found.


                  I've read an extract of JSR 52, chapter A.3.2 on literal handling (Integer litteral are handled as IntegerLiteral in section A.8 - IntegerLiteral only specifies syntax - not java type).


                  So, don't know if Integer literals are mapped to Integer or Long.


                  From another chapter of the spec, A.3.5, results of binary operation are coerced to Float, Double, String, Long but never coerced to Integer.


                  I've also tried to add an el function like :


                  <factory name="pageSize" value="#{sx:intValue(10)}" scope="APPLICATION" auto-create="true"/>
                  



                  But I don't know how to register it in order to be handled in components.xml (perhaps registering a custom application-factory in faces-config.xml but it appears to me to be overkill).


                  If anyone has an idea on the subject I'm really interested.


                  Otherwise, if I need to handle Integers literals in components.xml, I'll use a Holder object approach (as PageSettings), and if I need Long or String, I'll use the simpler approach.


                  • 6. Re: components.xml configuring a simple type component
                    stephen

                    I no longer use EL functions with Seam:
                    Simply create an application scoped seam component named for example util and use it from el:



                    value="#{util.intValue(10)}"



                    • 7. Re: components.xml configuring a simple type component
                      gonzalad
                      value="#{util.intValue(10)}"



                      Oups !
                      This is a simple and good solution thanks Stephen !