Is it possible to modularize JSF registration formularies?

Asked

Viewed 197 times

1

The question is this... although the problem does not involve JPA/ORM I find it interesting to contextualize.

My little project has a @Entity Addressee and as the name suggests it is an entity responsible for storing data related to real estate addresses, in this way, several other entities make relationships with this first one, such as the Client class and the Publisher class, etc... (For a publisher has a real address, as well as a client)

I thought then that maybe it would be possible to create a kind of VIEW in JSF called "view-addressee.xhtml" and it would contain all inputs that feed an entity of the address type, so I could give a INCLUDE in that view and load itthere wherever it is necessary to fill out address book.

But I entered a following dilemma...

Each JSF form is tied to a Managedbean, right? So, if I implement a publisher registration I will have :

  1. A @Entity Publishing house
  2. A @Managedbean Editorabean
  3. And a XHTML register-publisher.xhtml

My XHTML register-publisher.xhtml would give a include in the view responsible for addressee right?

And how then I would associate the attributes of the object editoraBean.editora.endereco to the VALUES of the JSF inputs of the "view-address.xhtml" ?

To illustrate, imagine a page like this:

<h:body>
    <h:form prependId="false">
        <p:growl id="msgs" showDetail="true" />
            <p:fieldset id="basic" legend="Editora" style="margin-bottom:20px">
              <h:panelGrid columns="2" cellpadding="10">
                  <p:outputLabel value="Nome: " for="txtEditora" />
                  <p:inputText id="txtEditora" value="#editoraBean.editora.nomeEditora}" />
              </h:panelGrid>
            </p:fieldset>

            <ui:include src="/restricted/fragments/contato.xhtml" />
            <ui:include src="/restricted/fragments/endereco.xhtml" />
     </h:form>
</h:body>

Do you understand? After all, how do I intend to modularize this view I cannot associate the values of its inputs to editoraBean, but I would like to associate them even if it were transmitting the ENDERECO object via parameter to the view and then retrieving the values of the view to give Submit on the publisher page.

1 answer

1


Opa Cleiton, in my system I did something in this sense, also with address. The only difference I saw from my idea to your example is that I used Taglibs (https://www.mkyong.com/jsf2/custom-tags-in-jsf-2-0/).

getting my tag:

<sga:enderecoListagem pessoa="#{empresaController.entidade}" />

in place of his:

<ui:include src="/restricted/fragments/endereco.xhtml" />

and for the address listing code, access is done as follows:

<ui:component>
    <p:dataTable id="enderecoLista" value="#{enderecoController.registrosDaPessoa(pessoa)}"
        paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}" var="endereco" paginator="true" rows="3"
        lazy="true" emptyMessage="Sem endereços!">
        (...) colunas
    </p:dataTable></ui:component>

realize that the attribute pessoa tag sga:enderecoListagem will be passed to my component, and then used in my address controller through the method enderecoController.registrosDaPessoa(pessoa).

I hope I’ve been of some help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.