6 Replies Latest reply on Mar 8, 2010 2:02 PM by Philip Maiwald

    trouble passing argument to s:link action

    Brian Johnson Newbie
      Using: Seam 2.2.0.GA, IceFaces 1.8.2, Weblogic 10.3

      Have the following excerpt in an .xhtml file:

      <ice:dataTable id="dataSortData"
                               sortColumn="#{vehicleList.sortColumnName}"
                               sortAscending="#{vehicleList.ascending}"
                               value="#{vehicleList.vehicles}" var="item">

                               <ice:column>
                                    <f:facet name="header">
                                         <ice:commandSortHeader
                                              columnName="#{vehicleList.vehicleIdColumnName}" arrow="true">
                                              <ice:outputText value="#{vehicleList.vehicleIdColumnName}" />
                                         </ice:commandSortHeader>
                                    </f:facet>
                                    <s:link id="link1" action="#{vehicleProfileAction.showVehicleProfile(item)}" value="#{item.vehicleId}">
                                         <f:param name="vehicleId" value="#{item.vehicleId}" />
                                    </s:link>
                               </ice:column>

      In the various columns, the item.whatever data is displaying just fine.  If I click the link, I successfully get in to the showVehicleProfile function, but the argument is null.  Here's a snippet of the Java code:

      @Name("vehicleProfileAction")
      public class VehicleProfileAction
      {
           @In
           private WebUser webUser;
           
           @Out(required=false)
           private VehicleBean vehicle;
           
           @RequestParameter
           private long vehicleId;

           public void showVehicleProfile(VehicleBean item)
           {
                if (item != null)

      I've tried to adhere to the policy of including a minimum amount of code... so, let me know if there's more info you need.  If I swap out the ice: tags with plain ole h: tags, the behavior is the same.  I'm assuming I'm missing some critical piece of config, but darned if I know what it is.

      Thanks in advance for pointing me in the right direction.

      --b.
        • 1. Re: trouble passing argument to s:link action
          Shervin Asgari Master

          I think you are missing the form element?

          • 2. Re: trouble passing argument to s:link action
            Brian Johnson Newbie
            The dataTable is wrapped in a simple <ice:form> tag.
            • 3. Re: trouble passing argument to s:link action
              Brian Johnson Newbie
              At the risk of including too much information, this is a snippet from my pom.xml:

                        <dependency>
                             <groupId>org.jboss.seam</groupId>
                             <artifactId>jboss-seam</artifactId>
                             <version>${seam-version}</version>
                             <exclusions>
                                  <exclusion>
                                       <groupId>javax.servlet</groupId>
                                       <artifactId>servlet-api</artifactId>
                                  </exclusion>
                             </exclusions>
                        </dependency>
                        <dependency>
                          <groupId>org.jboss.seam</groupId>
                          <artifactId>jboss-seam-ui</artifactId>
                          <version>${seam-version}</version>
                        </dependency>


                        <dependency>
                             <groupId>org.icefaces</groupId>
                             <artifactId>icefaces</artifactId>
                             <version>${icefaces-version}</version>
                             <exclusions>
                                  <exclusion>
                                       <groupId>javax.servlet</groupId>
                                       <artifactId>servlet-api</artifactId>
                                  </exclusion>
                             </exclusions>
                        </dependency>

                        <dependency>
                             <groupId>org.icefaces</groupId>
                             <artifactId>icefaces-comps</artifactId>
                             <version>${icefaces-version}</version>
                        </dependency>

                        <dependency>
                             <groupId>org.icefaces</groupId>
                             <artifactId>icefaces-facelets</artifactId>
                             <version>${icefaces-version}</version>
                             <exclusions>
                                  <exclusion>
                                       <groupId>javax.servlet</groupId>
                                       <artifactId>servlet-api</artifactId>
                                  </exclusion>
                                  <exclusion>
                                       <groupId>javax.el</groupId>
                                       <artifactId>el-api</artifactId>
                                  </exclusion>
                             </exclusions>
                        </dependency>


              And my faces-config:

              <?xml version='1.0' encoding='UTF-8'?>
              <!DOCTYPE faces-config PUBLIC
                      "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
                      "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
              <faces-config>
                 
                   <application>
                        <locale-config>
                            <default-locale>en</default-locale>
                        </locale-config>
                      <view-handler>com.icesoft.faces.facelets.D2DSeamFaceletViewHandler</view-handler>
                   </application>

              </faces-config>
              • 4. Re: trouble passing argument to s:link action
                Brian Johnson Newbie

                A bit more information... if in the action EL expression, I replace item with a literal string, the string successfully gets passed as an argument to the function.


                I'm not sure what that tells us other than, at least on some level, the Seam EL extensions are actually being used as I can pass an argument to the method binding.  But, for some reason, it's unable to resolve item.  I tried renaming item, in case it was some special reserved word, but still got a null.  I got this idea from the booking example...




                            <ice:dataTable id="hotels" value="#{hotels}" var="hot" rendered="#{hotels.rowCount>0}">
                                <h:column>
                                    <f:facet name="header">Name</f:facet>
                                    <ice:outputText id="name" value="#{hot.name}" onmouseovereffect="#{highlight}"/>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">Address</f:facet>
                                    <ice:outputText id="address" value="#{hot.address}" onmouseovereffect="#{highlight}"/>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">City, State</f:facet>
                                    <ice:outputText id="city" value="#{hot.city}, #{hot.state}, #{hot.country}" onmouseovereffect="#{highlight}"/>
                                </h:column> 
                                <h:column>
                                    <f:facet name="header">Zip</f:facet>
                                    <ice:outputText id="zip" value="#{hot.zip}" onmouseovereffect="#{highlight}"/>
                                </h:column>
                                <h:column>
                                    <f:facet name="header">Action</f:facet>
                                    <s:link id="viewHotel" value="View Hotel" action="#{hotelBooking.selectHotel(hot)}"/>
                                </h:column>
                            </ice:dataTable>





                So, I'm assuming it is actually possible to pass the var from dataTable as an argument this way... just not sure what I'm missing.

                • 5. Re: trouble passing argument to s:link action
                  Stuart Douglas Master

                  Use a h:commandLink so the form is submitted and it should work. I think that it is not so much a bug as a limitation of the JSF architecture (you need to restore the view to get the correct value for the parameter, which will not happen on GET requests, not 100% sure about this though).

                  • 6. Re: trouble passing argument to s:link action
                    Philip Maiwald Newbie

                    Hi,
                    i ran into the same problem.
                    The generated HTML Code shows that it can't work because it produces a get call wich contains the name of the var instead of any pointer or id.


                    Is this already solved?
                    I ask me why it seems to work in the hotel example. It is obviously not a String but a complex object in that case.