1 2 3 Previous Next 31 Replies Latest reply on Jan 24, 2013 5:42 PM by strenkor

    Entity Converter - "value is not valid"

    kariem

      Just a question, whether this is a bug or not. The documentation (look for s:convertEntity) says



      If you want to use more than one entity manager with the entity converter, you can create a copy of the entity converter for each entity manager in components.xml

      You should then use <f:converter converterId="myEntityConverter" /> instead of <s:convertEntity/>.


      I have two entity managers, but I only want to use one with the entity converter. So I used the standard notation.


      The problem: whenever I selected an item in my selectOneMenu I received a validator message value is not valid. It took a long time to figure out the reason for the problem.


      Could perhaps the documentation be updated, to be a little bit more precise? The main issue for me is that it works for forms where I use EntityHomes, but does not work for another form (shown below)


      There are two things that may deviate from the standard in the application and this other form:



      • I use hibernate sessions. The second hibernate session is only used in a special case (unrelated to the form where it does not work).

      • The form in question uses two s:selectItems inside a h:selectOneMenu



      components.xml:


      <persistence:managed-persistence-context name="entityManager"
           auto-create="true"
           persistence-unit-jndi-name="java:/amonEntityManagerFactory" />
      <factory name="hibernateSession" scope="STATELESS" auto-create="true"
           value="#{entityManager.delegate}" />
           
      <persistence:managed-persistence-context name="queryEntityManager"
           auto-create="true"
           persistence-unit-jndi-name="java:/amonEntityManagerFactory" />
      <factory name="querySession" scope="STATELESS" auto-create="true"
           value="#{queryEntityManager.delegate}" />



      EntityHome-based form (works with s:convertEntity)


      <h:form id="editRole">
        <rich:panel>
        <table >
          …
          <s:fragment rendered="#{currentRole.id != 1}">
            <s:decorate template="#{theme.editNV}">
              <ui:define name="label">Restrict To</ui:define>
              <h:selectOneMenu id="selectRole" required="false" value="#{currentRole.restrictedTo}">
                <s:selectItems value="#{allEnvTypes}" var="type" label="#{type.name}"
                  noSelectionLabel="No restriction" />
                <s:convertEntity />
              </h:selectOneMenu> 
            </s:decorate>
          </s:fragment>
          …
        </table>
        </rich:panel>
      
        <s:fragment rendered="#{roleHome.managed}">
          <h:commandLink action="#{roleHome.update}" value="Update role" rendered="#{roleHome.managed}"/>
          <rich:spacer width="10pt"/>
          <s:link action="#{roleHome.remove}" value="Delete role" rendered="#{roleHome.managed}"/>
        </s:fragment>
        
        <s:fragment rendered="#{!roleHome.managed}">
          <h:commandLink action="#{roleHome.persist}" value="Create role" rendered="#{!roleHome.managed}"/>
        </s:fragment>
        <rich:spacer width="20pt"/>
        <s:link view="/manage/roles.xhtml" value="Cancel"/>
        …
      </h:form>



      Form that does not work with s:convertEntity


      <h:form id="selectQuery">
        …
        <h:outputText value="Query Environment " />
        <h:selectOneMenu id="searchQuery" value="#{searchQuery}" rendered="#{showQueries}" required="true">
          <s:selectItems value="#{simpleQueries}" var="q" label="#{q.name}: #{q.description}"  />
          <s:selectItems value="#{globalQueries}" var="q" label="[global] #{q.name}: #{q.description}" />
          <!-- used to have s:convertEntity at this line -->
          <f:converter converterId="entityConverter" />
        </h:selectOneMenu>
        <h:selectOneMenu id="searchQueryDisabled" rendered="#{!showQueries}" disabled="true">
          <f:selectItem itemLabel="No queries available" itemValue="0" />
        </h:selectOneMenu>
        <h:commandButton value="Execute" disabled="#{!showQueries}" action="#{environmentQuerySearch.execute}" />
      </h:form>


        • 1. Re: Entity Converter - "value is not valid"
          kariem

          My post must have been too long, or it's because Pete was on vacation. I'll try again in fewer sentences.


          For more than one entity manager (or hibernate session), it should be sufficient to use <s:convertEntity/>, if only one entity converter component is configured. This works for some pages, but for others it does not (see previous post)


          I would like to raise a bug on this, but I don't know how it was intended to work. Should I raise it on the documentation, or rather on JSF integration? Did anyone have a similar problem?

          • 2. Re: Entity Converter - "value is not valid"
            pmuir

            Override equals() and hashCode() on the entity.


            Or make sure you are using the same persistence context through the whole form (for loading the list, for loading the value and for  entity converter).

            • 3. Re: Entity Converter - "value is not valid"
              kariem

              Override equals() and hashCode() on the entity.


              Does not help.



              Or make sure you are using the same persistence context through the whole form (for loading the list, for loading the value and for  entity converter).


              That worked, thank you for the advice!


              I was not aware that the list loading ran through the same persistence context (it is injected into a service class that is used for all use cases in this part of the implementation). I set it to null to see where it was used.


              Now it's clear to me. This is definitely not a bug, just bad implementation on my side.

              • 4. Re: Entity Converter - "value is not valid"
                todd.nash

                Kariem,


                I have the same issue with my converter. What did you do on your entity to make sure you were using the same persistence context?


                Thanks.

                • 5. Re: Entity Converter - "value is not valid"
                  kariem

                  Todd,


                  My secondary persistence context is injected into my DAO objects via setter injection (in components.xml instead of using @In). I have set the injected context variable for this persistence context to be null, so that any access to it throws a null pointer exception.


                  My menu contains two lists from which the user may select: simpleQueries and globalQueries which are both provided via @DataModel from one of my service classes.


                  <h:selectOneMenu id="searchQuery" value="#{searchQuery}" rendered="#{showQueries}" required="true">
                    <s:selectItems value="#{simpleQueries}" var="q" label="#{q.name}: #{q.description}"  />
                    <s:selectItems value="#{globalQueries}" var="q" label="[global] #{q.name}: #{q.description}" />
                    <s:convertEntity />
                  </h:selectOneMenu>
                  



                  With this approach I found out, that the service class used the DAO with the secondary persistence context.


                  This would have been ok, but we introduced this secondary persistence context (after initial design) only for special preview queries, and did not really check whether the DAO was already accessed from other service interfaces.


                  Sorry for the late reply, I hope this could help you.

                  • 6. Re: Entity Converter - "value is not valid"
                    german.otero

                    Pete Muir wrote on Mar 12, 2008 11:08 AM:


                    Or make sure you are using the same persistence context through the whole form (for loading the list, for loading the value and for  entity converter).


                    Please can you put an example, or explain what is the same persistence context.


                    I have my Crud. And when i go to the create page, i have a h:selectManyListbox ..... with the s:convertEntity
                    when i select an intem i got the Value is not valid error. I have only one Persistence context in the hole app.


                    Tnks

                    • 7. Re: Entity Converter - "value is not valid"
                      kariem

                      German,


                      My problem occurred in an environment where two persistence contexts were used in a single page. That's why Pete recommended only using one context when using the generic entity converter. If you have only one persistence context, your error has a different reason.


                      I understand your problem: the error message is not really helpful in locating the reason. This should definitely be improved.


                      Try searching this forum for convertEntity. You should also have a look at the FAQ, especially this entry. Pete's advice in his comment on this thread was also helpful.

                      • 8. Re: Entity Converter - "value is not valid"
                        pmuir

                        Kariem Hussein wrote on Mar 20, 2008 07:09 AM:


                        My problem occurred in an environment where two persistence contexts were used in a single page. That's why Pete recommended only using one context when using the generic entity converter. If you have only one persistence context, your error has a different reason.


                        No, it can occur with one SMPC in use - but the PC may be closed and a new one created. Anyway, read the FAQ.



                        I understand your problem: the error message is not really helpful in locating the reason. This should definitely be improved.

                        This error message is created by JSF, not us. Not sure if it can really be improved easily. What sort of error message would you like?

                        • 9. Re: Entity Converter - "value is not valid"
                          kariem

                          Pete Muir wrote on Mar 25, 2008 10:59 AM:



                          Kariem Hussein wrote on Mar 20, 2008 07:09 AM:


                          My problem occurred in an environment where two persistence contexts were used in a single page. That's why Pete recommended only using one context when using the generic entity converter. If you have only one persistence context, your error has a different reason.


                          No, it can occur with one SMPC in use - but the PC may be closed and a new one created. Anyway, read the FAQ.


                          Sorry, my statement was not clear.


                          The error message is displayed, if the selected object is not in the list of objects that are available for selection. I wanted to point out that the reason for this in German's case is different than in my case: I had used two different PCs, but I could not really identify the problem in German's case. Evidently it could not have been raised because of two persistence contexts being used while preparing the response.


                          This error message is created by JSF, not us. Not sure if it can really be improved easily. What sort of error message would you like?


                          I am really not sure, but I think that logging an error message to WARN would be adequate. A stack trace and a short pointer would have helped me with my search for the reason. In my case, both options in the FAQs (old, new) could not even give me a hint. In my case the converter was used to construct a menu: validation messages were not displayed.


                          The error message should indicate which component and converter (name?) was involved in raising this problem. It would also be a great improvement, if the documentation elaborated a little on how the entity converter actually works.


                          While tracing the problem, I was not aware that the introduction of a new EM could be the reason.

                          • 10. Re: Entity Converter - "value is not valid"
                            pmuir

                            Kariem Hussein wrote on Mar 25, 2008 01:44 PM:



                            This error message is created by JSF, not us. Not sure if it can really be improved easily. What sort of error message would you like?


                            I am really not sure, but I think that logging an error message to WARN would be adequate. A stack trace and a short pointer would have helped me with my search for the reason. In my case, both options in the FAQs (old, new) could not even give me a hint. In my case the converter was used to construct a menu: validation messages were not displayed.

                            The error message should indicate which component and converter (name?) was involved in raising this problem.


                            Ok, please raise an issue for this on the javaserverfacesspec issue tracker, and we can chase it up in the EG.


                            It would also be a great improvement, if the documentation elaborated a little on how the entity converter actually works.

                            While tracing the problem, I was not aware that the introduction of a new EM could be the reason.


                            Raise a JIRA task issue with a patch for what you would like to see, or update the FAQ.

                            • 11. Re: Entity Converter - "value is not valid"
                              kariem

                              Pete, thank you very much.



                              Pete Muir wrote on Mar 28, 2008 01:30 PM:

                              Ok, please raise an issue for this on the javaserverfacesspec issue tracker, and we can chase it up in the EG.

                              Sorry, I did not know where to raise this on the JSF spec issue tracker, could you provide a link? For now, I have raised it on JSF controls: JBSEAM-2788. Please close it, if it does not fit.



                              Raise a JIRA task issue with a patch for what you would like to see, or update the FAQ.


                              I added a patch, hoping I could communicate my point: JBSEAM-2789.

                              • 12. Re: Entity Converter - "value is not valid"
                                pmuir
                                • 13. Re: Entity Converter - "value is not valid"
                                  vladimir.kovalyuk

                                  Could someone please point me out the URL where I can download the source code for jsf-api.jar and jsf-impl.jar?
                                  Implementation-Version: 1.2_04-b16-p02
                                  Is the source code open for all?


                                  The problem in my case doesn't reproduce constantly. I see the message value is not valid from time to time. It's ok for most instances of some entity, but for a few it causes validation error.
                                  So I need to investigate the context when the error occurs.


                                  My hashCode() returns entity's id, and equals() compares entities by id.
                                  I use Seam-managed persistence context and it's the only context in my app.

                                  • 14. Re: Entity Converter - "value is not valid"
                                    baz

                                    Please look here
                                    FAQ FOR JSF


                                    And for JSF look here: JSF

                                    1 2 3 Previous Next