What I had to do was put the element I want to pre-select in the List in
index 0 of my ArrayList. The problem was I made all the logic for the first
element be on the position 0 and the rest in the Natural Sort Order.
Here is the code:
public static List<Empresa> ordenaEmpresasEspecial(List<Empresa>
empresas){ class OrdenaEmpresaPorDataCriacao implements
Comparator<Empresa> { @Override public int compare(Empresa o1,
Empresa o2) { Calendar dataO1 =
Calendar.getInstance(); Calendar dataO2 =
Calendar.getInstance(); dataO1.setTime(o1.getDtCadastro()); dataO2.setTime(o2.getDtCadastro());
boolean
o1After = dataO1.after(dataO2); if
(o1After){ //System.out.println("debug empresa "+o1.getNome()+"
depois de "+o2.getNome()); return -1; } else
{ //System.out.println("debug empresa "+o1.getNome()+" antes de
"+o2.getNome()); return 1; } } } // fim
classe Empresa empresaMaisRecente =
null; Collections.sort(empresas, new
OrdenaEmpresaPorDataCriacao()); empresaMaisRecente =
empresas.get(0); //System.out.println("debug empresa mais recente
minha data "+empresaMaisRecente.getDtCadastro()+ "
"+empresaMaisRecente.getNome()); Collections.sort(empresas); // de
volta na ordem natural alfabetica pelo nome de cada empresa //
ciclando nas "empresas" para pegar a empresa mais recente criada,
remove da posicao atual e recolocar na // no index 0 da List for
(int x = 0 ; x < empresas.size() ; x++){ Empresa e =
empresas.get(x); if (e.equals(empresaMaisRecente)){ // empresas
sao iguais pelo numero de id empresas.remove(x); // remove o
elemento empresas.add(0, empresaMaisRecente); // adiciona no
comeco //System.out.println("debug a Empresa mais recente foi
colocada em primeiro lugar (elemento 0 na
list)"); break; } } // end for return empresas; }
On Tue, Jun 21, 2016 at 9:44 AM, Christoph Nenning <
Christoph.Nenning@lex-com.net> wrote:
> >
> > Hi,
> >
> >
> > as far as I remember it is just about the name of <s:select />
> >
> > > <s:select id="empresas" list="empresas" listKey="id" listValue="nome"
> > > name="pessoaForm.empresa" label="Empresa" select="idDefaultSelection"
>
> > />*
> >
> > This means your action needs a member "pessoaForm.empresa" and that one
> > must be initialized with the preselected value.
> >
> > I don't think that you need the select attribute.
> >
>
>
> I got mail from Martin where he points out that you can use value
> attribute of select tag:
>
>
> <s:select .... value="defaultVal" ... />
>
>
> Of course you can use expressions to get it from action.
>
>
> Regards,
> Christoph
>
>
>
>
>
> >
> >
> >
> >
> > > From: Guilherme Bisconcini <guilherme.bisconcini@sefisa.com.br>
> > > To: user@struts.apache.org,
> > > Date: 20.06.2016 23:49
> > > Subject: How to pre-select a select combo box
> > >
> > > Hi,
> > >
> > > I'm trying to pre-select a select combo box, for 2 hours. No success.
> > Can
> > > anyone give some help?
> > >
> > > Here are the JSP file
> > > INIT >>>>> novaPessoa.jsp
> > >
> > > *<s:form id="formPessoa" action="registraNovaPessoa"
> theme="bootstrap"*
> > >
> > > * cssClass="well form-horizontal">*
> > >
> > >
> > > * <!-- Para montar objeto PessoaForm -->*
> > >
> > > * <s:bean name="br.com.xyz.portaria.controller.forms.PessoaForm"
> > > var="pessoaForm">*
> > >
> > >
> > > * ################## HERE ARE THE SELECTION COMBO
> BOX!*
> > >
> > > * <s:select id="empresas" list="empresas" listKey="id"
> listValue="nome"
> > > name="pessoaForm.empresa" label="Empresa" select="idDefaultSelection"
>
> > />*
> > >
> > > * <!-- Botao nova EMPRESA AJAX -->*
> > >
> > > * <sj:a id="buttonNovaEmpresa" href="novaEmpresa"
> targets="funcional">*
> > >
> > > * <button type="button" class="btn btn-warning">Nova Empresa</button>*
> > >
> > > * </sj:a>*
> > >
> > > * <br>*
> > >
> > > * <br>*
> > >
> > > * <s:textfield id="nome" label="Nome Pessoa" tooltip="O nome COMPLETO
> da
> > > pessoa!" name="pessoaForm.nome" placeholder="Nome"
> > > value="%{pessoaForm.nome}" />*
> > >
> > > * <s:textfield id="rg" label="RG" tooltip="RG pessoa, tudo junto sem
> > > espaços!" name="pessoaForm.rg" placeholder="RG"
> value="%{pessoaForm.rg}"
> > />*
> > >
> > > * </s:bean>*
> > >
> > > * <!-- Textfield de motivo -->*
> > >
> > > * <s:textarea label="Motivo" tooltip="Digite o MOTIVO QUE A PESSOA VEI
> > > FAZER AQUI!" placeholder="MOTIVO; VAI FALAR COM QUEM? FAZER O QUE?"
> > > name="motivoEntrada" cols="20" rows="3"/>*
> > >
> > >
> > > * <sj:submit value="Registrar Entrada" cssClass="btn btn-primary"*
> > >
> > > * targets="funcional" />*
> > >
> > >
> > >
> > >
> > > *</s:form>*
> > >
> > >
> > > END <<<<<<< novaPessoa.jsp
> > >
> > >
> > > The controller is nothing special, I have only a int declared
> > > "idDefaultSelection" with getter and setter who are supposed to send
> the
> > > parameter to the "select" option of the form above. What I'm doing
> > wrong?
> > >
> > > Thanks in advance
> > >
> > >
> > > Bisconcini
> >
> > This Email was scanned by Sophos Anti Virus
>
> This Email was scanned by Sophos Anti Virus
>
|