Creating an “Edit my Item”-page in Java Server Faces with Facelets

后端 未结 1 1362
野的像风
野的像风 2020-12-18 10:28

Let\'s say that you have the following Facelet ( Using Facelets 1.1.12 ):

edit_item.xhtml which i access with edit_item.jsf

Now i have anot

1条回答
  •  旧巷少年郎
    2020-12-18 11:27

    You can use the faces-config.xml configuration to inject the ID from the param map.

    For this simple bean:

    public class BeanWithId implements Serializable {
      private String id;
      private String info;
    
      private void populateInfo() {
        info = "Some info from data source for id=" + id;
      }
    
      public String getId() { return id; }
    
      public void setId(String id) {
        this.id = id;
        populateInfo();
      }
    
      public String getInfo() { return info; }
      public void setInfo(String info) { this.info = info; }
    
      public String save() {
        System.out.println("Saving changes to persistence store");
        return null; // no navigation
      }
    }
    

    You could inject the ID using this definition:

      
        beanWithId
        datasource.BeanWithId
        request
        
          id
          java.lang.String
          #{param.ID}
        
      
    

    Facelets form:

    
      

    ID:

    Info:

    This isn't the only way to do it (you could look the ID up directly using the FacesContext for example).

    0 讨论(0)
提交回复
热议问题