1

Ok, I've been discusing this with my colleages, and we can't find if what we are doing is ok or not, supose you have this view,

<h:form id="UsuarioEditForm">
    <h:panelGroup id="display" styleClass="createPanelGrid">
        <p:panelGrid  columns="2">
            <p:outputLabel value="Nombre de Usuario: " for="nombreUsuario" />
            <p:inputText id="nombreUsuario" value="#{usuarioController.selected.nombreUsuario}" required="true" requiredMessage="Nombre requerido."/>
            <p:outputLabel value="Contraseña: " for="password" />
            <p:password id="password" value="#{usuarioController.selected.password}" required="true" requiredMessage="Contraseña requerida."/>
            <p:outputLabel value="Correo Electrónico: " for="email" />
            <p:inputText id="email" value="#{usuarioController.selected.email}" required="true" requiredMessage="Correo electrónico requerido."/>
            <p:outputLabel value="Tipo de Usuario: " for="tipoUsuario" />
            <h:selectOneMenu id="tipoUsuario" value="#{usuarioController.selected.tipoUsuario}" required="true" requiredMessage="Tipo de Usuario requerido." converter="#{tipoUsuarioConverter}">
                <f:selectItem itemLabel="Seleccionar..."/>
                <f:selectItems value="#{tipoUsuarioController.items}"
                 var="tipoUsuarioItem"  itemValue="#{tipoUsuarioItem}" itemLabel="#{tipoUsuarioItem.tipo}" />
            </h:selectOneMenu>
        </p:panelGrid>
        <p:separator></p:separator>
        <p:commandButton styleClass="ui-priority-primary" actionListener="#{usuarioController.save}" value="Guardar" update="display,:UsuarioListForm:datalist,:growl" oncomplete="handleSubmit(xhr,status,args,UsuarioEditDialog);"/>
        <p:commandButton value="Cancelar" type="button" onclick="UsuarioEditDialog.hide()"/>
    </h:panelGroup>
</h:form>

the main managed bean who control the whole operation is called usuarioController, this bean do the logic to insert a Usuario entity, but, this entity needs a TipoUsuario entity for correct insert, so we have another bean called tipoUsuarioController that get the list of TipoUsuario entity and display it in a selectOneMenu where the user choose one TipoUsuario, so, the question is simple, it's ok to call a bean just to perform the operation to get the TipoUsuario List?, or it's better to get the List inside the usuarioController bean? Which operation is the best for the application performance?.

Thanks,

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • possible duplicate of [Can I use multiple managed bean in the same xhtml page?](http://stackoverflow.com/questions/18919545/can-i-use-multiple-managed-bean-in-the-same-xhtml-page). Refer to the country example in the answer. – Luiggi Mendoza Nov 15 '13 at 19:41
  • ok, but lets say TipoUsuario is a list that can change a lot, if its applicationScoped bean, the list will change too? or I have to use ViewScoped to do the query again? – John Gamarra González Nov 15 '13 at 20:03
  • The fact that the `CountryBean` is `@ApplicationScoped` in my example doesn't mean it should be in your project/application as well. The scope of the bean is a totally different matter. – Luiggi Mendoza Nov 15 '13 at 20:05
  • Anyway, IMO if your list needs to change, use a `@ViewScoped` for your `TipoUsuarioController`. If is not going to change until the application needs a redeploy or you have a strategy about changing its values and being reflected in the whole app, use `@ApplicationScoped`. – Luiggi Mendoza Nov 15 '13 at 20:07
  • Precisely, thats my question, so its ok to have two `@ViewScoped` for example in the same xhtml page? in this case `UsuarioController` and `TipoUsuarioController` is this a good practice? and how about performance? – John Gamarra González Nov 15 '13 at 20:44
  • As you may see in my answer, you can have several beans in your page, regarding its scope. In my example I post three beans with different scope and it will work without problems. It is nor a good nor a bad practice, you just can do it and if it works for you, then do it. The only thing you should be aware is *how each managed bean behaves in the page, so it will be pretty neat or a really bad experience, based on how you have defined the beans* (directly copied from my answer). – Luiggi Mendoza Nov 15 '13 at 20:50
  • About performance, it will depend how you define the bean. IMO all the lists for dropdown components e.g. ` – Luiggi Mendoza Nov 15 '13 at 20:51
  • Got it, so its ok to have multiple `@ViewScoped` beans in the same xhtml page – John Gamarra González Nov 16 '13 at 13:24

0 Answers0