Loading...

Forward View and Redirect View in IBM Websphere Commerce Server

Redirect View 

In the case of redirect view when redirects from a command the View or JSP will run in a new transaction Hence if an  exception occurs in the JSP what is saved in the command won't roll back.Redirect is done via URL  and hence it can't pass objects  back to View.It can only pass name value pairs.Redirect has a browser URL length limitation with IE browser.
Forward and Redirect view in IBM

There are two approaches for handling a limited length redirect URL:

1.Override the getViewInputProperties method in the controller command to return only the sets of parameters that are required to be passed to the redirect response.

2.Use a specified special character in the URL parameters to indicate which parameters can be removed from the input parameter string.

For E.g.: While redirecting to TestViewName we need to remove certain parameters due to URL length limitation. In this case property2, property3 has to be removed.

URL="TestViewName";
Property1=" PropertyValue1";
Property2=" PropertyValue2";
Property3=" PropertyValue3";

Using Approach 1 (Override the getViewInputProperties method)

If you are overriding the getViewInputProperties method, the new method can be written so that only the following parameters are passed to the view command:

Property1="PropertyValue1";

public TypedProperty getViewInputProperties() {
TypedProperty tp = viewReqProperties;
tp.remove(Property2);
tp.remove(Property3);
return tp;
}

Using the second approach(Use special character to indicate which parameters can be removed), consider this URL=”TestViewName?Property2*=&Property3*="

This URL parameter instructs the Web Sphere Commerce runtime framework of the following:
The Property2*= specification means that all parameters whose names start with Property2 should be removed.
The Property3*= specification means that all parameters whose names start with Property3 should be removed.
TypedProperty rspProp = new TypedProperty();
rspProp.put(ECConstants.EC_URL, "TestViewName");
rspProp.put(ECConstants.EC_VIEWTASKNAME, ECConstants.EC_GENERIC_REDIRECTVIEW);

ForwardView

In the case of forward view when we are forwarding from a command to a View or a JSP the command and the JSP will run in the same transaction.Hence if an exception in JSP will cause what is saved in command to roll back.Forward View method can pass objects back to the view.

TypedProperty rspProp = new TypedProperty();
rspProp.put(ECConstants.EC_VIEWTASKNAME, "TestViewName");        

Note: If you use forward view while passing control from a command to a view then if user presses refresh button or F5 the command will be executed again as the URL will remain the same command URL for e.g. While passing control from OrderItemAddCmd to a view. Then when user presses F5 button one more item might be added to cart. But in the case of redirect since the URL is changed to the view URL even if user presses F5 button only the view will be loaded again.
websphere 3275205112596891915

Post a Comment

emo-but-icon

Home item

Blog Archive

Popular Posts

Random Posts

Flickr Photo