0 Replies Latest reply on Jul 26, 2010 8:24 AM by Sascha Hoffmann

    Problem with Ajax

    Sascha Hoffmann Newbie

      Hello all


      I'm relative new in Seam and have a problem with my web application.


      The situation:
      With the help of the following website (http://docs.jboss.com/seam/latest/reference/en-US/html/remoting.html ) and my book Jboss Seam
      I tried to add ajax in my application, but nothings happend. I have absolut no idea where the mistake is. I hope anybody here can help me.
      I'd like to call a function in my stateful-bean if a file d lost the focus......thats all.



      Here ist my web.xml:




      <?xml version="1.0" encoding="UTF-8"?>
      <web-app version="2.4" 
              xmlns="http://java.sun.com/xml/ns/j2ee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
      
      
                
          <context-param>
            <param-name>javax.faces.CONFIG_FILES</param-name>
            <param-value>/WEB-INF/navigation.xml</param-value>
          </context-param>
        
          <!-- Seam -->    
          <listener>
              <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
          </listener>
      
          <servlet>
        <servlet-name>Seam Resource Servlet</servlet-name>
        <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
      </servlet>
      
      <servlet-mapping>
        <servlet-name>Seam Resource Servlet</servlet-name>
        <url-pattern>/seam/resource/*</url-pattern>
      </servlet-mapping>
      
          <filter>
              <filter-name>Seam Filter</filter-name>
              <filter-class>org.jboss.seam.web.SeamFilter</filter-class>
          </filter>
      
          <filter-mapping>
              <filter-name>Seam Filter</filter-name>
              <url-pattern>/*</url-pattern>
          </filter-mapping>
          
          <!-- MyFaces -->
          <!--
          <listener>
              <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
          </listener>
          -->    
      
          <context-param>
              <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
              <param-value>client</param-value>
          </context-param>
          
          <context-param>
              <param-name>facelets.DEVELOPMENT</param-name>
              <param-value>true</param-value>
          </context-param>
      
          <context-param>
              <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
              <param-value>.xhtml</param-value>
          </context-param>
      
          <servlet>
              <servlet-name>Faces Servlet</servlet-name>
              <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
              <load-on-startup>1</load-on-startup>
          </servlet>
      
          <!-- Faces Servlet Mapping -->
          <servlet-mapping>
              <servlet-name>Faces Servlet</servlet-name>
              <url-pattern>*.seam</url-pattern>
          </servlet-mapping>
              
      </web-app>





      Here ist a part of my client:


      <!DOCTYPE html PUBLIC 
              "-//W3C//DTD XHTML 1.0 Transitional//EN" 
              "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <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:s="http://jboss.com/products/seam/taglib">
      
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
      <link type="text/css" rel="stylesheet" href="../style.css" />
      <title>Axel Springer Deutschland - Dialogpflege</title>
      </head>
      <body>
      <script type="text/javascript" 
        src="seam/resource/remoting/resource/remote.js">
      </script>
      
      <script type="text/javascript"
                src="seam/resource/remoting/interface.js?suchhdl">
      </script>
      
      <script language="javascript">
      //<![CDATA[
              //Seam.Remoting.setDebug(true);
      
              /*Seam.Remoting.displayLoadingMessage = function() {};
              Seam.Remoting.hideLoadingMessage = function() {};*/
              
              //Denasynchronen Aufruf mit einem Callback-Handler ausführen
              function nameAufbereiten()      {
                      //Meine Seam Komponente abrufen
                      var suchhdl = Seam.Component.getInstance("suchhdl");
                      suchhdl.nameAufbereiten(NameCallback);
              }
      
              function NameCallback(result)   {
                      alert(result);
              }
      
              // ]]>
      </script>
      <h:form id="anzeigen">
      <table width="937" height="303" border="0">
        <tr>
          <td height="94" colspan="2" class="Stil1" valign="top">
                <fieldset>
                <legend class="Stil1">Sperr-Informationen</legend>
                  <table width="100%">
                        <tr>              
                          <td width="16%">Personen-Sperre:</td>
                      <td colspan="2"><h:selectOneMenu id="psperre" value="#{suchhdl.person.personenSperre}" style="height : 20px; width : 150px;"
                              valueChangeListener="#{suchhdl.strtextChanged}">
                                      <f:selectItems value="#{suchhdl.psperreList}"/> 
                              </h:selectOneMenu>
                              </td>               
                              <td width="13%" style=" width : 85px;">Pers.- Sperrdatum</td>
                      <td><h:inputText id="psperrdat" value="#{suchhdl.person.sperrdatum}" size="18"/>
                      </td>
                              <td width="15%" valign="top">Pers.-Sperr.- Letzter Bediener</td>
                      <td width="18%" colspan="2"><h:inputText value="#{suchhdl.person.sperreLetzterBediener}" size="18" disabled="true"/>
                              </td>
                        </tr>
                        <tr>
                          <td valign="top">Adressen-Sperre:</td>
                      <td colspan="2"><h:selectOneMenu value="#{suchhdl.person.adressenSperre}" style="height : 20px; width : 150px;"
                                                                      valueChangeListener="#{suchhdl.strtextChanged}" disabled="true">
                                                              <f:selectItems value="#{suchhdl.asperreList}"/> 
                              </h:selectOneMenu>
                              </td>
                              <td>
                                  <h:inputHidden id="auswahlFlag" value="#{suchhdl.auswahlFlag}" />
                              </td>     
                        </tr>
                </table>
                </fieldset>     </td>
          <td width="17%" rowspan="2" valign="top">
            <fieldset style="width: 140px">
            <legend><span class="Stil1">Dialoge</span></legend>
              <table width="100%" border="0">
                <tr>
                <td align="center"><h:commandButton id="suchen" action="#{suchhdl.update()}" value="Person suchen" 
                                                              styleClass="usrFormBtnSuchen"/>
                      <br/><h:commandButton id="auswahl" action="#{suchhdl.auswahl()}" value="Person-Auswahl" 
                                                              styleClass="usrFormBtnSuchen"/>
                     <br/>
                     <h:commandButton id="delete" action="#{suchhdl.delete()}" value="Person löschen" 
                                                              styleClass="usrFormBtnSuchen"/>
                     <br/>
                     <h:commandButton id="abbruch" action="#{suchhdl.reset()}" value="Abbruch" 
                                                              styleClass="usrFormBtnSuchen"/>
                     <br/>
                     <h:commandButton id="logout" action="#{identity.logout}" value="Logout" 
                                                              styleClass="usrFormBtnSuchen"/>
                </td>
                </tr> 
              </table>
            </fieldset>    </td>
        </tr>
        <tr>
          <td width="50%" rowspan="2" valign="top">
                <fieldset>
                <legend class="Stil1">Namen und Anrede-Informationen</legend>
                <table width="100%" border="0">
                      <tr>
                        <td width="35%" class="Stil1">Anrede:</td>
                        <td width="65%"><h:selectOneMenu id="anrede" value="#{suchhdl.person.anredeschluessel}" style="height : 20px; width : 150px;"
                              valueChangeListener="#{suchhdl.strtextChanged}">
                                      <f:selectItems value="#{suchhdl.anredeList}"/> 
                              </h:selectOneMenu>
                        </td>
                      </tr>
                      <tr>
                        <td class="Stil1">Name1:</td>
                        <td><h:inputText id="name1" value="#{suchhdl.person.name1}" size="40"/>
                              </td>
                      </tr>
                      <tr>
                        <td class="Stil1">Name2:</td>
                        <td><h:inputText id="name2" value="#{suchhdl.person.name2}" size="40"/>
                              </td>
                      </tr>
                      <tr>
                        <td class="Stil1">Name3:</td>
                        <td><h:inputText id="name3" value="#{suchhdl.person.name3}" size="40"/>
                              </td>
                      </tr>
                      <tr>
                        <td class="Stil1" valign="top">Name:</td>
                        <td><h:inputTextarea id="name" cols="40" rows="3" value="#{suchhdl.nameVoll}"  
                                                              onblur="doHwname();" style=" width : 263px;" styleClass="Stil1"/>
                              </td>
                      </tr>
                      <tr>
                        <td class="Stil1">Titel </td>
                        <td><h:inputText id="titel" value="#{suchhdl.person.titel}" size="40" onblur="javascript:nameAufbereiten()"/>
                              </td>
                      </tr>
                      <tr>
                        <td class="Stil1">Vorname:</td>
                        <td><h:inputText id="vname" value="#{suchhdl.person.vorname}" size="40" onblur="nameAufbereiten();"/>
                              </td>
                      </tr>
      ...........









      and last but not least my java-bean and the interface of the bean:



      package src.ejb;
      
      import hwname_pd.ejb.HWname_PDBean;
      import java.util.ArrayList;
      import java.util.Iterator;
      import java.util.List;
      import javax.ejb.*;
      import javax.faces.event.ValueChangeEvent;
      import javax.faces.model.SelectItem;
      import javax.persistence.*;
      import org.jboss.annotation.ejb.cache.Cache;
      import org.jboss.seam.annotations.*; 
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.annotations.datamodel.DataModelSelection;
      import org.jboss.seam.core.FacesMessages;
      import org.jboss.seam.security.Identity;
      import src.entity.*;
      import src.interfaces.*;
      import src.klassen.PersonTmp;
      import static org.jboss.seam.ScopeType.SESSION;
      
      
      @Stateful
      @Name("suchhdl")
      @Scope(SESSION)
      //Verhindert das dieses Bean passiviert wird
      @Cache(org.jboss.ejb3.cache.NoPassivationCache.class)
      public class Suche implements SucheLocal {
              
              //EntityManager
          @PersistenceContext(unitName="asd")
              public EntityManager asdb;
          
          @EJB
              public Manager manager;
              
          public HWname_PDBean hwname = new HWname_PDBean();
              
              @In
              Identity identity; 
              
              @In
              FacesMessages facesMessages;
              
              //Variablen für die Anzeige der Person
              public Person person = new Person();
              public PersonTmp personTmp;
              private String nameVoll;
              
              //Suchvariablen
              private String nummer;
              private String name;
              private String strasse;
              private String plz;
              private String ort;
              
              //Flagvariable um zu schauen ob sich in den Felder was geändert hat
              boolean feldAenderung;
              
              //Flagvariable zur Steuerung des Kunden-Auswahl-Buttons
              private String auswahlFlag;
              
              //Datenmodell für die Suche
              @DataModel
              private List <Person> personen;
              @DataModelSelection("personen")
              @Out (required=false)
              private Person selectedPerson;
      //*************************************************************************
              /**
               * Methode um HWname auszuführen und den Namen zu prüfen
               */
              public boolean nameAufbereiten()        {
                      System.out.print("nameAufbereiten");
                      nameVoll = nameZusammensetzen();
                      return true;            
              }
      //-------------------------------------------------------------------------     
              /**
               * Methode um HWname auszuführen und den Namen zu prüfen
               */
              public boolean doHwname(String name)    {
                      
                      return true;
                      
              }
      //-------------------------------------------------------------------------     
      ..........
      The interface
      package src.interfaces;
      
      import java.util.List;
      
      import javax.ejb.*;
      import javax.faces.event.ValueChangeEvent;
      import javax.faces.model.SelectItem;
      import org.jboss.seam.annotations.WebRemote;
      import src.entity.Person;
      
      
      @Local
      public interface SucheLocal {
      
              public String suchen();
              public void setNummer(String nummer);
              public String getNummer();
              public void setName(String name);
              public String getName();
              public void setStrasse(String strasse);
              public String getStrasse();
              public void setPlz(String plz);
              public String getPlz();
              public void setOrt(String ort);
              public String getOrt();
              public List<?> getAsperreList();
              public List<?> getPsperreList();
              public void strtextChanged(ValueChangeEvent vce);
              public void destroy();
              void setPerson(Person person);
              Person getPerson();
              List<SelectItem> getAnredeList();
              void setAuswahlFlag(String auswahlFlag);
              String getAuswahlFlag();
              @WebRemote
              boolean doHwname(String name);
              void setNameVoll(String nameVoll);
              String getNameVoll();
              @WebRemote
              boolean nameAufbereiten();
              String reset();
      }



      Please help me, I search since 2 days and have no idea what the problem is.