Thanks again, Vangel!

I`m trying the simplest approach as described on the docs page (the choosing
colors example). But when the page renders, the form is displayed without
the select element.

If you could please have a look at my code, I`ll provide it here. I`ve kept
the domain in portuguese (my native language) to avoid any typos in the
transcription. But if necessary I could translate it.

The page class (NovoAtestado.java):

public class NovoAtestado {

    @Property
    private Atestado atestado;

    @Property
    private SelectModel contratanteSelectModel;

    @Property
    private Long selectedContratanteId = 1L;
    ...
    void setupRender(){
        List<Contratante> contratantes = contratanteDao.listaTodos();
        contratanteSelectModel = selectModelFactory.create(contratantes,
"nome");
     }
}

The page template (NovoAtestado.tml):
...
<t:beaneditform submitlabel="message:submit-label" object="atestado">
    <t:select t:id="contratantes" value="selectedContratanteId"
        model="contratanteSelectModel" />
</t:beaneditform>
...

The beaneditform main bean model (Atestado.java):

@Entity
public class Atestado {

    @NonVisual
    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private Long id;

    @ManyToOne
    private Contratante contratante;
    ...
}

The ManyToOne model (Contratante.java)

@Entity
public class Contratante {
    @NonVisual
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
     private Long id;

    private String nome;

    @Override
    public String toString() {
        return id.toString();
    }
}

Do you notice anything wrong? Thank you.

Eric Torti


On Sat, Aug 6, 2011 at 9:18 PM, Vangel V. Ajanovski <a...@ii.edu.mk> wrote:

> On 08/06/2011 04:46 PM, Eric Torti wrote:
>
>> The only doubt I still have is whether the<t:selectObject ...>  tag is
>> supposed to work nested inside the<t:beaneditform ...>  tag.
>>
> The bean model does not automatically create fields for the ManyToOne
> links, so they are not like standard part of the BeanEditForm, but I "add"
> virtual fields for them and proceed like this (just a piece of working tml
> in our app):
>
> <form t:type="beaneditform" t:id="newInstructor"
>                    t:submitlabel="message:save" t:exclude="instructorID"
>                    t:reorder="person, institution, fromDate, toDate"
>                    t:add="person,institution">
> <p:person>
> <t:label for="person" />
> <t:selectObject t:id="person" list="persons" value="newInstructor.person"
>                            labelField="literal:lastName '\s' firstName '\s'
> userName"
>                            keyField="literal:personId" blankOption="NEVER"
> />
> </p:person>
> <p:institution>
> <t:label for="institution" />
> <t:selectObject t:id="institution" list="institutions"
>                            value="newInstructor.**institution"
> labelField="literal:title"
>                            keyField="literal:**institutionId"
> blankOption="NEVER" />
> </p:institution>
> </form>
>
> But, have in mind that the doc from the wiki does not do all of what I
> said, as I have made some additional changes (like for example the
> "keyField"). But you can try to read the source carefully and customize it
> depending on what exactly you need.
>
>

Reply via email to