Search code examples
javajakarta-eewebsphere-7

How to use the forward and redirect view in my controller command?


I was working with my new Controller command. I just want to know how can i use both forward and redirect views in my controller command to to redirect to a view which is configured in my struts-config-ext.xml?


Solution

  • You could try some thing like this:

    Redirect:

    public void performExecute() throws ECException {
            //do something here...
            //....................
            TypedProperty rspProp = new TypedProperty();
            rspProp.put(ECConstants.EC_URL, "YourViewName");
            rspProp.put(ECConstants.EC_VIEWTASKNAME, ECConstants.EC_GENERIC_REDIRECTVIEW);
            //....................
            //....................
        }
    

    Forward:

    public void performExecute() throws ECException {
            //do something here...
            //....................
            TypedProperty rspProp = new TypedProperty();
            rspProp.put(ECConstants.EC_VIEWTASKNAME, "YourViewName");       
            //....................
            //....................
        }
    

    Both forward and redirect can be used in your controller command for passing control from your command to a view which is configured in your strut-config-ext.xml. If you use forward, both command and view runs in a single transaction and in case of any exception in view all the data saved in the command will be rolled back. But, if you use the redirect view in your command, the command and view runs in two transaction unlike forward. Once the command finishes it commits transaction a new transaction starts for view. An exception in your view may not roll back the committed data in your command in this case.