Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

how to make a prepare method in struts 2

kamal.javaMar 11 2014

Hi i am having the following action in my struts application, but m stucked up wid the problem where i want to implement preparable interface and use of customize methods like prepareCreate() etc see the action below :    

package manning.chapterThree;

import static com.opensymphony.xwork2.Action.SUCCESS;

import manning.chapterThree.utils.PortfolioService;

import manning.chapterThree.utils.User;

import com.opensymphony.xwork2.ActionSupport;

import com.opensymphony.xwork2.Preparable;

/*

* This is our first version of the Register action.  This version uses

* the basic validation and message localization services provided by the

* ActionSupport help class.  By extending this class, we automatically

* receive implementations of several interfaces that allow us to do

* validation and localize our message texts with out polluting the

* execute() method of our action.  

*/

public class Register extends ActionSupport implements Preparable{

   

        @Override

    public String execute(){

               

                create();

        /*

         * Create and move the data onto our application domain object, user.

         */

           

//        User user = new User();

//        user.setPassword( getPassword() );

//        user.setPortfolioName( getPortfolioName() );

//        user.setUsername( getUsername() );

//       

//        getPortfolioService().createAccount( user );

              

        return SUCCESS;

    }

   

   

    /* JavaBeans Properties to Receive Request Parameters */

   

    private String username;

    private String password;

    private String portfolioName;

    public String getPortfolioName() {

        return portfolioName;

    }

    public void setPortfolioName(String portfolioName) {

        this.portfolioName = portfolioName;

    }

    public String getPassword() {

        return password;

    }

    public void setPassword(String password) {

        this.password = password;

    }

    public String getUsername() {

        return username;

    }

    public void setUsername(String username) {

        this.username = username;

    }

   

    /* Validateable Implementation

     *

     * The validate method validates, invoked by the validation interceptor in

     * the default stack, will validate the data already set on the action

     * by the params interceptor, also in the default stack. 

     *

     * If this method finds problems in validation it stores error messages via

     * the methods exposed by the ValidationAware interface -- already implemented

     * by the ActionSupport class that this action extends.  To complete the

     * the validation process, the workflow interceptor fires next in the default

     * stack.  It checks for error messages on the action, and if it finds them

     * it diverts workflow back to the input page where the error messages are

     * displayed to the user.  In this case, the execute method of the action

     * will not be called because the workflow was diverted, due to validation

     * problems, before execution reached the action itself.

     *

     * */

   

    public void validate(){

       

        /* Retrieve our simple portfolio service object. */

        PortfolioService ps = getPortfolioService();

       

        /* Check that fields are not empty */

        if ( getPassword().length() == 0 ){           

            addFieldError( "password", getText("password.required") );

        }

        if ( getUsername().length() == 0 ){           

            addFieldError( "username", getText("username.required") );

        }

        if ( getPortfolioName().length() == 0  ){           

            addFieldError( "portfolioName", getText( "portfolioname.required" ));

        }       

        /* Make sure user doesn't already have an account */

        if ( ps.userExists(getUsername() ) ){       

            addFieldError("username", getText( "user.exists"));

        }

       

    }

   

    /* 

     * Simple way to retrieve our business logic and data persistence

     * object.  Late versions of the portfolio app will integrate with

     * more sophisticated technologies for these services.

     */

    public PortfolioService getPortfolioService( )     {

          //   update();

       

        return new PortfolioService();

       

    }

   

   

    @Override

    public void prepare() throws Exception {

        //update();

        create();

        System.out.println("Calling prepare itself");

      //  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.

    }

   

   

    void create() throws Exception

    {

      System.out.println("Calling Update Updating ...");

    }

       

    void prepareCreate () throws Exception

    {

      System.out.println("Prepare Updating ...");           

    }

   

   

}

i called create() on line 26, the framework should call prepareCreate() prior to create , but it is not executing , only prepare method get called , any help will be appreciated , THANKS IN ADVANCE

Comments

mseberg
Try

ALTER SESSION SET CURRENT_SCHEMA=QA



There's also an Oracle note on this :

ALTER SESSION returns ORA-02421 missing or invalid schema authorization identifier. [ID 848248.1]

Best Regards

mseberg
user3636719
Where can I find the note?
mseberg
Answer
Try it without the single quotes.

Best Regards

mseberg


Test on mine :

Release 11.2.0.1.0 - 64bit Productio

I get the same error with quotes

ERROR at line 1:
ORA-02421: missing or invalid schema authorization identifier

Edited by: mseberg on Aug 15, 2011 2:50 PM

So this and then the verify
ALTER SESSION SET CURRENT_SCHEMA=QA
You can verify using this :
select sys_context('USERENV','SESSION_SCHEMA') from dual;
Edited by: mseberg on Aug 15, 2011 3:08 PM
Marked as Answer by user3636719 · Sep 27 2020
1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Apr 8 2014
Added on Mar 11 2014
0 comments
3,126 views