在primefaces JSF中使用模板 [英] using templates in primefaces JSF

查看:208
本文介绍了在primefaces JSF中使用模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有主页index.xhtml,带有声明的位置,可以根据单击的页面放置内容.

I have main page index.xhtml with declared place to put content dependent on page clicked.

            <br>
            <div id="centerContent">
        <ui:insert name="centerContent" >
              <ui:param name="mainTag" value="" />
        <ui:include src="/template/commonContent.xhtml" />
        </ui:insert>
                <h4>#{mainTag}</h4>
           </div>
            </br><br></br>
            <p:panel id="content">
                        <h:form>
    <h:inputText id="namez" ></h:inputText>
</h:form>
            </p:panel>       
        </p:layoutUnit>

我的模板commonContent是:

my template commonContent is:

<?xml version="1.0" encoding="UTF-8"?>
<!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"
      >
    <body>
        <ui:composition>
        <h1>Ubezpieczamy najlepiej!</h1>
        </ui:composition>
    </body>
</html>

发送电子邮件的页面是:

and page for sending emails is:

<?xml version="1.0" encoding="UTF-8"?>
<!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:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      >
    <h:body>

        <ui:composition template="index.xhtml">

            <ui:define name="centerContent">
                <h2>Zapytaj</h2>
                        <h:commandButton actionListener="#{mySendBean.sendMail2()}" value="Welcome Me">
            </h:commandButton>
                        <ui:param name="mainTag" value="Z chęcią odpowiemy" />
            </ui:define>


        </ui:composition>

    </h:body>

在将CommandButton置于主页上时,它会发送电子邮件,但通过模板加载时,它不会起作用.一切正常,但<h:commandButton actionListener="#{mySendBean.sendMail2()}" value="Welcome Me">无效. 为什么通过单击的模板加载时不起作用?

when commandButton is put on main pages it works, email is sent, but when loaded via template it didn't work. All things work but not <h:commandButton actionListener="#{mySendBean.sendMail2()}" value="Welcome Me">. Why it doesn't work when loaded via clicked template?

bean代码:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.mail.*;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;


/**
 *
 * @author root
 */
@ManagedBean
@SessionScoped
public class mySendBean {

    private myEmailSend mE;
    /**
     * Creates a new instance of mySendBean
     */
    public mySendBean() {
        mE=new myEmailSend();
    }

    private static int j;

    /**
     * Get the value of j
     *
     * @return the value of j
     */
    public int getJ() {
        return j;
    }

    /**
     * Set the value of j
     *
     * @param j new value of j
     */
    public void setJ(int j) {
        this.j = j;
    }

        private String name="iop";

    /**
     * Get the value of name
     *
     * @return the value of name
     */
    public String getName() {
        return name;
    }

    /**
     * Set the value of name
     *
     * @param name new value of name
     */
    public void setName(String name) {
        this.name = name;
        sendMail2();
    }

    public String getSayWelcome(){
       //check if null?
       if("".equals(name) || name ==null){
        return "";
       }else{
        return "Ajax message : Welcome " + name;
       }
    }

    public void setSendMail(){
        sendMail2();
    }
    public void sendMail2(){ 
        j=getJ();
        setJ(++j);

        Email email = new SimpleEmail();
        try {
        //send mail
    }
}

推荐答案

必须在<h:form>中包含内容:

<?xml version="1.0" encoding="UTF-8"?>
<!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:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      >
    <h:body>

        <ui:composition template="index.xhtml">

            <ui:define name="centerContent">
                    <h:form>
                        <ui:param name="mainTag" value="Z chęcią odpowiemy" />
                <h2>Zapytaj</h2>
                        <h4>#{mainTag}</h4>
                        <h:commandButton actionListener="#{mySendBean.sendMail2()}" value="Welcome Me">
            </h:commandButton>
                    </h:form>
            </ui:define>


        </ui:composition>

    </h:body>

</html>

这篇关于在primefaces JSF中使用模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆