Entity Converter - "value is not valid"
kariem Mar 10, 2008 2:28 AMJust 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>