title: JSF 2 sending parameters via URL
body: <p>I'm trying to send parameter via URL and it fails, because I somewhat can't assign value to the bean or I can't concat value with URL string. By the way when I write color value by hand everything works, for example: </p>
  
  <pre><code>    &lt;h:button outcome="viewParams?c=red"/&gt;
  </code></pre>
  
  <p>This is the page code from which I'm trying to send parameter.</p>
  
  <pre><code>                &lt;h:form&gt;
                      &lt;h:selectOneMenu value="#{viewMngr.selectedColor}"&gt;
                          &lt;f:selectItems value="#{viewMngr.colors}" var="c"
                              itemLabel="#{c}" itemValue="#{c}" /&gt;
                          &lt;f:ajax listener="#{viewMngr.valueChanged}" /&gt;
                      &lt;/h:selectOneMenu&gt;
                      &lt;h:button outcome="viewParams?c=#{viewMngr.selectedColor}"/&gt;
                  &lt;/h:form&gt;
  </code></pre>
  
  <p>This is viewManager bean code (as far as I can see bean value is set, because I'm able to print it out)</p>
  
  <pre><code>@ManagedBean
  public class ViewMngr {
  private ArrayList&lt;String&gt; colors = new ArrayList&lt;String&gt;();
  
  private String selectedColor;
  
  public ViewMngr()
  {
      getColors().add("red");
      getColors().add("green");
      getColors().add("blue");
      getColors().add("gray");
      getColors().add("yellow");
      getColors().add("orange");
  }
  
  
  public ArrayList&lt;String&gt; getColors() {
      return colors;
  }
  
  public void setColors(ArrayList&lt;String&gt; colors) {
      this.colors = colors;
  }
  
  public String getSelectedColor() {
      return selectedColor;
      }
  
  public void setSelectedColor(String selectedColor) {
      System.out.println("Selected color: " + selectedColor);
      this.selectedColor = selectedColor;
  }
  
  public void valueChanged() {
      System.out.println("Value changed!");
  }
  }
  </code></pre>
  
  <p>Now here is the code from second page which tries to catch that parameter:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"&gt;
  
              &lt;f:metadata&gt;
                  &lt;f:viewParam name="c" value="#{color.color}"/&gt;
              &lt;/f:metadata&gt;
  
              &lt;h:body style="background-color:#{color.color}"&gt;
                &lt;fieldset&gt;
                  &lt;h:form&gt;
                    &lt;h:outputText value="Some text!"/&gt;
                  &lt;/h:form&gt;
                &lt;/fieldset&gt;
              &lt;/h:body&gt;
      &lt;/html&gt;
  </code></pre>
  
  <p>And here is color bean:</p>
  
  <pre><code>@ManagedBean
  public class Color {
  private String color;
  
  public String getColor() {
  
      return color;
  }
  
  public void setColor(String color) {
      if(color != null)
          System.out.println(color);
      this.color = color;
  }
  }
  </code></pre>