ricardo_1977 Posted June 14, 2012 at 03:24 PM Report Share #462835 Posted June 14, 2012 at 03:24 PM Boas, eu tenho uma pagina jsp com uma select list onde quero que seja possivel fazer mais que uma selecao. depois vou num servlet quero receber os valores seleccionados. o problema é que so me devolve o ultimo valor seleccionado. aqui vai parte do codigo codigo jsp: <form action = "myservlet" method = "post"> .... <select name ="selectPaises" style="border:1px solid #58ACFA"> <option value ="" ><center></center></option> <option value="EU">Europa comunitaria</option> <option value ="TE">Toda a Europa</option> <% if(paises!=null) { Set<String> aux = paises.keySet(); for (String p: aux) { %> <option value="<%=p%>"> <%=p%> </option> <% } } %> </select> </form> .... codigo servlet: .... String[] listaPaises = request.getParameterValues("selectPaises"); ..... Link to comment Share on other sites More sharing options...
pmg Posted June 14, 2012 at 03:30 PM Report Share #462838 Posted June 14, 2012 at 03:30 PM Se a tua página está em HTML 4.01 tens de por multiple no select. <select name="selectPaises" style="whatever" multiple> <option>... ... </select> What have you tried? Não respondo a dúvidas por PM A minha bola de cristal está para compor; deve ficar pronta para a semana. Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código! Link to comment Share on other sites More sharing options...
ricardo_1977 Posted June 14, 2012 at 03:37 PM Author Report Share #462842 Posted June 14, 2012 at 03:37 PM isso so funciona se ao fazer a seleccao carregar no "ctrl" caso contrario so me devolve o ultimo na mesma Link to comment Share on other sites More sharing options...
pmg Posted June 14, 2012 at 03:43 PM Report Share #462847 Posted June 14, 2012 at 03:43 PM (edited) Ah! O que queres então é uma série de checkboxes ... <label><input type="checkbox" name="selectPaises[EU]">Europa Comunitaria</label> <label><input type="checkbox" name="selectPaises[TE]">Toda a Europa</label> ... Edit ... dentro dum div com altura fixa e que "scrolla" Edit2: se calhar tens que acertar o que está dentro das [] no nome das checkboxes para ficar compativel com Java Edited June 14, 2012 at 03:48 PM by pmg What have you tried? Não respondo a dúvidas por PM A minha bola de cristal está para compor; deve ficar pronta para a semana. Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código! Link to comment Share on other sites More sharing options...
ricardo_1977 Posted June 14, 2012 at 03:50 PM Author Report Share #462850 Posted June 14, 2012 at 03:50 PM Ah! O que queres então é uma série de checkboxes ... <label><input type="checkbox" name="selectPaises[EU]">Europa Comunitaria</label> <label><input type="checkbox" name="selectPaises[TE]">Toda a Europa</label> ... Edit ... dentro dum div com altura fixa e que "scrolla" Não, eu quero um select em que o utilizador possa escolher mais que uma opcao. uma especie de um select com uma lista de hobbies: cinema desporto PC etc e onde o utilizador possa escolher uma de que uma opcao. o problema é que o servlet so recolhe a ultima opcao seleccionada no select Link to comment Share on other sites More sharing options...
KTachyon Posted June 14, 2012 at 03:59 PM Report Share #462855 Posted June 14, 2012 at 03:59 PM Se a tua página está em HTML 4.01 tens de por multiple no select. <select name="selectPaises" style="whatever" multiple> <option>... ... </select> A forma correcta é com multiple="multiple". Penso que o ideal é utilizares uma das componentes desenvolvidas com JQuery UI, por exemplo: http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/ “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare Link to comment Share on other sites More sharing options...
pmg Posted June 14, 2012 at 05:02 PM Report Share #462881 Posted June 14, 2012 at 05:02 PM A forma correcta é com multiple="multiple". Talvez seja em XHTML ou XML ou HTML 1.042 ... Em HTML 4.01, como especificado no link submetido, a forma correcta é como eu coloquei (os browsers devem, alem de aceitar a forma correcta, aceitar a forma incorrecta que tu dizes ser correcta). What have you tried? Não respondo a dúvidas por PM A minha bola de cristal está para compor; deve ficar pronta para a semana. Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código! Link to comment Share on other sites More sharing options...
KTachyon Posted June 14, 2012 at 06:36 PM Report Share #462904 Posted June 14, 2012 at 06:36 PM Pois, mas o multiple="multiple" é mais portável, pelo que deve ser considerada a abordagem correcta, independentemente da forma como os browsers lidam com a questão. “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare Link to comment Share on other sites More sharing options...
pmg Posted June 14, 2012 at 08:50 PM Report Share #462934 Posted June 14, 2012 at 08:50 PM Tambem o ingles e mais portavel que o portugues, pelo que toda a gente deve usar "mouse" em vez de "rato" independentemente de quem esta a ouvir 🙂 What have you tried? Não respondo a dúvidas por PM A minha bola de cristal está para compor; deve ficar pronta para a semana. Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código! Link to comment Share on other sites More sharing options...
pmg Posted June 14, 2012 at 09:26 PM Report Share #462940 Posted June 14, 2012 at 09:26 PM (edited) Em HTML 5, com o DOCTYPE "<!DOCTYPE html>" a sintaxe do <select> é a mesma do que para HTML 4.01 ("<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">") http://www.w3.org/TR/2012/WD-html5-20120329/the-select-element.html#the-select-element Eu acho estranho alguem fazer, por exemplo, uma pagina assim: <!DOCTYPE html> <html> <head><title>hello world</title></head> <body><p>Hello<br/>world</p></body> </html> Aquele <br/>, a meu ver, esta completamente deslocado Edited June 14, 2012 at 09:26 PM by pmg What have you tried? Não respondo a dúvidas por PM A minha bola de cristal está para compor; deve ficar pronta para a semana. Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código! Link to comment Share on other sites More sharing options...
KTachyon Posted June 14, 2012 at 10:28 PM Report Share #462951 Posted June 14, 2012 at 10:28 PM Mas aqui não é exactamente uma questão de linguagens diferentes. Em português podes dizer "fila" ou "bicha", o que não quer dizer que ambas sejam interpretadas por toda a gente da mesma forma. 🙂 “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare Link to comment Share on other sites More sharing options...
ricardo_1977 Posted June 15, 2012 at 10:57 AM Author Report Share #463018 Posted June 15, 2012 at 10:57 AM continua a nao funcionar. Link to comment Share on other sites More sharing options...
KTachyon Posted June 15, 2012 at 12:17 PM Report Share #463055 Posted June 15, 2012 at 12:17 PM Mas o que é que não funciona? A selecção múltipla, ou a recepção dos itens seleccionados? “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare Link to comment Share on other sites More sharing options...
ricardo_1977 Posted June 15, 2012 at 12:36 PM Author Report Share #463061 Posted June 15, 2012 at 12:36 PM Mas o que é que não funciona? A selecção múltipla, ou a recepção dos itens seleccionados? Se fiser com as checkboxes ja funciona. se puser em selects é que ja nao funciona.Só guarda o ultimo item seleccionado. se calhar vai ficar com as checkboxes embora em termos esteticos nao me agrade muito Link to comment Share on other sites More sharing options...
KTachyon Posted June 15, 2012 at 01:06 PM Report Share #463064 Posted June 15, 2012 at 01:06 PM Chegaste a ver aquilo que coloquei anteriormente? http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/ “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare Link to comment Share on other sites More sharing options...
ricardo_1977 Posted June 15, 2012 at 03:13 PM Author Report Share #463117 Posted June 15, 2012 at 03:13 PM vou ver isso com mais tempo. de qualquer das formas para esta fase fica resolvido com checkboxes que assim ja consigo avancar. esta questao estava -me a encravar o resto da aplicação. mais tarde vejo o que me mandaste e caso resolva de outra forma posto aqui a solução. gracias Link to comment Share on other sites More sharing options...
KTachyon Posted June 15, 2012 at 07:24 PM Report Share #463165 Posted June 15, 2012 at 07:24 PM Não irá ser exactamente uma solução, porque a solução já aqui foi dada. O problema é que tu não queres o comportamento comum do select, daí que precisas efectivamente de utilizar uma componente que implemente o comportamento que tu queres (ou implementares tu a tua própria componente). Existem centenas e funcionam perfeitamente bem. Lembra-te que, com checkboxes, a implementação é radicalmente diferente da implementação para o select, pelo que aquilo que estás a desenvolver agora para as checkboxes não deverá ser directamente compatível com a versão com o select. Quando fores fazer a alteração tens que ter isso em conta. “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now