Menu

How to get autogenerated id after save

CSJakharia
2009-01-02
2012-11-26
  • CSJakharia

    CSJakharia - 2009-01-02

    As soon as the user saves the data I want that the user should be transferred to another url and therefore I had written a action which extends SaveAction and implements IForwardAction but the problem is that I don't know how to get id of the saved data?

    My Class has declared id as

    @Id @Hidden @GeneratedValue(generator="system-uuid")
    @GenericGenerator(name="system-uuid", strategy = "uuid")
    private String id;

    Action Code
    --------------------

    public class SaveAction extends org.openxava.actions.SaveAction implements IForwardAction {
        private String url;
        @Override
        public void execute() throws Exception {
            // TODO Auto-generated method stub
            id=(String)getView().getKeyValues().get("id");
            super.execute();
           
        }
        public String getForwardURI() {
            // TODO Auto-generated method stub
            return "/xava/custom/forward.jsp?url="+url;
        }

        public boolean inNewWindow() {
            // TODO Auto-generated method stub
            return false;
        }

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }
    }

    Thanks in advance

    CSJakharia

     
    • Javier Paniza

      Javier Paniza - 2009-01-05

      Hi CSJakharia,

      do it in this way:

      public void execute() throws Exception {

      setResetAfter(false); // In this way the key will be refreshed from saved Entity to View
      super.execute(); // Save, and after it you have the oid in View
      id=(String)getView().getKeyValues().get("id");  // Now, id has value

      }

      Cheers
      Javi

       
    • CSJakharia

      CSJakharia - 2009-01-09

      Thanks that works

      CSJakharia

       

Log in to post a comment.