1

私のindex.xhtmlページには、これと、フッター、ヘッダー、メニューなどの他の小さなものが含まれています...:

index.html には以下が含まれます:

<h:head/>
<h:body>
 <p:layout fullPage="true">
  <p:layoutUnit position="center" >
  <h:panelGroup id="content" layout="block">

    <h:form id="contentform">
<!-- Cas page contact == page affichée lors du clic sur contact -->
     <h:form id="contact">
      <h:panelGroup rendered="#{navBean.page == 'contact'}">
       <ui:include src="contact.xhtml" />
      </h:panelGroup>
     </h:form>
    </h:form>
<!--Fin de gestion des cas possible -->
 </h:panelGroup>
</p:layoutUnit>
<!-- Fin layout central --> 
 </p:layout>
</h:body>

私は JSF 2.1 と PrimeFaces を使用しています。次のコマンド ボタンがありますcontact.xhtml

<h:head/>
 <h:body> 
  <p:commandButton value="Envoie la sauce" action="#{mail.sendEmail()}"  >
   <f:ajax execute="@form" render="@form" />
  </p:commandButton>
</h:body>

次の Bean アクションを参照します。

@ManagedBean(name="mail")
@SessionScoped
public class MailBean {
public void sendEmail() throws IOException {
    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.socketFactory.class",
            "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "465");

    Session session = Session.getDefaultInstance(props,
        new javax.mail.Authenticator() {
                            @Override
    protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication("username","password");
            }
        });

    try {

        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("toto@yopmail.com"));
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse("toto@gmail.com"));
        message.setSubject("Demande de Contact");
        message.setText("Dear Mail Crawler," +
                "\n\n No spam to my email, please!");

        Transport.send(message);

                    //to see if message was send
        System.out.println("Done");

    } catch (MessagingException e) {
        throw new RuntimeException(e);
    }
}
}

これは JavaMail 経由でメールを送信することになっていますが、このボタンはページを更新する以外には何もしません。

SendHTMLEmail クラスをスタンドアロンの Java アプリケーションとしてテストしましたが、完全に動作します。

私がやろうとしているのは、JSF2.1 を使用して xhtml で作成された単純な連絡先フォームです。

更新 - 今日はいくつかのニュースがあります!このこと<p:commandButton action="#{mail.send()}"/>を使用すると、ページ index.xhtml で何かが発生し、クラスが見つからない理由を特定する必要があります...:

<?xml version='1.0' encoding='UTF-8'?>
<partial-response><error><error-name>class javax.faces.el.EvaluationException</error-name><error-message><![CDATA[/index.xhtml @35,47 action="#{mail.send()}": Target Unreachable, identifier 'mail' resolved to null]]></error-message></error></partial-response>

しかし、contact.xhtmlには、同じボタンが付いたこれだけがあります:

<?xml version='1.0' encoding='UTF-8'?>
<partial-response><changes><update id="log:messages"><![CDATA[<div id="log:messages" class="ui-messages ui-widget" aria-live="polite"></div>]]></update><update id="javax.faces.ViewState"><![CDATA[-2283025416922274948:-229809047557820449]]></update></changes></partial-response>

だから私はすべてユニークなIDを持っています! 誰かが何が起こるか考えていますか? edit1: 完全なコードが追加されました edit2: すべての balises を含む index.html が追加されました edit3: アクション ボタンに関する何かが xhtml ページに発見されました

4

1 に答える 1