2014-01-16 68 views
0

我在我的應用程序中有一個頁面,用於發送一封電子郵件,其中包含要包含在正文中的用戶的詳細信息。返回空值的JSF頁面

電子郵件發送正確,但JSF返回的值爲空,我找不到原因。框架:Eclipse Kepler,JSF2,Glassfish4。 這個bean代碼

    import java.util.Date; 
        import java.util.Properties; 
        import javax.faces.bean.ManagedBean; 
        import javax.faces.bean.SessionScoped; 
        import javax.faces.application.FacesMessage; 
       import javax.faces.context.FacesContext; 
       import javax.inject.Named; 
       import javax.mail.Authenticator; 
       import javax.mail.Message; 
       import javax.mail.MessagingException; 
       import javax.mail.PasswordAuthentication; 
      import javax.mail.Session; 
      import javax.mail.Transport; 
      import javax.mail.internet.InternetAddress; 
      import javax.mail.internet.MimeMessage; 

       @ManagedBean 
       @SessionScoped 
      public class SendMail implements java.io.Serializable{ 
private static final long serialVersionUID = 1L; 
private String to = "[email protected]"; 
private String objet = "Compte inaccessible"; 
private String body= "Mon compte " 
     + getNom() 
     + " " 
     + getPrenom() 
     + " n'est plus accessible.Veuillez s'il vous plaît réinitialiser mes cordonnées et les envoyer à mon email " 
     + getFrom(); 

我需要從JSF頁面得到的值是從,NOM,prenom我已經創建自己的getter和setter。這是JSF頁面代碼

    <div id="box" style="height: 197px;"> 

     <h:form id="f1"> 
      <br></br> 
      <div class="centre"> 
       <p:inputText placeholder="Nom" required="true" id="nom" 
        value="#{sendMail.nom}" 
        validator="#{AdministrateurBean.checkAdmin}"></p:inputText> 
       <h:messages style="color:red" for="nom"/> 
      </div> 
      <div class="centre"> 
       <p:inputText placeholder="Prénom" required="true" 
        value="#{sendMail.prenom}" id="prenom" ></p:inputText> 
       <h:messages style="color:red" for="prenom"/> 
      </div> 

      <div class="centre"> 
       <p:inputText placeholder="[email protected]" required="true" id="email"></p:inputText> 
       <h:messages style="color:red" for="email"/> 
      </div> 
      <div class="centre"> 
       <p:commandButton value="Envoyer" size="30" style="width:207px" 
        action="#{sendMail.send}" update="f1" ></p:commandButton> 
      </div> 

     </h:form> 
    </div> 

,這是我的web.xml代碼

   <?xml version="1.0" encoding="UTF-8"?> 
       <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 
id="WebApp_ID" version="3.1"> 
      <display-name>Portail</display-name> 
       <welcome-file-list> 
       <welcome-file>index.xhtml</welcome-file> 
       </welcome-file-list> 
      <context-param> 
      <param-name>primefaces.THEME</param-name> 
      <param-value>delta</param-value> 
      </context-param> 
      <!-- keys gotten from recaptcha --> 
      <context-param> 
      <param-name>primefaces.PUBLIC_CAPTCHA_KEY</param-name> 
      <param-value>6Ld7pMESAAAAAHd1VihJkqPUXAJVwU3Cghc8fzrq</param-value> 
      </context-param> 

       <context-param> 
      <param-name>primefaces.PRIVATE_CAPTCHA_KEY</param-name> 
       <param-value>6Ld7pMESAAAAAMhr5WSk5bcRrff8Y08NtDi8Buoq</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> 
      <servlet-mapping> 
      <servlet-name>Faces Servlet</servlet-name> 
       <url-pattern>*.xhtml</url-pattern> 
      </servlet-mapping> 

     </web-app> 

回答

1

我真的不知道,你的意思是什麼「的價值觀從JSF返回」。我認爲你的意思是主體字符串變量。創建後臺bean時創建變量。那時你的所有成員都是空的。您需要在命令按鈕的操作方法中構造您的身體。那時你的成員將被JSF框架填充。

+0

謝謝問題解決 – MeknessiHamida