primefaces提交表格以保存

时间:2012-12-17 19:35:32

标签: java xhtml primefaces

我的代码段如下:

<h:form>
                <p:panel id="projectLabel" header="Yeni Proje" style="margin-bottom:10px;">
                    <p:messages id="messages" />

                    <h:panelGrid columns="2">

                        <h:outputLabel for="projectname" value="Proje Adı :" />
                        <p:inputText id="projectname" value="" label="ProjectName">
                            <f:validateLength minimum="2" />
                        </p:inputText>
                        <p:message for="projectname" />
                        <h:outputText value="" />

                        <h:outputLabel for="sector" value="Sektör :" />
                        <p:inputText id="sector" value=""  label="Sector"/>
                        <p:message for="sector" />
                        <h:outputText value="" />


                        <center>
                            <p:commandButton ajax="false" value="Kaydet" icon="ui-icon-disk" action="#{createProject.create()}" />
                        </center>
                    </h:panelGrid>
                </p:panel>
            </h:form>

我想要做的是,当用户点击“保存”按钮时,表单的所有条目都将被触发到java类以保存数据库。我怎么能这样做?

1 个答案:

答案 0 :(得分:3)

这是支持豆

@ManagedBean(name="saveData")
@ViewScoped
public class SaveData{
    public SaveData(){}
    private String projectName;
    private String sector;
    //getters setters
    public void save(){
        // you have your data here
    }
}

这是html

<p:panel id="projectLabel" header="Yeni Proje" style="margin-bottom:10px;">
                <p:messages id="messages" />

                <h:panelGrid columns="2">

                    <h:outputLabel for="projectname" value="Proje Adı :" />
                    <p:inputText id="projectname" value="#{saveData.projectName}" label="ProjectName">
                        <f:validateLength minimum="2" />
                    </p:inputText>
                    <p:message for="projectname" />
                    <h:outputText value="" />

                    <h:outputLabel for="sector" value="Sektör :" />
                    <p:inputText id="sector" value="#{saveData.projectName}"  label="Sector"/>
                    <p:message for="sector" />
                    <h:outputText value="" />


                    <center>
                        <p:commandButton ajax="false" value="Kaydet" icon="ui-icon-disk" action="#{saveData.save}" />
                    </center>
                </h:panelGrid>
            </p:panel>
        </h:form>