h:inputText将空值返回到Data表中

时间:2017-04-26 17:49:25

标签: jsf jsf-2 xhtml

我确信这是一个常见的问题,但我似乎无法找到解决方案。基本上,当我将所需的数据添加到每个输入文本框中并单击下面输入页面上看到的所有命令按钮时,数据不会传递到指定的数据表,而是留下空值。

这是输入这些值的xhtml代码:

 <h3> Please fill in the boxes below and click save when you have finished.</h3>
            <h:form>
                <table>
                    <tr>
                <td>Id Number :</td>
                        <td><h:inputText size="20" value="#{collectors.ID}" /></td>
                    </tr>

                    <tr>
                <td>Name :</td>
                        <td><h:inputText size="20" value="#{collectors.name}" /></td>
                    </tr>

                    <tr>
                <td>Release Date :</td>
                        <td><h:inputText size="20" value="#{collectors.releaseDate}" /></td>
                    </tr>

                    <tr>
                <td>Platform :</td>
                        <td><h:inputText size="20" value="#{collectors.platform}" /></td>
                    </tr>

                    <tr>
                <td>Genre :</td>
                        <td><h:inputText size="20" value="#{collectors.genre}" /></td>
                    </tr>

                    <tr>
                <td>Developer :</td>
                        <td><h:inputText size="20" value="#{collectors.developer}" /></td>
                    </tr>

                    <tr>
                <td>Publisher :</td>
                        <td><h:inputText size="20" value="#{collectors.publisher}" /></td>
                    </tr>

                </table>

                <h:commandButton value="SAVE"  action="#{collectors.saveAction}"  />

            </h:form>

这是应该显示该数据的数据表的代码:

<h:form>

            <h:dataTable value="#{collectors.collectionList}"  var="c" border ="2">

             <h:column>
            <f:facet name="header">
                ID NO
                </f:facet>
                #{c.ID}

             </h:column>

            <h:column>
                 <f:facet name="header">
                    Name
                </f:facet>   
                #{c.name}
            </h:column>

            <h:column>
                    <f:facet name="header">
                    Release Date
                    </f:facet>
                    #{c.releaseDate}
            </h:column>

            <h:column>
                    <f:facet name="header">
                    Platform
                    </f:facet>
                    #{c.platform}
           </h:column>
           <h:column>
                    <f:facet name="header">
                    Genre
                    </f:facet>
                    #{c.genre}
           </h:column>

           <h:column>
                     <f:facet name="header">
                    Developer
                    </f:facet>
                    #{c.developer}
           </h:column>

           <h:column>
                     <f:facet name="header">
                    Publisher
                    </f:facet>
                    #{c.publisher}
           </h:column>

            <h:column>

            <f:facet name="header">Action</f:facet>

            <h:commandLink value="Delete" action="#{collectors.deleteAction(c)}" />

            </h:column>
            </h:dataTable>

我的Java Managed Bean Code:

package bean;

    import java.util.ArrayList;
    import java.util.Arrays;
    import javax.faces.bean.SessionScoped;
    import java.io.Serializable;


@Named(value = "collectors")
@SessionScoped

public class CollectorsBean implements Serializable{


    private static final long serialVersionUID = 1L;


int ID; 
String Name;
String ReleaseDate;
String Platform;
String Genre;
String Developer;
String Publisher;


public int getID() {
        return ID;
    }

public void setID(int ID) {
    this.ID = ID;
}

public String getName() {
    return Name;
}

public void setName(String Name) {
    this.Name = Name;
}

public String getReleaseDate() {
    return ReleaseDate;
}

public void setReleaseDate(String ReleaseDate) {
    this.ReleaseDate = ReleaseDate;
}

public String getPlatform() {
    return Platform;
}

public void setPlatform(String Platform) {
    this.Platform = Platform;
}

public String getGenre() {
    return Genre;
}

public void setGenre(String Genre) {
    this.Genre = Genre;
}

public String getDeveloper() {
    return Developer;
}

public void setDeveloper(String Developer) {
    this.Developer = Developer;
}

public String getPublisher() {
    return Publisher;


 }

    public void setPublisher(String Publisher) {
        this.Publisher = Publisher;
    }



  private static final ArrayList<Entry> collectionList= 
                new ArrayList<Entry>(Arrays.asList(

                new Entry (1, "Persona 5", " 4th April 2017", "Playstation 4", "Social Simulator/RolePlaying","Atlus","Deep Silver" )


                ));

    public ArrayList <Entry> getCollectionList(){

        return collectionList;
    }

    public String saveAction(){

       Entry entry = new Entry(this.ID, this.Name, this.ReleaseDate, this.Platform, this.Genre, this.Developer, this.Publisher);

        collectionList.add(entry);

        return "Collection Page.xhtml";
    }

    public String deleteAction(Entry entry) {

                collectionList.remove(entry);
        return null;
    }

    public static class Entry{

    int ID; 
    String Name;
    String ReleaseDate;
    String Platform;
    String Genre;
    String Developer;
    String Publisher;

    public Entry(int ID, String Name, String ReleaseDate, String Platform, String Genre, String Developer, String Publisher)
    {
        this.ID = ID;
        this.Name = Name;
        this.ReleaseDate = ReleaseDate;
        this.Platform = Platform; 
        this.Genre = Genre;
        this.Developer = Developer;
        this.Publisher = Publisher;


    }

     public int getID() {
        return ID;
    }

    public void setID(int ID) {
        this.ID = ID;
    }

    public String getName() {
        return Name;
    }

    public void setName(String Name) {
        this.Name = Name;
    }

    public String getReleaseDate() {
        return ReleaseDate;
    }

    public void setReleaseDate(String ReleaseDate) {
        this.ReleaseDate = ReleaseDate;
    }

    public String getPlatform() {
        return Platform;
    }

    public void setPlatform(String Platform) {
        this.Platform = Platform;
    }

    public String getGenre() {
        return Genre;
    }

    public void setGenre(String Genre) {
        this.Genre = Genre;
    }

    public String getDeveloper() {
        return Developer;
    }

    public void setDeveloper(String Developer) {
        this.Developer = Developer;
    }

    public String getPublisher() {
        return Publisher;
    }

    public void setPublisher(String Publisher) {
        this.Publisher = Publisher;
    }



    }




}

如果有人能帮助我解决这个问题,我将非常感激。

0 个答案:

没有答案