3

我的代码片段如下:

<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 类以保存数据库。我怎样才能做到这一点?

4

1 回答 1

4

这是一个后备豆

@ManagedBean(name="saveData")
@ViewScoped
public class SaveData {
    
    private String projectName;
    private String sector;
    
    public SaveData(){}
    
    //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>   
于 2012-12-17T20:21:33.353 回答