Tuesday, November 11, 2014

Understanding controller command in IBM websphere commerce

Before writing controller command we need to understand what all OOTB method need to implement.

Below six OOTB method available in Controller command :

isGeneric()

In the standard WebSphere Commerce implementation there are multiple types of users. These include generic, guest, and registered users. Within the grouping of registered users there are customers and administrators. The isGeneric method returns a Boolean value which specifies whether the command can be invoked by the generic user. The isGeneric method of a controller command's superclass sets the value to false (meaning that the invoker must be either a registered customer or a guest customer). If your new controller command can be invoked by generic users, override this method to return true.
 

isRetriable()

 
The isRetriable method returns a Boolean value which specifies whether the command can be retried on a transaction rollback exception. The isRetriable method of the new controller command's superclass returns a value of false. You should override this method and return a value of true, if your command can be retried on a transaction rollback exception. 
 

setRequestProperties(com.ibm.commerce.datatype.TypedProperty reqParms)

The setRequestProperties method is invoked by the Web controller to pass all input properties to the controller command. The controller command must parse the input properties and set each individual property explicitly within this method.
 
 

validateParameters()

The validateParameters method is used to do initial parameter checking and any necessary resolution of parameters. For example, it could be used to resolve orderId=*. This method is called before both the getResources and performExecute methods.
 

performExecute()

The performExecute method contains the business logic for your command. It should invoke the performExecute method of the command's superclass before any new business logic is executed. At the end, it must return a view name.
 
 
Under performExecute following
 

    /// Create a new TypedProperties for output purposes.
  TypedProperty rspProp = new TypedProperty();
 
 
  /// The controller command passes variables to the JSP page
 /// add additional parameters in controller command to rspProp for response
    String message1 = "Hello from IBM!";
    rspProp.put("controllerParm1", message1);
    rspProp.put("controllerParm2", "Have a nice day!");
 
 
 /// instantiate the MyNewDataBean databean and set the properties, then add the instance to resProp for response
 MyNewDataBean mndb = new MyNewDataBean();
 mndb.setCallingCommandName(this.getClass().getName());
 mndb.setCalledByControllerCmd(true);
 
 // pass the input information to the databean
 mndb.setUserName(this.getUserName());
 mndb.setPoints(this.getPoints());

 rspProp.put("mndbInstance", mndb);
 

    /// The controller command calls a task command
 MyNewTaskCmd cmd = null;
 try {
  cmd = (MyNewTaskCmd) CommandFactory.createCommand("com.ibm.commerce.sample.commands.MyNewTaskCmd", getStoreId());
        // this is required for all commands
        cmd.setCommandContext(getCommandContext());
  /// set input parameters to task command
  cmd.setInputUserName(getUserName());
  cmd.setInputPoints(getPoints()); // change to Integer

  /// pass rrb instance variable to the task command
  cmd.setUserRegistryAccessBean(rrb);

  /// pass bb instance variable to the task command
  cmd.setBonusAccessBean(bb);
  /// invoke the command's performExecute method
  cmd.execute();
  /// retrieve output parameter from task command, then put it to response properties
  rspProp.put("taskOutputGreetings", cmd.getGreetings());

  ///using access bean to get information from databse
  if (cmd.getFoundUserId() != null) {
   rspProp.put("taskOutputUserId", cmd.getFoundUserId());
  }

  if (cmd.getOldBonusPoints() != null) {
   rspProp.put("oldBonusPoints", cmd.getOldBonusPoints());
  }

     ///Instantiate the bonus databean , then put it into response properties
        BonusDataBean bdb  = new com.ibm.commerce.sample.databeans.BonusDataBean(cmd.getBonusAccessBean());
     rspProp.put("bdbInstance", bdb );

 } catch (ECException ex) {
  /// throw the exception as is
  throw (ECException) ex;
 }
 
    /// see how the controller command calls the JSP
 rspProp.put(ECConstants.EC_VIEWTASKNAME, "MyNewView");
 setResponseProperties(rspProp);

}
 
 

2 comments:

  1. Excellent…Amazing…. I’m satisfied to find so many helpful information here within the put up,for latest php jobs in hyderabad. we want work out extra strategies in this regard, thanks for sharing.

    ReplyDelete
  2. Ibm Websphere Commerce: Understanding Controller Command In Ibm Websphere Commerce >>>>> Download Now

    >>>>> Download Full

    Ibm Websphere Commerce: Understanding Controller Command In Ibm Websphere Commerce >>>>> Download LINK

    >>>>> Download Now

    Ibm Websphere Commerce: Understanding Controller Command In Ibm Websphere Commerce >>>>> Download Full

    >>>>> Download LINK Ne

    ReplyDelete