5 Replies Latest reply on May 22, 2007 10:33 AM by ector7280

    a4j:support strange events

    ector7280

      I'm using a selectOneRadio to modify a selectOneMenu and it almost works correctly except for some inconsistent behavior.
      I'm passing a paramter in the querystring and sometimes
      when I click the radio button the value will remain the same as the passed in value. For instance if I pass in a '3' when I click on the radio button whose value is '1', I'll get '3'. If I click again, then it turns to '1'. It seems like it's storing the initial value along with it's real value.
      Also, if some unrelated fields are empty the radio button value will not change when clicked. When I enter text in that unrelated field the value will change.
      Are these bugs or am I doing something wrong?

      Here's the facelets page:

      <f:view xmlns="http://www.w3.org/1999/xhtml"
       xmlns:s="http://jboss.com/products/seam/taglib"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:tr="http://myfaces.apache.org/trinidad"
       xmlns:rich="http://richfaces.ajax4jsf.org/rich"
       xmlns:a4j="https://ajax4jsf.dev.java.net/ajax">
      
       <html>
       <body>
      
       <h:messages globalOnly="true" styleClass="message" id="globalMessages" />
       <h:form id="vessel" styleClass="edit">
      
       <rich:panel>
       <f:facet name="header">Vessel Details</f:facet>
      
       <s:decorate id="vesselIdDecoration">
       <h:inputHidden id="vesselId" disabled="#{vesselHome.managed}"
       value="#{vesselHome.instance.vesselId}">
       <a4j:support event="onblur" reRender="vesselIdDecoration" />
       </h:inputHidden>
       </s:decorate>
       <h:outputText>
       <fieldset title="shipyard"><legend>Shipyard</legend> <a4j:outputPanel
       ajaxRendered="true">
       <h:panelGrid title="Shipyard Info">
       <h:outputLabel for="statusDecoration">
       <p align="right"><span class="required">*</span> Shipyard
       Status:</p>
       </h:outputLabel>
       [#{shipyardFilter.statusId}]
       <s:decorate id="statusDecoration">
       <h:selectOneRadio id="status" value="#{shipyardFilter.statusId}"
       styleClass="radio">
       <f:selectItem itemLabel="Open" itemValue="1" />
       <f:selectItem itemLabel="Closed" itemValue="2" />
       <f:selectItem itemLabel="Renamed" itemValue="3" />
       <a4j:support event="onclick" reRender="shipyard" />
       </h:selectOneRadio>
       </s:decorate>
      
       <a4j:region>
       <s:decorate id="shipyardDecoration">
       <h:selectOneMenu id="shipyard"
       value="#{vesselHome.instance.shipyard}" required="true">
       <s:selectItems value="#{shipyardFilter.shipyards}"
       var="shipyard" label="#{shipyard.name}" />
       <a4j:support event="onchange" reRender="location1" />
       <s:convertEntity />
       </h:selectOneMenu>
       </s:decorate>
       <f:subview id="location1">
       <ui:include src="VesselLocation.xhtml" />
       </f:subview>
       </a4j:region>
       </h:panelGrid>
      
       </a4j:outputPanel></fieldset>
       </h:outputText>
       <h:outputText>
       <table>
       <tr>
       <td><h:outputLabel for="vesselName">
       <p align="right"><span class="required">*</span> Name:</p>
       </h:outputLabel></td>
       <td><s:decorate id="vesselNameDecoration">
       <h:inputText id="vesselName" required="true" size="50"
       maxlength="50" value="#{vesselHome.instance.vesselName}">
       <a4j:support event="onchange" reRender="vesselNameDecoration" />
       </h:inputText>
       </s:decorate></td>
       </tr>
       </table>
       </h:outputText>
       </rich:panel>
      
       </h:form>
      
       </body>
      
       </html>
      
      </f:view>
      


      Here's the Seam bean:

      package gov.dot.marad.business.ejb;
      
      import gov.dot.marad.persistence.ejb.model.Shipyard;
      import gov.dot.marad.persistence.ejb.model.VesselHome;
      
      import java.util.List;
      
      import javax.ejb.Stateless;
      import javax.persistence.EntityManager;
      
      import org.jboss.seam.annotations.Factory;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.datamodel.DataModel;
      
      @Stateless
      @Name("shipyardFilter")
      public class ShipyardFilterAction implements ShipyardFilter
      {
       @Out
       private int statusId;
      
       private List<Shipyard> shipyards;
      
       @In(create = true)
       EntityManager entityManager;
      
      
       public EntityManager getEntityManager()
       {
       return entityManager;
       }
      
       public int getStatusId()
       {
       return this.statusId;
       }
       public void setStatusId(int statusId)
       {
       this.statusId = statusId;
      
       }
      
       @SuppressWarnings("unchecked")
       @DataModel
       public List <Shipyard> getShipyards()
       {
      
       shipyards = getEntityManager().createQuery(
       " select shipyard from Shipyard shipyard " +
       " where shipyard.shipyardStatus.statusId=:status")
       .setParameter("status", getStatusId()).getResultList();
      
       System.out.println("SHIPYARDFILTERACTION StatusId " + statusId);
       return shipyards;
       }
      
      
      
      }
      


        • 1. Re: a4j:support strange events
          alexsmirnov

          input field have "required" attribute. Empty field cause validation error and tell JSF to bypass update and application phases.

          • 2. Re: a4j:support strange events
            ector7280

            Hi, thanks. That explains part of the problem, or is that what is causing the initial value to be stored by the other radio buttons?
            Is there a way to have required fields on this page or should I just separate the two?

            • 3. Re: a4j:support strange events
              ector7280

              Well, I figured the required field part. Just needed to use a4j:region with
              renderRegionOnly="true".

              Does anyone have any ideas on why the query string value shows up on the other two radio buttons?

              Thanks,

              JR

              • 4. Re: a4j:support strange events
                ilya_shaikovsky

                sorry.. but seems I missed the sence of the last question. As far as I understand your first problem was solved.. So please describe please more carefully the next one..

                • 5. Re: a4j:support strange events
                  ector7280

                  OK, here is what is happening, I call my web page with a parameter on the query string like so:

                  page.seam?statusId=1

                  As I click the three radio buttons that are defined thusly:

                  <h:selectOneRadio id="status" value="#{shipyardFilter.statusId}"
                  <f:selectItem itemLabel="Open" itemValue="1" />
                  <f:selectItem itemLabel="Closed" itemValue="2" />
                  <f:selectItem itemLabel="Renamed" itemValue="3" />
                  <a4j:support event="onclick" reRender="shipyard" />
                  </h:selectOneRadio>
                  


                  When I click on Closed with value '2' sometimes I still get a #{shipyardFilter.statusId} of '1'.
                  If I click a second time, I get the correct value, '2'. This happens with "Renamed" as well.

                  The only one that works correctly is "Open", I guess because I passed in it's value '1'.

                  Hopefully I explained it more clearly this time. If not let me know.

                  Is this a bug?

                  Thanks,

                  JR