# Formulario referenciado (Grupoarticulo->Modelo)

## Formulario referenciado (Grupoarticulo->Modelo)

## Documentos Referenciados

Muchas ocasiones deseamos referenciar dos documentos, en los formularios usaremos un \<p:autocomplete> para obtener el documento referenciado.

![](https://2578941663-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lc1Wg6ze2c8GK7mFBZX%2F-Lc1WjGeqF4Ig-44ZLgX%2F-Lc1X8jZyIFH8-3KwBQJ%2Fbb6a928d-c4c4-4439-ab95-bc40403f2285.png?generation=1554820669347112\&alt=media)

![](https://2578941663-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lc1Wg6ze2c8GK7mFBZX%2F-Lc1WjGeqF4Ig-44ZLgX%2F-Lc1X8jaXOFFjjdwVWsC%2F8faaaca5-448e-4c28-ab95-3aefa45abb38.png?generation=1554820669353638\&alt=media)

## Definir los Entity

#### Grupoarticulo

```java
@Getter
@Setter
public class Grupoarticulo {

    @Id
    private String idgrupoarticulo;
    private String descripcion;
    private Double porcentajeventapublico;
    private Double porcentajeventacredito;
    private Integer redondeodecimales;
    private String activo;

    @Embedded
    private List<UserInfo> userInfo;

    public Grupoarticulo() {
    }

    @Override
    public String toString() {
        return "Grupoarticulo{" + "idgrupoarticulo=" + idgrupoarticulo + ", descripcion=" + descripcion + '}';
    }

}
```

#### Modelo

```java
@Setter
public class Modelo {

    @Id
    private String idmodelo;
    private String descripcion;
    @Referenced(documment = "Grupoarticulo", repository = "com.avbravo.ejbspard.ejb.GrupoarticuloRepository",
            field = "idgrupoarticulo",javatype = "String",lazy = false)
    private Grupoarticulo grupoarticulo;
    private String activo;


 @Embedded
    private List<UserInfo> userInfo;

    public Modelo() {
    }
 }
```

### Controller

Agregar el services del entity referenciado y generar los get/set. Se usuaran para el autocomplete.

```java
    @Inject
GrupoarticuloServices grupoarticuloServices;

 public GrupoarticuloServices getGrupoarticuloServices() {
        return grupoarticuloServices;
    }

    public void setGrupoarticuloServices(GrupoarticuloServices grupoarticuloServices) {
        this.grupoarticuloServices = grupoarticuloServices;
    }
```

### Formularios:

### new\.xthml, view\.xhtml

Agregar el autocomplete.

![](https://2578941663-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lc1Wg6ze2c8GK7mFBZX%2F-Lc1WjGeqF4Ig-44ZLgX%2F-Lc1X8jenmPZNdYvXKW1%2Ffe360a98-1bbd-42a3-a6bf-b67a88432f28.png?generation=1554820671194997\&alt=media)

### Segmento de codigo del autocomplete

```java
<p:outputLabel  value="#{msg['field.grupoarticulo']}"/>
 <p:autoComplete scrollHeight="250" dropdown="false" size="50"
                 emptyMessage="#{app['info.nohayregistros']}"
                 value="#{modeloController.modelo.grupoarticulo}"
                 completeMethod="#{modeloController.grupoarticuloServices.complete}"
                 var="p" itemLabel="#{p.descripcion}" itemValue="#{p}" forceSelection="true"> 
      <f:converter binding="#{grupoarticuloConverter}"/>
      <f:attribute name="field" value="descripcion" />

  </p:autoComplete>
```

### List.xhtml

Colocar en la columna un atributo que describa al documento referenciado,

```
    <p:column headerText="#{msg['field.grupoarticulo']}" 
                      sortBy="#{item.grupoarticulo.descripcion}"  filterMatchMode="contains" >
                   <h:outputText value="#{item.grupoarticulo.descripcion}" />
     </p:column>
```

![](https://2578941663-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lc1Wg6ze2c8GK7mFBZX%2F-Lc1WjGeqF4Ig-44ZLgX%2F-Lc1X8jiDueocLPCKm4d%2F5769d8b1-29b9-41ab-90d1-2143ed430f30.png?generation=1554820674156003\&alt=media)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://avbravo-2.gitbook.io/trucosjakartaee/overview/formularios/formulario-referenciado-grupoarticulo-modelo.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
