2 Replies Latest reply on Jan 20, 2009 7:51 PM by clerum

    Using Seam to Access Web Services

    clerum

      Hopefully someone can point me in the right direction here. I'm trying to intergrate some access to salesforce.com into my seam application. I have generated my web services objects with their WSDL file and can pull data from salesforce and work with it within the seam framework.


      The next step is to start setting data.


      There is a salesforce object called Lead and I have an instance of it called newLead.


      When the

      add_lead.xhtml

      gets loaded I'm getting the following error. What is the correct way to access this so that a Lead object gets created when this page is loaded and it will be accessible from the addLead method in SFLeadAction.


      javax.el.PropertyNotFoundException: /partner/lead_add.xhtml @24,111 value="#{sfleadutil.newLead.company}": Property 'newLead' not found on type org.javassist.tmp.java.lang.Object_$$_javassist_2




      package net.demo.polaris.salesforce;
      
      import java.util.ArrayList;
      import java.util.Collection;
      
      import javax.ejb.Stateless;
      
      import net.demo.polaris.User;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Factory;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.datamodel.DataModel;
      
      import com.sforce.soap.enterprise.QueryResult;
      import com.sforce.soap.enterprise.sobject.Lead;
      
      @Stateless
      @Name("sfleadutil")
      public class SFLeadAction implements SFLeadUtil {
           
           @In(create=true, required=true)
           @Out(scope=ScopeType.SESSION)
           private SFConnection sfc;
           
           @In
           User authuser;
           
           @In(required=false)
           Lead newLead;
           
           @DataModel
           private Collection <Lead> leadList = new ArrayList<Lead>();
           
           @Factory("leadList")
           public void listLeads()
           {     
                
                System.out.println("Got to list Leads");
                QueryResult qr = null;
                String query = "Select l.Account_Manager__c, l.City, l.Company, l.CreatedDate, l.Id, l.IsUnreadByOwner, l.LastName, l.Lead_Code__c, l.Name, l.State, l.Status from Lead l where PartnerID__c = '" + authuser.getOrganization().getSfcode() + "' and isConverted = false";
              qr = sfc.runQuery(query);       
                leadList.clear();
              if (qr.getSize() != 0) 
              {
                   System.out.println("Got " + qr.getSize() + " Opportunities");
                   for(int x=0; x<qr.getSize(); x++)
                   {
                        Lead ld = (Lead) qr.getRecords(x);
                       leadList.add(ld);
                   }
              }
           }
           
           public String addLead()
           {
                System.out.println("Got New Lead for " + newLead.getCompany());
                return "/partner/lead_list_org.xhtml";
           }     
      }
      



      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          xmlns:s="http://jboss.com/products/seam/taglib"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:rich="http://richfaces.org/rich"
          template="/layout/template.xhtml">
      
         <ui:define name="body"> 
          
          <h:messages globalOnly="true" styleClass="message"/> 
          
          <h:form id="newLeadForm"> 
       
              <rich:panel>  
                  <f:facet name="header">New Lead</f:facet>
                  <table>
                        <tr> 
                             <td>
                                 <s:decorate id="leadnameDecoration" template="/layout/edit.xhtml"> 
                                     <ui:define name="label">Company Name</ui:define> 
                                     <h:inputText tabindex="1" id="name" required="true" value="#{sfleadutil.newLead.company}"/>  
                                 </s:decorate>
                            </td>
                       </tr>
                       <tr>
                            <td> 
                                 <s:decorate id="leadStreetDecoration" template="/layout/edit.xhtml"> 
                                      <ui:define name="label">Primary Address</ui:define> 
                                     <h:inputText tabindex="2" id="street" required="true" value="#{sfleadutil.newLead.street}"/>
                              </s:decorate>
                          </td>
                      </tr>
                      <tr>
                            <td> 
                                 <s:decorate id="leadCityDecoration" template="/layout/edit.xhtml"> 
                                      <ui:define name="label">City</ui:define> 
                                     <h:inputText tabindex="3" id="city" required="true" value="#{sfleadutil.newLead.city}"/>
                              </s:decorate>
                              <s:decorate id="leadStateDecoration" template="/layout/edit.xhtml"> 
                                      <ui:define name="label">State</ui:define> 
                                     <h:inputText tabindex="4" maxlength="2" id="state" required="true" value="#{sfleadutil.newLead.state}"/>
                              </s:decorate>
                              <s:decorate id="leadZipDecoration" template="/layout/edit.xhtml"> 
                                      <ui:define name="label">ZIP</ui:define> 
                                     <h:inputText tabindex="5" maxlength="5" id="zip" required="true" value="#{sfleadutil.newLead.postalCode}"/>
                              </s:decorate>
                          </td>
                      </tr>
                      <tr>
                            <td> 
                                 <s:decorate id="leadNameDecoration" template="/layout/edit.xhtml"> 
                                      <ui:define name="label">Contact First,Last</ui:define> 
                                     <h:inputText tabindex="6" id="first" required="true" value="#{sfleadutil.newLead.firstName}"/>
                                     <h:inputText tabindex="7" id="last" required="true" value="#{sfleadutil.newLead.lastName}"/>
                              </s:decorate>                        
                          </td>
                      </tr>                        
                 <div style="clear:both"/>
               </table>   
                   
              </rich:panel> 
       
                <div class="actionButtons">
                  <h:commandButton id="create" 
                                value="Create Lead" 
                               action="#{sfleadutil.addLead}"/>
                   </div>
              
          </h:form> 
          
      </ui:define> 
       
      </ui:composition>
      




        • 1. Re: Using Seam to Access Web Services
          clerum

          Do I need to define these components in the components.xml since I can't annotate them with an @Name?


          Anyone have an example of what that would look like?

          • 2. Re: Using Seam to Access Web Services
            clerum

            Got this working by defining the lead object in the components.xml and then just referencing it. Is this the correct best practices way of doing this, or is there something better?


            <component name="lead" 
                      class="com.sforce.soap.enterprise.sobject.Lead" scope="event" />    
            </components>



            <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:s="http://jboss.com/products/seam/taglib"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:rich="http://richfaces.org/rich"
                template="/layout/template.xhtml">
            
               <ui:define name="body"> 
                
                <h:messages globalOnly="true" styleClass="message"/> 
                
                <h:form id="newLeadForm"> 
             
                    <rich:panel>  
                        <f:facet name="header">New Lead</f:facet>
                        <table>
                              <tr> 
                                   <td>
                                       <s:decorate id="leadnameDecoration" template="/layout/edit.xhtml"> 
                                           <ui:define name="label">Company Name</ui:define> 
                                           <h:inputText tabindex="1" id="name" required="true" value="#{lead.company}"/>  
                                       </s:decorate>
                                  </td>
                             </tr>
                             <tr>
                                  <td> 
                                       <s:decorate id="leadStreetDecoration" template="/layout/edit.xhtml"> 
                                            <ui:define name="label">Primary Address</ui:define> 
                                           <h:inputText tabindex="2" id="street" required="true" value="#{lead.street}"/>
                                    </s:decorate>
                                </td>
                            </tr>
                            <tr>
                                  <td> 
                                       <s:decorate id="leadCityDecoration" template="/layout/edit.xhtml"> 
                                            <ui:define name="label">City</ui:define> 
                                           <h:inputText tabindex="3" id="city" required="true" value="#{lead.city}"/>
                                    </s:decorate>
                                    <s:decorate id="leadStateDecoration" template="/layout/edit.xhtml"> 
                                            <ui:define name="label">State</ui:define> 
                                           <h:inputText tabindex="4" maxlength="2" id="state" required="true" value="#{lead.state}"/>
                                    </s:decorate>
                                    <s:decorate id="leadZipDecoration" template="/layout/edit.xhtml"> 
                                            <ui:define name="label">ZIP</ui:define> 
                                           <h:inputText tabindex="5" maxlength="5" id="zip" required="true" value="#{lead.postalCode}"/>
                                    </s:decorate>
                                </td>
                            </tr>
                            <tr>
                                  <td> 
                                       <s:decorate id="leadNameDecoration" template="/layout/edit.xhtml"> 
                                            <ui:define name="label">Contact First,Last</ui:define> 
                                           <h:inputText tabindex="6" id="first" required="true" value="#{lead.firstName}"/>
                                           <h:inputText tabindex="7" id="last" required="true" value="#{lead.lastName}"/>
                                    </s:decorate>                        
                                </td>
                            </tr>                        
                       <div style="clear:both"/>
                     </table>   
                         
                    </rich:panel> 
             
                      <div class="actionButtons">
                        <h:commandButton id="create" 
                                      value="Create Lead" 
                                     action="#{sfleadutil.addLead}"/>
                         </div>
                    
                </h:form> 
                
            </ui:define> 
             
            </ui:composition>
            



            package net.clearfly.polaris.salesforce;
            
            import java.util.ArrayList;
            import java.util.Collection;
            
            import javax.ejb.Stateless;
            
            import net.clearfly.polaris.User;
            
            import org.jboss.seam.ScopeType;
            import org.jboss.seam.annotations.Factory;
            import org.jboss.seam.annotations.In;
            import org.jboss.seam.annotations.Name;
            import org.jboss.seam.annotations.Out;
            import org.jboss.seam.annotations.datamodel.DataModel;
            
            import com.sforce.soap.enterprise.QueryResult;
            import com.sforce.soap.enterprise.sobject.Lead;
            
            @Stateless
            @Name("sfleadutil")
            public class SFLeadAction implements SFLeadUtil {
                 
                 @In(create=true, required=true)
                 @Out(scope=ScopeType.SESSION)
                 private SFConnection sfc;
                 
                 @In
                 User authuser;
                 
                 @In(required=false)
                 Lead lead;
                 
                 @DataModel
                 private Collection <Lead> leadList = new ArrayList<Lead>();
                 
                 @Factory("leadList")
                 public void listLeads()
                 {     
                      
                      System.out.println("Got to list Leads");
                      QueryResult qr = null;
                      String query = "Select l.Account_Manager__c, l.City, l.Company, l.CreatedDate, l.Id, l.IsUnreadByOwner, l.LastName, l.Lead_Code__c, l.Name, l.State, l.Status from Lead l where PartnerID__c = '" + authuser.getOrganization().getSfcode() + "' and isConverted = false";
                    qr = sfc.runQuery(query);       
                      leadList.clear();
                    if (qr.getSize() != 0) 
                    {
                         System.out.println("Got " + qr.getSize() + " Opportunities");
                         for(int x=0; x<qr.getSize(); x++)
                         {
                              Lead ld = (Lead) qr.getRecords(x);
                             leadList.add(ld);
                         }
                    }
                 }
                 
                 public String addLead()
                 {
                      System.out.println("Got New Lead for " + lead.getCompany());
                      return "/partner/lead_list_org.xhtml";
                 }
            }