11 Replies Latest reply on Feb 14, 2007 1:18 PM by nfeybesse

    h:commandButton and h:commandLink don't delegate conversatio

      Hi All,

      I have the following problem. I have a conversation scoped bean:

      @Name("regionAction")
      @Scope(ScopeType.CONVERSATION)
      public class RegionAction implements Serializable {
      
       ...
      
       @In(required=false) @Out(required=false)
       private Generalarticle selectedArticle;
      
       /**
       * Current Region bean
       */
       @Out(required=false)
       @In(required=false)
       @DataModelSelection
       private RegionBean region;
      
       @DataModel
       private List<RegionBean> allRegions;
      
       @Factory("allRegions")
       @Begin(join=true)
       public void loadAllRegions() {
       m_logger.trace("Loading all regions");
       this.allRegions = em.createQuery("from RegionBean as r")
       .getResultList();
       }
      
       @Begin(join=true)
       public String selectRegion(RegionBean aRegion) {
       this.region = aRegion;
       m_logger.debug("Current region is set to " + region);
       return RESULT_SHOW_REGION;
       }
      
       public String submitEditGisArticle() {
       if ( null != this.region ) {
       if ( this.region.getGisArticle() == null) {
       this.selectedArticle = createGisArticle(region);
       } else if ( region.getGisArticle() != null ) {
       this.selectedArticle = this.region.getGisArticle();
       }
       } else {
       FacesMessages.instance().add("Region is not selected!");
       }
       m_logger.trace("submitEditGisArticle with #{selectedArticle} = #0", this.selectedArticle);
       return RESULT_EDIT_ARTICLE;
       }
      }
      


      From my understanding conversation begins with the factory method (which also seems to be backed up by logs)
      And I have the start page with the following:

      <s:link id="editLnk" value="#{message['edit']}"
       action="#{regionAction.submitEditGisArticle}" styleClass="texttoolbar" />


      In this case the result of regionAction.submitEditGisArticle leads me to the next page with the following:

      <h:form id="editForm">
       <h:inputText id="title" value="#{selectedArticle.title}" required="true"></h:inputText>
       <h:inputTextarea id="mainTextId" value="#{selectedArticle.text}" />
       <s:button id="submitBtn" value="save" action="success"></s:button>
      </h:form>
      <h:messages />
      


      Now, this works fine (I get both region and selectedArticle carried across the conversation). But as soon as I replace s:link on the first page with the h:commandButton (I tried h:commandLInk as well) like this:

      <h:form id="edtRgnArt">
       <h:commandButton value="#{message['edit']}" action="#{regionAction.submitEditGisArticle}" />
      </h:form>
      


      Then logs, debugging and h:messages show that region is null inside submitEditGisArticle

      Can anybody help with an advise what the problem might be?

      I use myfaces(tried 1.1.4 and 1.1.5)+facelets(tried 1.1.11 and 1.1.12)+ajax4jsf(tried 1.0.5 and 1.0.6)+seam(tried 1.1.0 and 1.1.0) in all cases with the same result - the region bean is null.

      Although the bean is null I still see this bean in a conversation context via debugger.xhtml:

      Conversation Context (2)
      allRegions
      em
      org.jboss.seam.core.conversation
      org.jboss.seam.core.facesMessages
      org.jboss.seam.core.persistenceContexts
      region
      regionAction



      Any help is appreciated!

        • 1. Re: h:commandButton and h:commandLink don't delegate convers

          I think I might have solved it. I was missing redirects on the jsf navigation and my entity bean name did not match the variable I used for bijection. I'll check tonight if the problem is indeed fixed.

          • 2. Re: h:commandButton and h:commandLink don't delegate convers
            kukeltje

            Read th fine, very fine manual. h:commandButton and link wil not propagate the conversation unless you configure it so (with the s:conversationpropagation)

            The manual is good, real good. 4 of the pittfalls I (personally) fell into were addressed in the docs, including this one. I (personally) found them by reading the docs...

            • 3. Re: h:commandButton and h:commandLink don't delegate convers

              Well I've spent some time reading the docs and looking what I could have done wrong and the docs say that

              "Any faces request (a JSF postback)"
              which is done by h:commandButton for example
              "will propagate the conversation context. By default, non-faces requests (GET requests, for example) do not propagate the conversation context"
              in which case you need to use conversationId to propagate the link.

              Which is why I was stumbled by conversation not propagating properly by JSF components that actually perform a JSF postback.

              And from what I understand s:conversationPropagation is needed "to begin and end conversation, or begin a nested conversation" and not just for propagating the conversation context further.

              Thanks for the pointers though. I appreciate any help.

              • 4. Re: h:commandButton and h:commandLink don't delegate convers
                gavin.king

                 

                Read th fine, very fine manual. h:commandButton and link wil not propagate the conversation unless you configure it so (with the s:conversationpropagation)


                This is not correct, JSF postbacks propagate the conversation.

                • 5. Re: h:commandButton and h:commandLink don't delegate convers
                  gavin.king

                  Please try the latest Seam CVS. I fixed

                  http://jira.jboss.org/jira/browse/JBSEAM-685

                  which looks like your problem.

                  • 6. Re: h:commandButton and h:commandLink don't delegate convers

                    Yes, Gavin, this very much looks like my problem. Although adding (I think) redirect and changing the entity component name (not sure which one) fixed the problem, again I think that it fixed it because it was 2am and I wasn't sure if it was real or I was already sleeping :)

                    So is really needed? I tried to find hard reference but only found that it helps to solve the back-button problem, although I am not (yet) sure how, but I am sure I'll come to that point :)

                    I'll try CVS anyway, thanks!

                    • 7. Re: h:commandButton and h:commandLink don't delegate convers

                       

                      "gavin.king@jboss.com" wrote:
                      Please try the latest Seam CVS. I fixed

                      http://jira.jboss.org/jira/browse/JBSEAM-685

                      which looks like your problem.


                      Yep that fixed it.

                      • 8. Re: h:commandButton and h:commandLink don't delegate convers
                        nfeybesse

                        Gavin,

                        I am not sure but I believe I have still the problem with JSF 1.2 in nested conversations...

                        • 9. Re: h:commandButton and h:commandLink don't delegate convers
                          gavin.king

                          I find that pretty difficult to believe. But if you think you have a bug, you need to create a very simple, stripped-down, easily runnable test case.

                          • 10. Re: h:commandButton and h:commandLink don't delegate convers
                            nfeybesse

                            Gavin,

                            My problem was with JSF1.2 and form enctype="multipart/form-data" wich seems to transmit incorrectly input datas if there isn't a file input component.

                            No problem with Myfaces.

                            Best Regards

                            • 11. Re: h:commandButton and h:commandLink don't delegate convers
                              nfeybesse

                              I think there is still a bug with <h:selectmanycheckbox> within <h:form enctype="multipart/form-data"> despite http://jira.jboss.org/jira/browse/JBSEAM-706

                              JBoss 4.0.5 / JSF 1.2 / Seam 1.1.6

                              Here is an example showing the bug and working without enctype="mulipart/form-data"


                              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                              <html xmlns="http://www.w3.org/1999/xhtml"
                               xmlns:ui="http://java.sun.com/jsf/facelets"
                               xmlns:h="http://java.sun.com/jsf/html"
                               xmlns:f="http://java.sun.com/jsf/core">
                              
                              <head>
                               <title>Manycheckbox and multipart error</title>
                              </head>
                              <body>
                               <f:view>
                               <div>
                               <h:form enctype="multipart/form-data">
                               <h:selectManyCheckbox value="#{errorAction.selectedErrors}">
                               <f:selectItems value="#{errorItems}" />
                               </h:selectManyCheckbox>
                               <h:commandButton action="#{errorAction.save}" value="Save"/>
                               <h:messages/>
                               </h:form>
                               </div>
                               </f:view>
                              </body>
                              </html>
                              


                              and POJO :

                              package com.genericsystem.error;
                              
                              import java.io.Serializable;
                              import java.util.Arrays;
                              import java.util.List;
                              
                              import javax.faces.model.SelectItem;
                              
                              import org.jboss.seam.annotations.Factory;
                              import org.jboss.seam.annotations.In;
                              import org.jboss.seam.annotations.Logger;
                              import org.jboss.seam.annotations.Name;
                              import org.jboss.seam.annotations.Out;
                              import org.jboss.seam.core.FacesMessages;
                              import org.jboss.seam.log.Log;
                              
                              @Name("errorAction")
                              public class ErrorAction implements Serializable {
                               private static final long serialVersionUID = 7654273335405896287L;
                              
                               @Logger Log log;
                              
                               @In(required=false) @Out(required=false)
                               List<SelectItem> errorItems;
                              
                               private List<String> selectedErrors;
                              
                               public List<String> getSelectedErrors() {
                               return (List<String>)Arrays.asList(new String[]{"Error1","Error2"});
                               }
                              
                               public void setSelectedErrors(List<String> selectedErrors) {
                               this.selectedErrors = selectedErrors;
                               }
                              
                               @Factory("errorItems")
                               public void findErrorItems(){
                               errorItems = (List<SelectItem>)Arrays.asList(new SelectItem[]{new SelectItem("Error1","Error1"),
                               new SelectItem("Error2","Error2"),new SelectItem("Error3","Error3"),new SelectItem("Error4","Error4")});
                               }
                              
                               public String save(){
                               FacesMessages.instance().add("save : ");
                               for (String error : selectedErrors){
                               log.info("************** selectedError : "+error+" ***************");
                               FacesMessages.instance().add("selectedError : "+error);
                               }
                               return "/error.xhtml";
                               }
                              
                              }
                              
                              


                              Best regards
                              Nicolas