6 Replies Latest reply on Jan 23, 2008 5:35 PM by Alexander Seitz

    Select item from table and convertEntity

    Alexander Seitz Newbie

      Hi,

      I have a use case to implement which could normally done with a <h:selectOneMenu> and <s:convertEntity />.
      Imagine you have a project editing page where I can set the manager of a project. Normally this could be done with a drop-down list like:

      <h:selectOneMenu value="#{project.manager}">
       <s:convertEntity />
       <s:selectItems value="#{allPersons.resultList}"
       var="person"
       label="#{person.name}"/>
      </h:selectOneMenu>


      So the <s:converEntity/> will automatically converts the selected person and set it to my project (project hast a setManager(Person p) method).

      But what if the data-list (here: allPersons.resultList) is too big to show it in the drop-down list? Let's say the list has 100000 entries.. In this case a popup should appear where I can search for persons, see the results in a table where I can select one to set for the project.
      How could I accomplish that? Is there a way to use the <s:convertEntity> here or would I need to grab the id of the selected person manually and set it to the entity before saving it?

      I think this is a common use case in real-world applications, so maybe one of you can give me a hint on how to implement it with Seam/JSF possibilities.

      Thanks,

      Alexander


        • 1. Re: Select item from table and convertEntity
          Nicklas Karlsson Master

          Well, you could have two separate components:

          * selectOneMenu rendered when list.count < n

          * separate modal window with datatable, paginator, search and filtering

          I think you should be able to get both options working with a list of entities in the model. Then there is the question on how you should trigger the modal window. A separate button? An empty selectOneMenu with some sort of "on open trigger"?

          • 2. Re: Select item from table and convertEntity
            Alexander Seitz Newbie

             

            "nickarls" wrote:
            Well, you could have two separate components:

            * selectOneMenu rendered when list.count < n

            * separate modal window with datatable, paginator, search and filtering

            I think you should be able to get both options working with a list of entities in the model. Then there is the question on how you should trigger the modal window. A separate button? An empty selectOneMenu with some sort of "on open trigger"?


            I would have a little icon next to the input field which will trigger the popup with the person-selection table.
            My main concern is not how to trigger the popup etc, it is how do I set the selected person directly to the entity (pass it to the project.setManager(Person p) method!

            What I tried is (this is the person-select table in the popup):


            <tr:table styleClass="trTableDiv" id="personss"
             rows="10" columnClasses="col"
             value="#{allPersons}" var="pers">
             <tr:column>
             <f:facet name="header">Name</f:facet>
             <h:outputText
             value="#{pers.vorname} #{pers.nachname}" />
             </tr:column>
             <tr:column>
             <f:facet name="header">select</f:facet>
             <a:commandLink reRender="panelProjekt" action="#{projekt.setManager(pers)}" value="set">
             <s:conversationId />
             </a:commandLink>
             </tr:column>
            </tr:table>


            The problems here are the following:
            - only the last person in the table is set to the project if I click a link. Why??
            - the project record is immediately updated in the DB after I click the link (maybe here I could use flushMode="manual"?)
            - this only works for the first click on the commandLink

            Any help would be appreciated.

            Alexander

            • 4. Re: Select item from table and convertEntity
              Alexander Seitz Newbie

              So I figured it out: The Trinidad table is the problem here. If I use the standard h:dataTable or rich:datatable it works!!

              <rich:dataTable styleClass="trTableDiv" id="personss" value="#{allePersonen}" var="pers">
               <rich:column>
               <f:facet name="header">Name</f:facet>
               <h:outputText
               value="#{pers.vorname} #{pers.nachname}" />
               </rich:column>
               <rich:column>
               <f:facet name="header">select</f:facet>
               <a:commandLink immediate="true" reRender="panelProjekt" action="#{projekt.setManager(pers)}" value="set">
               <s:conversationId />
               </a:commandLink>
               </rich:column>
              </rich:dataTable>


              So here we have another little incompatibility with Trinidad?

              But what happens when I click the set link is that the project record is immediately updated in the database. Is there a way to prevent this or do I have to set the flushMode of the conversation to manual?

              • 5. Re: Select item from table and convertEntity
                Nicklas Karlsson Master

                I think that is the expected behaviour and manual flushmode should fix that.

                • 6. Re: Select item from table and convertEntity
                  Alexander Seitz Newbie

                  Ok, thanks for your help! It works like I want it now :-)

                  But can anyone explain to me what happens behind the scene when passing the entity-object (pers in my example) directly as method parameter? Well, it works, but how?

                  Alexander