javaserverfaces
  1. javaserverfaces
  2. JAVASERVERFACES-1532

f:viewParam with required="true" problem when using field with f:ajax

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Duplicate
    • Affects Version/s: 2.0.2
    • Fix Version/s: None
    • Component/s: ajax
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      1,532
    • Status Whiteboard:
      Hide

      size_medium importance_large

      Show
      size_medium importance_large
    • Tags:

      Description

      Describing the content of the use case:
      welcome.xhtml having
      ...
      <h:body>
      <p>
      <h:link outcome="home" value="Welcome demo - CA">
      <f:param name="country" value="CA"/>
      </h:link>

      <h:link outcome="home" value="Welcome demo - US">
      <f:param name="country" value="US"/>
      </h:link>
      </p>
      </h:body>
      ...
      home.xhtml having
      ...
      <f:view>
      <f:metadata>
      <f:viewParam id="country" name="country"
      value="#

      {welcome.country}

      " required="true"
      requiredMessage="The 'country' parameter is missing.
      Invalid access for this page ...">
      </f:viewParam>
      </f:metadata>
      </f:view>
      <h:head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
      <title>Hello JSF 2! </title>
      </h:head>
      <h:body>

      <h:messages id="messages" style="color: red;"
      layout="table"/>

      <h:form id="form">

      <fieldset>
      <p>
      <h:outputLabel id="vip__Label" for="vip" value="Vip Lounge
      Access">
      </h:outputLabel>
      <h:selectOneRadio id="vip" layout="pageDirection"
      label="Vip Lounge Access"
      required="true" immediate="true"
      value="#

      {welcome.vip}

      ">
      <f:selectItem itemLabel="Yes" itemValue="true" />
      <f:selectItem itemLabel="No" itemValue="false" />
      <f:ajax execute="@this" render="@form :messages">
      </f:ajax>
      </h:selectOneRadio>

      </p>
      <p>
      <h:outputLabel id="name__Label" for="name" value="Name" >
      </h:outputLabel>

      <h:inputText id="name" value="#

      {welcome.name}" label="Name">
      <f:ajax execute="@this" render="name__Label :messages">
      </f:ajax>
      </h:inputText>
      </p>
      <div >
      <h:commandButton value="Hello"
      action="readback?faces-redirect=true&includeViewParams=true">
      <f:param name="country" value="#{param['country']}" />
      </h:commandButton>
      <h:commandButton value="Goodbye" immediate="true"
      action="#{welcome.goodbye}" />
      </div>
      </fieldset>

      </h:form>
      </h:body>
      ...

      Note the
      <f:param name="country" value="#{param['country']}" />
      indented in <h:commandButton> to hold the country viewParam .

      WelcomeBean.java

      @RequestScoped
      @ManagedBean(name = "welcome")
      public class WelcomeBean implements Serializable {

      Boolean vip;
      String country;
      String name;

      public WelcomeBean() {
      }

      public String getGreetings() { return "JSF2 Greetings!"; }

      public String goodbye() { ExternalContext ectx = FacesContext.getCurrentInstance().getExternalContext(); HttpSession session = (HttpSession) ectx.getSession(false); session.invalidate(); return "welcome?faces-redirect=true"; }

      public String getCountry() { return country; }

      public void setCountry(String country) { this.country = country; }

      @NotNull
      public Boolean getVip() { return vip; }

      public void setVip(Boolean vip) { this.vip = vip; }

      @NotNull
      @Size(min = 3, max = 20, message = "Invalid text length; must be between {min} and {max}")
      public String getName() { return name; }

      public void setName(String name) { this.name = name; }
      }

      readback.xhtml (not so relevant but posted for the sake of full use-case )
      <f:view>
      <f:metadata>
      <f:viewParam id="name" name="name"
      value="#{welcome.name}

      " required="true"
      requiredMessage="The name parameter is missing. Invalid
      access for this page ...">
      </f:viewParam>
      </f:metadata>
      </f:view>
      <h:head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
      <title>Readback JSF 2! </title>
      </h:head>
      <h:body>
      <h:form id="form">
      <p>'Welcome!' #

      {welcome.name}</p>
      <br/>
      <h:commandButton value="Goodbye" immediate="true"
      action="#{welcome.goodbye}" />
      </h:form>
      </h:body>

      While changing the value of the input fields with f:ajax attached behaviour you
      will end up with the error message
      The 'country' parameter is missing. Invalid access for this page ...

      This happens because the value of the viewParam a.k.a request param , is not
      carried over for post requests that result from f:ajax .

      I've concluded this issue could be resolved if f:ajax would support f:param as
      children .

      By association with richfaces, it is stated in many places that f:ajax is
      equivalent with a4j:support and I came across examples with nesting f:param in
      a4j:support tags.

      However if do something like this
      <h:inputText id="name" value="#{welcome.name}

      " label="Name">
      <f:ajax execute="@this" render="@form :messages">
      <f:param name="country" value="#

      {param['country']}" />
      </f:ajax>
      </h:inputText>
      the client ajax behaviour doesn't work ( the javascript API is not attached anymore)

      By association, since the following is possible

      <h:commandButton value="Hello" action="readback>
      <f:param name="country" value="#{param['country']}

      " />
      </h:commandButton>

      I beleive is essential to have the ability to add custom parameters to post
      requests generated from f:ajax. as well.

      Otherwise f:viewParam with required=�true� and f:ajax turn into exclusive
      features in same view.

        Issue Links

          Activity

          Hide
          Ed Burns added a comment -

          Move to 2.2 because spec issue is at 2.2

          Show
          Ed Burns added a comment - Move to 2.2 because spec issue is at 2.2
          Hide
          Manfred Riem added a comment -

          Linking it to the SPEC issue

          Show
          Manfred Riem added a comment - Linking it to the SPEC issue
          Hide
          Manfred Riem added a comment -

          Please vote for this issue at the SPEC tracker. Thanks.

          Show
          Manfred Riem added a comment - Please vote for this issue at the SPEC tracker. Thanks.
          Hide
          Ed Burns added a comment -
          Show
          Ed Burns added a comment - Will link to JAVASERVERFACES_SPEC_PUBLIC-742 .
          Hide
          Ed Burns added a comment -
          Show
          Ed Burns added a comment - Duplicates JAVASERVERFACES_SPEC_PUBLIC-742 .

            People

            • Assignee:
              Unassigned
              Reporter:
              movemountfuji
            • Votes:
              3 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: