Arch2Arch Tab BEA.com

Vimala Ranganathan's Blog

Vimala Ranganathan's Homepage
is a QA engineer on the workshop team. She has over eight years of experience in Java SE/Java EE technologies. She has been with BEA for more than 5 years during which time she worked as a DRE in Weblogic Server and Workshop Support Team. She has also been a contributor to Java One, Dev2Dev workshop newsgroup and the Weblogic Developer Journal.

Issues with popup window and pageflows/portlets

Posted by rvimala on November 15, 2006 at 3:53 PM | Permalink | Comments (6)

Popups and pageflow don't work together in 8.1GA because only the current pageflow and it's stack (of nested pageflows) is maintained in the session. The issue is that each portlet has its own "scoped" instance of the relevant page flow. The popup window talks to the default (unscoped) page flow.

What's jpfScopeID and what does it do?

From 8.1SP2 onwards, we added a way for *any* request to be associated with a particular scope. So if you want a popup window to talk to a pageflow that lives in a portlet, you can add a special request parameter ("jpfScopeID") to the URL in order to identify the target scope (in this case, portlet-ID). Each scope has its own idea of the current page flow and the current stack of nested page flows.

BEA engineer Richard Feit wrote a sample that demonstrates this functionality.This example will pop up a window which allows the user to submit a value to the *portlet's* page flow instance.

There is also some additional funky javascript to close the window and refresh the portlet when the user submits the form in the popup window. The main point, though, is the use of the "jpfScopeID" request parameter.
In the attached example there's a portlet that you can drop (any number of times) into a new portal under 8.1 SP2.

Setup:
1. Create a Default Portal Application and a Portal Web Project in your application
2. Right click and import the folder popup into your web project
3. Create a portal and drag and drop the .portlet file as many times as you want into the portal
4. Build and Run the Portal
5. Click on the popup link in one portlet and enter any value and submit
6. You can see that the portal will have the value entered in the popup window
7. Similarly, you can click on the popup link in other portlets and see that the value is saved in each of the portlet. One popup window value does not override the previous value. Each portlet instance gets it's own pageflow instance.

Sample

popup.zip - the sample on using popup window within portlets and pageflow

Working with Arrays in form Bean using different FORM bean scopings

Posted by rvimala on November 15, 2006 at 11:36 AM | Permalink | Comments (2)

Abstract

This article discusses two types of form scoping and addresses the issue of  working with Array or Complex DataType as a member of the FormBeans

In this sample we have taken an array of checkbox items to demonstrate how  the two form scopings work with form beans.

The article also has samples for both Workshop 8.1 and Workshop 9.2

Form Bean Scopings

There are two different scopings available for Form Beans: (1) request-scoping and (2) page flow-scoping. 

Request-Scoped Form Beans

By default, Form Bean instances that are passed to action methods are request-scoped instances.

<pre class="code">
 /**
* @jpf:action
* @jpf:forward name="success" path="displayData.jsp"
*/
protected Forward submit( MyFormBean requestScopedBean )
{
return new Forward( "success" );
}
</pre>

"Request-scoped" means that the Form Bean instance has the same life-cycle as the HTTP request. The Form Bean instance is created at the same time as the request and it is destroyed, along with any data within it, when the request is destroyed. Request-scoped Form Bean instances are useful when you submitting data from a single JSP page to a single action method. 

Page Flow-Scoped Form Beans

Page Flow-scoped Form Bean instances have the same life-cycle as the Controller file instance. They are created and destroyed when the Controller file instance is created and destroyed. This makes Page Flow-scoped Form Beans useful for storing data that has been accumulated across many different JSP pages.

To create a Page Flow-scoped Form Bean instance, construct a public member variable of the Form Bean in the Controller file.

<pre class="code">
public class myController extends PageFlowController
{
public MyFormBean pageFlowScopedBean = new MyFormBean();
.
.
.
}
</pre>

Once you have created a Page Flow-scoped instance of a Form Bean, you can pass the instance to action methods by using the @action form="form_bean" annotation.

<pre class="code">
public class myController extends PageFlowController
{
public MyFormBean pageFlowScopedBean = new MyFormBean();

/**
* @jpf:action form="pageFlowScopedBean"
* @jpf:forward name="success" path="displayData.jsp"
*/
protected Forward submit( MyFormBean form )
{
return new Forward( "success" );
}
}
</pre>

Each time the submit() method is invoked, it is passed the same instance of the Form Bean, namely, pageFlowScopedBean, the instance that was created when the Controller file instance was created.

Arrays or Complex Data Type within Request Scoped Form Bean

Default scope of formBean is Request; therefore, each http request triggers the container to instantiate a new formBean instance. That is, the formBean instance that contains large array will not be used upon subsequent form submission.

The container usually inokes the setXXX method to set the values into the form bean. But in case of arrays or complex object type the container invokes getXXX method for the array type object or complex type object before setting a value to each array element. So you need to modify the getter method and make sure the array is initialized to the correct size. By default workshop would initialize it to 1 and would generate a setter like below
<pre class="code">
public String[] getName() {
// For data binding to be able to post data back, complex types and
// arrays must be initialized to be non-null.
if(this.name == null || this.name.length == 0) {
this.name = new String[1];
}
return this.name;
}
</pre>
You can modify this code to set the size of the String array to any size

When can I not use Arrays with in Request Scoped form beans:

The problem with the above solution is that we need to know the size of the array and if the form bean has a complex object which may have arrays, then we need to know its size too and kind of hardcode the value.
This may not be possible in all situations and page flow scoped form bean will be useful in overcoming these issues.

Arrays or Complex Data Type within PageFlow Scoped Form Bean

This design approach allows a user to solve the following issues.

· a formBean contains non-static array sized array type
· a formBean contains XMLBean Document as a property and one or more elements in this XMLBean Document instance has array type
· getXXX method returns non-null array type as default and usally the array size is set to one. setXXX is used to set larger array sized object but upon submission of form only one element is submitted.

When can I not use Arrays with in Page Flow Scoped form beans:

There are certain situations like standalone portlets when you are using Arrays, you cannot use Pageflow scoped formbeans and in such case you need to use Request Scoped Form Bean.

Code Sample:

In this sample we have demonstrated how an array of a complex java bean works with both request scoped form bean and page flow scoped form bean.

We have defined a java bean "FormListBean" which has a string and a int member variable and the Form Bean has an array of  type "FormListBean"

Setup:

    1. Create a Web Project in your application
    2. Right click and import the folder sample into your web project
    3. Build and Run the Controller
    4. The Controller will bring up a page with a table of strings and checkboxes with default value. 
    5. You can edit and submit the data and the display page will display all the modified data. 
    To test again you can reset the values by clicking the Reset button on the page which will take you to index page

    Conclusion

    This article talks about the two types of form bean scopings and how they can be used when we have arrays or complex object type as member variable of  a form bean and also to be able to modify the data in the array and submit. It discusses the scenario's when a specific form bean scoping cannot be used with form beans having array data type. The article is also accompanied by samples on both 8.1 and 9.2 for both Request Scoped Form Beans and Page Flow Scoped Form Beans.

    References

    Edocs Reference - the BEA edocs page
    RequestScoped_Workshop8.1.zip - the sample on request scoped form bean with arrays on workshop 8.1
    PageFlowScoped_Workshop8.1.zip - the sample on page flow scoped form bean with arrays on workshop 8.1
    RequestScoped_Workshop9.2.zip - the sample on request scoped form bean with arrays on workshop 9.2
    PageFlowScoped_Workshop9.2.zip - the sample on page flow scoped form bean with arrays on workshop 9.2


April 2008

Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      


Search this blog:


Archives

November 2006

Categories

Version Information and BEA Workshop blogs for more details. ">Product: BEA Workshop Product Family

Recent Entries

Issues with popup window and pageflows/portlets

Working with Arrays in form Bean using different FORM bean scopings

Articles

An Introduction to the Enterprise JavaBeans 3.0 (EJB 3) Specification
The EJB 3.0 specification goes a long way toward making the EJB programming experience a pleasant one by simplifying development, facilitating test-driven development, and focusing more on plain Java objects. This article takes a look at the specification, and how to build EJBs in the new model. Mar. 29, 2006

WS-Security and Java: Practical, In-Depth, Message-Based Security
This article looks at WS-Security and related technologies such as XML Signatures and XML Encryption, with a brief look at other protocols in this space. May. 26, 2004

All articles by Vimala Ranganathan »


Powered by
Movable Type 3.31