3 Replies Latest reply on Jun 4, 2007 4:41 AM by mail.micke

    @DataModelSelection problem,outjects the first element in th

    mail.micke

      Hi,
      I'm learning seam at the moment and wonder what I'm doing wrong.

      Note:
      Read a previous post with the same problem where the problem was solved by switching form tomahawk datatable to standard datatable.
      I have tried with both standard datatable and richfaces one, but the problem persists.

      I'm trying to implement a simple search/select/edit/save use case with seam in order to learn how to use some of the features (annotations, scopes and pageflow).

      But in the search part of the flow, the first row is always outjected..

      And I just started with Seam yesterday, so please point out any tips you have for me :-)

      Backing bean:

      @Name("riskAddonBacking")
      @Scope( ScopeType.CONVERSATION)
      public class CountryRiskAddonBacking implements Serializable{
      
       /**
       *
       */
       private static final long serialVersionUID = 1L;
      
       @DataModel
       private List<CountryRiskAddonBean> searchResults;
      
       @DataModelSelection
       @Out(required=false)
       private CountryRiskAddonBean selectedItem;
      
       private String searchPattern;
      
       @Begin(pageflow="countryaddon")
       public void startPageFlow(){
      
       }
      
       public String performSearch(){
      
       int nbrHits = RandomUtils.nextInt()%10;
       List<CountryRiskAddonBean> tmpList = new ArrayList<CountryRiskAddonBean>(nbrHits);
       for(int i=0; i<nbrHits; i++ ){
       CountryRiskAddonBean cab = new CountryRiskAddonBean();
       cab.setTicketNumber("RSK-" + (RandomUtils.nextInt()%10000) );
       cab.setCptyName("CptyXYZ");
       cab.setCountryOfRisk("SWE");
       tmpList.add( cab );
       }
       searchResults = tmpList;
      
       return null;
       }
      
       public String save(){
       System.out.println("SAAAAAAVVVVVVIIIIIIIIINNNNNNNNGGGGGGGG to db");
      
       return "";
       }
      
       public String getSearchPattern() {
       return searchPattern;
       }
      
       public void setSearchPattern(String searchPattern) {
       this.searchPattern = searchPattern;
       }
      }
      


      search.xhtml:

      <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:t="http://myfaces.apache.org/tomahawk"
       xmlns:a4j="https://ajax4jsf.dev.java.net/ajax"
       xmlns:rich="http://richfaces.ajax4jsf.org/rich"
       xmlns:s="http://jboss.com/products/seam/taglib">
      <body>
      
      
      <ui:composition template="/WEB-INF/layout/template.xhtml">
       <ui:param name="title" value="Pageflow Start"/>
      
       <ui:define name="body">
       <h:form>
       <s:decorate>
       <h:inputText id="srchPatt" value="#{riskAddonBacking.searchPattern}" required="true"/>
       </s:decorate>
      
       <s:button action="#{riskAddonBacking.performSearch}" value="Search"/>
      
       <h:outputText value="Found #{searchResults.rowCount} hits"
       rendered="#{searchResults.rowCount > 0}"/>
       </h:form>
      
      
       <h:form rendered="#{not empty searchResults}">
       <h:dataTable value="#{searchResults}"
       var="_item">
       <h:column>
       <f:facet name="header">
       Ticket Number
       </f:facet>
       #{_item.ticketNumber}
       </h:column>
       <h:column>
       <f:facet name="header">
       Counterparty
       </f:facet>
       #{_item.cptyName}
       </h:column>
       <h:column>
       <f:facet name="header">
       Country of Risk
       </f:facet>
       #{_item.countryOfRisk}
       </h:column>
       <h:column>
       <f:facet name="header">
       Risk Addon
       </f:facet>
       #{_item.riskAddon}
       </h:column>
       <h:column>
       <f:facet name="header">
       Add/Edit
       </f:facet>
      
       <s:link action="edit" value="Edit" rendered="#{_item.riskAddon > 0}" />
       <s:link action="edit" value="Add" rendered="#{_item.riskAddon == 0}"/>
       </h:column>
       </h:dataTable>
       <!--
       <rich:dataTable value="#{searchResults}"
       var="_item">
       <rich:column>
       <f:facet name="header">
       Ticket Number
       </f:facet>
       #{_item.ticketNumber}
       </rich:column>
       <rich:column>
       <f:facet name="header">
       Counterparty
       </f:facet>
       #{_item.cptyName}
       </rich:column>
       <rich:column>
       <f:facet name="header">
       Country of Risk
       </f:facet>
       #{_item.countryOfRisk}
       </rich:column>
       <rich:column>
       <f:facet name="header">
       Risk Addon
       </f:facet>
       #{_item.riskAddon}
       </rich:column>
       <rich:column>
       <f:facet name="header">
       Add/Edit
       </f:facet>
      
       <s:link action="edit" value="Edit" rendered="#{_item.riskAddon > 0}" />
       <s:link action="edit" value="Add" rendered="#{_item.riskAddon == 0}"/>
       </rich:column>
       </rich:dataTable>
       -->
       </h:form>
      
       </ui:define>
      </ui:composition>
      
      </body>
      </html>
      


      countryaddon.jpdl.xml :

      <pageflow-definition
       xmlns="http://jboss.com/products/seam/pageflow"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation=
       "http://jboss.com/products/seam/pageflow http://jboss.com/products/seam/pageflow-1.2.xsd"
       name="countryaddon">
      
       <start-state name="start">
       <transition to="searchPage"/>
       </start-state>
      
       <page view-id="/countryaddon/search.xhtml" name="searchPage">
       <redirect/>
       <transition name="edit" to="editPage"/>
       </page>
      
       <page view-id="/countryaddon/edit.xhtml" name="editPage">
       <redirect/>
       <transition name="approve" to="approvePage"/>
       </page>
      
       <page view-id="/countryaddon/approve.xhtml" name="approvePage">
       <redirect/>
       <transition name="save" to="endPage">
       <action expression="#{riskAddonBacking.save}"/>
       </transition>
       <transition name="prev" to="editPage"/>
       </page>
      
       <page view-id="/countryaddon/end.xhtml" name="endPage">
       <redirect/>
       <end-conversation/>
       </page>
      
      </pageflow-definition>
      


      And OT, I get annoying error messages related to there not being a transaction, from the ExceptionFilter. Is there a cure for this, read a post about this problem but it didn't have a solution of how to get rid of it.

      Cheers,
      Mike

        • 1. Re: @DataModelSelection problem,outjects the first element i
          mail.micke

          Hi again,

          when looking at post [1] which seems to have had my problem the main difference I find is that the @Factory annotation is used to initialize the List backing the datamodel.

          In my test app I initialize the List backing the datamodel via the performSearch action(which rerenders the page with the table to select from), could that be why @DataModelSelection doesn't work properly for me?

          [1] http://www.jboss.com/index.html?module=bb&op=viewtopic&t=108196

          Any help/suggestions appreciated,
          Mike

          • 2. Re: @DataModelSelection problem,outjects the first element i
            rkosiarz82

            I think you should put

            @Factory("searchResults")
            public String performSearch(){

            int nbrHits = RandomUtils.nextInt()%10;
            List tmpList = new ArrayList(nbrHits);
            for(int i=0; i<nbrHits; i++ ){
            CountryRiskAddonBean cab = new CountryRiskAddonBean();
            cab.setTicketNumber("RSK-" + (RandomUtils.nextInt()%10000) );
            cab.setCptyName("CptyXYZ");
            cab.setCountryOfRisk("SWE");
            tmpList.add( cab );
            }
            searchResults = tmpList;

            return null;
            }


            • 3. Re: @DataModelSelection problem,outjects the first element i
              mail.micke

              Hi,
              asked this question again [1] with a little more details, and got it sort of working.

              Turned out that I had to invoke an action method for the selected value to get outjected properly, as suggested in the other post I just call an empty action mehtod.

              Not sure that I'm doing everything correctly, because I was hoping to use navigation strings defined in my page flow to handle navigation and not have to execute any serverside action methods.

              And the reason I didn't use a Factory annotation is that I need to populate the list based on a search string, and be able to repopulate that search result for a new search.

              [1] http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4050835

              Thanks,
              Mike