12 Replies Latest reply on Dec 30, 2005 1:28 PM by Carolina U.

    Very very Newbie question about datamodel

    Carolina U. Newbie

      Hi guys!

      I 'm just starting to learn how to develop using jboss seams & facelets ejb3
      and i ran into some problems, so im posting here if somebody can help this little girl

      If I have a list of objects "CaroTypeGroup" as I describe here, (this is when u check the object with the eclipse inspector)

      - groups=ArrayList
      - elementData=Object[10]
      - CAROTypeGroup
      + code="NAME001"
      + subTypes=PersistenceSet(id 602)
      + description="description 1"
      + id="id001"

      - CAROTypeGroup
      + code="NAME002"
      + subTypes=PersistenceSet(id 603)
      + description="description 2"
      + id="id002"
      ... etc


      Well this is my ejb Bean

      @Stateful
      @Name("caroGroups")
      @Scope(ScopeType.CONVERSATION)
      @Interceptor(SeamInterceptor.class)
      public class CaroTypeGroupListAction implements Serializable,
       CaroTypeGroupList {
      
       @PersistenceContext
       private Session session;
      
       @DataModel
       private List<CaroTypeGroup> groups;
      
       @DataModelSelectionIndex
       private int groupsIndex;
      
       @DataModelSelection
       private CaroTypeGroup selectedGroup;
      
       @Out(required = false)
       private CaroTypeGroup group;
      
       public String findCaroGroups() {
       groups = session.createCriteria(CaroTypeGroup.class).list();
       return "success";
       }
      
       @Begin
       public String setCaroGroup() {
       group = selectedGroup;
       return "success";
       }
      


      ----
      As a Starting point, I just want to print that list (groups) to a page with a data table that contains the following code:

      <h:dataTable value="#{groups}" var="g">
      
       <h:column>
       <f:facet name="header">Code</f:facet>
       #{g.code}
       </h:column>
      
       <h:column>
       <f:facet name="header">Actions</f:facet>
       <h:commandButton value="See" action="#{caroGroups.setCaroGroup}" />
       </h:column>
      
      </h:dataTable>
      



      The problem is that it doesn't print anything, like the atribute code is empty, so I dunno if im using seam datamodel in the correct way or... what could be my problem here? what am i doing wrong?..
      Thanks

        • 1. Re: Very very Newbie question about datamodel
          js8523 Novice

          Try using

          <h:outputText value="#{g.code}" />
          instead, i've had a strange problem with trying to directly use
          #{g.code}
          before.

          James




          • 2. Re: Very very Newbie question about datamodel
            Gavin King Master

            Right, you cannot use #{foo} in a JSP page. You have to use <h:outputText/>.


            The examples which show a naked #{foo} only work in facelets.

            One of the many reasons why JSP is bad and should be deprecated :)


            But the original poster says she is using facelets, so this is not the problem, I guess.

            • 3. Re: Very very Newbie question about datamodel
              Gavin King Master

              By the way, the code looks basically correct.

              It might be a good idea to try with the current CVS version of Seam.

              • 4. Re: Very very Newbie question about datamodel
                Eric Fennell Newbie

                Shinerella, I did a good amount of debugging like this on my own app... trying to figure out why things don't work.

                Is it that your table is being rendered but the data fields don't show up, or is your table not rendered at all?

                One thing I did in debugging is to put a lot of log.info statements in some critical areas... maybe put one after your "groups=session.createCriteria..." that says:

                log.info(groups.size() + " groups returned by criteria query.");

                (You'd have to define the logger, of course, but the example app shows this I believe.)

                That'll at least tell you whether you actually have groups in your list...

                • 5. Re: Very very Newbie question about datamodel
                  Carolina U. Newbie

                  ok, this is the thing gavin.King, SORRY i wrote jsp because I was very used to it, but im using facelets now, should have wrote xhtml page instead.

                  Indeed, today Im trying the new version of seams and the error log is :

                  12:42:21,984 WARN [VariableResolverImpl] Variable 'caroGroups' could not be resolved.
                  12:42:22,265 WARN [VariableResolverImpl] Variable 'groups' could not be resolved.

                  thank u both for your answers!! I already tried the <h:outputText> tag, but I did not have the expected results yet, im trying other things out, if i find my error I will post it back :)

                  • 6. Re: Very very Newbie question about datamodel
                    Carolina U. Newbie

                    Marobashi

                    * Into my groups this is what I have in running Time:
                    (setting a breakpoint on the following return statement and inspecting what "groups" contents after the session.createCriteria)

                    groups = ArrayList
                    - elementData=Object[10]
                    - CAROTypeGroup
                    + code="NAME001"
                    + subTypes=PersistenceSet(id 602)
                    + description="description 1"
                    + id="id001"

                    - CAROTypeGroup
                    + code="NAME002"
                    + subTypes=PersistenceSet(id 603)
                    + description="description 2"
                    + id="id002"
                    ... etc

                    So As u can see... I have a list of caroTypegroup, and those objects have atributtes like "code", "description", etc...

                    What I think is may be that somehow the variables are no longer in Scope so that's why them cannot be resolved... but why?

                    I already changed the "Begin" of the conversation to the Method findCaroGroups() where I set the value to groups ... but anyway... not good results yet

                    • 7. Re: Very very Newbie question about datamodel
                      Carolina U. Newbie

                      And finally my problem solution is:

                      The@Factory anotation is needed, this is not found in the old doc, i guess..

                      @Begin
                       @Factory("groups")
                       public String findCaroGroups() {
                       groups = session.createCriteria(caroTypeGroup.class).list();
                       return "success";
                       }


                      thanks ivan :)



                      • 8. Re: Very very Newbie question about datamodel
                        Eric Fennell Newbie

                        Shinerella, what are you seeing as output?

                        1) Table headings and empty boxes where the data should be.
                        2) Table headings but no rows
                        3) No table at all

                        If 3, do you have any other output on the page, and are you seeing that? (Like a <h1>Here are your CAROGroups:</h1> before the dataTable snippet you sent...)

                        Also, the example HotelBookingAction doesn't use @DataModelSelection... just @DataModel and @DataModelSelectionIndex. I attempted to duplicate what you're doing in a working application that I have, by adding a @DataModelSelection tag and associated object. My table showed up ok, but when I attempted to click any of my subsequent conversation methods (or even cancel, to end the conversation) I received an error.

                        This very well could be due to my own stupidity somewhere in my code, but when I removed @DataModelSelection and the defined object, my application started working again.

                        Again, this doesn't seem to explain why your data isn't showing up... but I'd be curious to see what happens if you remove that DataModelSelection tag.

                        You'd have to change your setCaroGroup to:

                         public String setCaroGroup() {
                         group = groups.get(groupsIndex);
                         return "success";
                         }
                        


                        • 9. Re: Very very Newbie question about datamodel
                          Eric Fennell Newbie

                          Why is the factory annotation required on the DataModel here but not when filling the hotels DataModel in the booking example? Is it because of a difference in the application deployment context, how the find() method is initially invoked, or something else?

                          ... batting 1000 today... if these problems were pinatas, I'd be going home with no candy.

                          Any feedback would be welcome.

                          Thanks,
                          Eric

                          • 10. Re: Very very Newbie question about datamodel
                            Gavin King Master

                            @DataModelSelection is working perfectly for me in the demo apps in CVS. It may not have been working in the 1.0 beta 1 release.

                            See, for example, BookingListAction in the booking demo.

                            The reason why @Factory is sometimes needed, and sometimes not is that.

                            (1) Sometimes we are processing a faces postback (ie a action listener invocation), so the action listener prepares the data in the DataModel.

                            (2) Sometimes we are processing non-faces HTTP GET request, and so no action listener has been invoked and we need to prepare the data during the RENDER_RESPONSE phase.


                            In case (1), all you need is an action listener marked @Begin. In case (2) you need an @Factory @Begin method.

                            Hope that is clear.

                            • 11. Re: Very very Newbie question about datamodel
                              Eric Fennell Newbie

                              Thank you very much for the response. I appreciate your willingness to take time out to help a struggling newb along.