1

xhtml:

<p:selectOneMenu id="tipo" value="#{chamadoBean.chamado.tipoChamado}" effect="drop" style="width:180px">
    <f:selectItem itemLabel="Tipo de Chamado" />
    <f:selectItems value="#{chamadoBean.tipoChamado}" var="tipo" itemValue="#{tipo}" itemLabel="#{tipo}" />
</p:selectOneMenu>

bean:

public List<String> getTipoChamado() {
    if (this.tipoChamado == null) {
        this.tipoChamado = new ArrayList<String>();
        this.tipoChamado.add("Reclamação");
        this.tipoChamado.add("Sugestão");
    }
    return tipoChamado;
}

button:

<h:commandButton action="#{chamadoBean.salvar}" value="Abrir Chamado" />

error: Validation Error: Value is not valid

When I use the p:commandButton from PrimeFaces, then it works, but it don't redirect the page. When I put ajax="false" in order to redirect, then I get the same error again.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
octavarium
  • 45
  • 1
  • 8
  • What's `chamadoBean.salvar` ? – Bhesh Gurung Oct 24 '11 at 21:00
  • @Bhesh: literally `callBean.save`. – BalusC Oct 24 '11 at 21:04
  • @caematos: The `` **should** have the same problem. When you said "it works", don't you *actually* mean "I don't see any error" or do you really mean "The action method is invoked"? – BalusC Oct 24 '11 at 21:07
  • it works! it saves perfect in mysql! but dont redirects the page. Also, when I use p:commandButton ajax="false" property the error comes again. weird – octavarium Oct 24 '11 at 21:22
  • Weird indeed, I can't reproduce your problem based on the code given so far. There must be more into the view which is disturbing the action. I only can't think of any possible causes. The error at least suggests that `#{chamadoBean.tipoChamado}` has somehow been changed during the submit. – BalusC Oct 25 '11 at 00:28
  • there is another way to do that ? i tryed a list of selectitems but give me: javax.faces.model.SelectItem cannot be cast to java.lang.String :( – octavarium Oct 25 '11 at 00:45
  • @BalusC maybe I can use a custom converter? I tryed but didnt worked: – octavarium Oct 25 '11 at 00:57
  • You don't need a `List` nor a `Converter` for a simple `List`. I suggest you to create a blank playground page, copy the relevant code in smallest possible form to there and then test it on that page. If it works, then I'd try gradually extending the page and the bean until you get the same setup as the original page. On every step, test it until the problem reappears again. – BalusC Oct 25 '11 at 01:00
  • I think that so... im really pissed off about it – octavarium Oct 25 '11 at 01:02
  • Is chamado.tipoChamado really a type of String? – sogukk Oct 25 '11 at 12:28
  • @BalusC i thought chamadoBean.chamado.tipoChamado should be a String while the selectitems (chamadoBean.tipoChamado) are a List of String?We are choosing one value from a list,right? – sogukk Oct 25 '11 at 14:02
  • Oh, the `chamadoBean.chamado.tipoChamado`. Look like so, the `p:commandButton` would otherwise also have failed. – BalusC Oct 25 '11 at 14:17
  • @BalusC , @sogukk Chamado class: `@Column(name = "tipo_chamado") private String tipoChamado;` – octavarium Oct 25 '11 at 16:34
  • @BalusC nice! it was an encoding problem. `` resolved. thanx!! – octavarium Oct 28 '11 at 07:53
  • @caematos +1 for stumping BalusC, even though he did provide help in finding the solution – bakoyaro Oct 28 '11 at 20:06
  • sorry but what is stumping ? lol – octavarium Oct 29 '11 at 03:46

2 Answers2

2

For me the problem was that the web server was forcing the default local enconding in the processing cycle. I had to change the webserver configuration file to force the use of the UTF-8 encoding.

In my case, I had to add the glassfish-web.xml file to my project and add the line

<parameter-encoding default-charset="UTF-8"/>
Yamada
  • 723
  • 6
  • 23
1

It was an encoding problem. <?xml version='1.0' encoding='ISO-8859-1' ?> resolved.

oers
  • 18,436
  • 13
  • 66
  • 75
octavarium
  • 45
  • 1
  • 8
  • Congrats on the solution. When you are able, please make sure to mark your answer as 'accepted' so that others might learn from your success. Cheers~ – Andrew Kozak Dec 21 '11 at 19:17