Modularising registration forms in JSF is possible?

1

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

My project has an @Entity Address and as the name suggests it is an entity responsible for storing data related to the real estate address, in this way, several other Entities have a relationship with this one, such as (eg a publisher has a real address as well as a client)

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

But I entered into the following dilemma ...

Each JSF form is attached to a ManagedBean, right? So, if I implement a publisher's registry I'll have:

  • An @Entity Publisher
  • A @ManagedBean EditoraBean
  • And an XHTML registration-editor.xhtml
  • My XHTML registration-editor.xhtml would give an include in the view responsible for the address right?

    And how would I then associate the attributes of the publisherBean.editora.endereco object with 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>
    

    Understand? After all, as I intend to modularize this view I can not associate the values of its inputs to the EditBean , but I would like to associate them even if I passed the ENDERECO object via parameter to the view and then retrieving the values to submit on the publisher page.

        
    asked by anonymous 21.03.2017 / 04:20

    1 answer

    1

    Oops Cleiton, in my system I did something in this sense, also with address. The only difference I saw from my idea for your example is that I've used taglibs ( link ).

    getting my tag:

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

    instead of yours:

    <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>
    

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

    I hope I have helped with something.

        
    29.03.2017 / 07:08