2 Replies Latest reply on Sep 23, 2008 11:10 AM by George Kokkinos

    action with s:convertEntity doesn't work

    George Kokkinos Newbie
      Hallo everyone.

      I'm using seam 1.2.1 GA and I'm facing the following problem.

      I'm trying to use a dropdownlist, an h:selectOneMenu with s:selectItems with s:convertEntity inside a form.When I hit the commandButton of my form the dropdown list (the h:selectOneMenu) of the form works fine (I am able to change my selection and get the corresponding entity using appropriate hash code only - did some digging before made it work), though the action associated with the commandButton is never called!

      I did various tests and came to conclusion that when the h:selectOneMenu is used along with the s:selectItems AND s:convertEntity and click the commandButton the only thing that happens is the convertion of the selection of the dropdown to the appropriate entity (I can see the appropriate sql in my console - I'm using jpa with hibernate) but the action that is associated with the commandButton is never called. No setter in my backing bean is called (my backing bean which is an EJB is never touched) and the action is not called. The page is just rerendered and the convertEntity does the call to the database to fetch the entity. Nothing else happens. When I remove the <s:convertEntity> tag, the form behaves as expected. All appropriate setters of the ejb are called (to fetch data from the form) and the action is called properly.

      If you want me to show you my code I'm more than happy to do so.

      Thanks in advance.
        • 1. Re: action with s:convertEntity doesn't work
          Nicklas Karlsson Master

          Show code.


          Add a h:messages to see if there are any validation errors.

          • 2. Re: action with s:convertEntity doesn't work
            George Kokkinos Newbie
            <h:messages> is already included in my page and no messages appear, neither jsf or log messages.

            Here is the code of the EJB which works as a backing bean for my page:
            @Name("testAction")
            @Stateful
            public class TestAction implements TestLocal {
                 
                   private String myString;

                 
                 @EJB
                 CategoryDAO categoryDAO;
                 
                 List<Category> primaryCategories = null;
                 
                 Category selectedCategory = null;
                 
                 public String myAction() {
                      return null;
                 }
                 
                 
                 public List<SelectItem> getStrings() {
                      return strings;
                 }
                 
                 @Create @Begin
                 public void init() {
                      primaryCategories = categoryDAO.getAllPrimaryCategories();
                 }
                 
                      
                 public void setMyString(String myString){
                      this.myString = myString;
                 }
                 
                 public String getMyString() {
                      return myString;
                 }
                 
                 @Remove @Destroy
                 public void destroty() {}


                 /**
                  * @return the primaryCategories
                  */
                 public List<Category> getPrimaryCategories() {
                      return primaryCategories;
                 }


                 /**
                  * @param primaryCategories the primaryCategories to set
                  */
                 public void setPrimaryCategories(List<Category> primaryCategories) {
                      this.primaryCategories = primaryCategories;
                 }


                 /**
                  * @return the selectedCategory
                  */
                 public Category getSelectedCategory() {
                      return selectedCategory;
                 }


                 /**
                  * @param selectedCategory the selectedCategory to set
                  */
                 public void setSelectedCategory(Category selectedCategory) {
                      this.selectedCategory = selectedCategory;
                 }
                 
            }

            The primaryCategories list (list of Category jpa entity) will feed the s:selectItems and the selectedCategory will be the one that the user will select in the page. The code of the <h:selectOneMenu> is the following:

            <h:selectOneMenu value="#{testAction.selectedCategory}" id="categSel">
                                     <s:selectItems value="#{testAction.primaryCategories}" var="cat" label="#{cat.description}"
                                     noSelectionLabel="Select..." hideNoSelection="true"/>
                                     <s:convertEntity/>
                                </h:selectOneMenu>

            And the complete code of the page:
            <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                            xmlns:s="http://jboss.com/products/seam/taglib"
                            xmlns:ui="http://java.sun.com/jsf/facelets"
                            xmlns:f="http://java.sun.com/jsf/core"
                            xmlns:h="http://java.sun.com/jsf/html"
                            xmlns:rich="http://richfaces.ajax4jsf.org/rich"
                            template="layout/template.xhtml">
                                  
            <ui:define name="body">
               
                <h:messages globalOnly="true" styleClass="message" id="globalMessages"/>
               
                <h:form id="dummyform" styleClass="edit">
               
                    <rich:simpleTogglePanel label="Currency search parameters" switchType="ajax">

                        <s:decorate template="layout/display.xhtml">
                            <ui:define name="label">A dummy String</ui:define>
                            <h:inputText value="#{testAction.myString}" id="myStringTxt"/>
                        </s:decorate>
            <s:decorate template="layout/display.xhtml">
                            <ui:define name="label">Select Category</ui:define>
                            <h:selectOneMenu value="#{testAction.selectedCategory}" id="categSel">
                                     <s:selectItems value="#{testAction.primaryCategories}" var="cat" label="#{cat.description}"
                                     noSelectionLabel="Select..." hideNoSelection="true"/>
                                     <s:convertEntity/>
                                </h:selectOneMenu>
                        </s:decorate>
                   
                    </rich:simpleTogglePanel>
                   
                    <div class="actionButtons">
                        <h:commandButton id="search" value="Search" action="#{testAction.myAction}"/>
                       
                    </div>
                   
                </h:form>

            </ui:define>

            </ui:composition>


            As I mentioned in my first message, when clicking on the <h:commandButton value="Search" action="testAction.myAction"/> the action myAction - method of the testAction bean - is never called.
            After removing just the <s:convertEntity/> everything works as expected and the myAction function is called properly.

            Thanks again.