Mario,

 

I am having some difficulty in implementing the Conversation Component into my application when using Facelets and I have a suggestion for a small coding change.  Specifically my issue is with how the managed bean name is determined.

 

In my application I have a combination of Facelets Templates and composition components where I often pass the managed bean as a parameter

 

For instance a parameter called theController ="#{countryQBEController}"

 

And I use it as follows

      <s:conversation name="theConversation" value="#{theController}" />

 

The problem is that in ConversationUtils the following method returns

 

      public static String extractBeanName(ValueBinding vb)

      {

            String valueBinding = vb.getExpressionString();

            return valueBinding.substring(2, valueBinding.length()-1);

      }

 

theController and not countryQBEController which is the managed Beans Name as defined in FacesConfig.xml.

 

Thus in the Conversation Class

 

public void putBean(FacesContext context, ValueBinding vb) Method

 

      What gets stored in the TreeMap is

                  theController, Pointer to countryQBEController

 

 

I have locally made a small Change to ConversationUtils, Conversation and UIConversation which fixes my problem.  The basis of the change is a new method in ConversationUtils which determines the managed bean name based on the bean instantiated and what is defined in the ServletRequest.

 

        public static String getManagedBeanName(FacesContext context, Object myBean) throws ClassNotFoundException {

            String managedBeanName = null;

            HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();

           

            // lookup bean in request scope

            Enumeration requestAttributeNames = request.getAttributeNames();

            while (requestAttributeNames.hasMoreElements()) {

                String requestAttribute = (String) requestAttributeNames.nextElement();

                Object object = request.getAttribute(requestAttribute);

                if ( Class.forName(myBean.getClass().getName()).isInstance(object) ) {

                    managedBeanName = requestAttribute;

                    break;

                }

            }

 

            return managedBeanName;

        }       

 

Locally I have only implemented this for request scoped beans.  I did notice that the Conversation component seems to support Session Scoped Beans and that could be easily added if necessary.  I have tested this locally and have not found any issues so far.

 

I am attaching all three changed classes in the hopes that you would consider this change for the component.

 

Tom

 

 

     

 

Attachment: UIConversation.java
Description: Binary data

Attachment: Conversation.java
Description: Binary data

Attachment: ConversationUtils.java
Description: Binary data

Reply via email to