4 Replies Latest reply on Mar 31, 2009 7:38 PM by sarfaraz

    Call to Struts action from richfaces

      Hi all,
      I request your assistance with integrating a seam application with an existing struts application.

      My requirement is to call a struts action on click of command button in richfaces (the command button may be a4j:commandbutton or h:commandbutton).

      Below is a code snippet:
      CODE SNIPPET ONE:

      <rich:modalPanel xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:rich="http://richfaces.ajax4jsf.org/rich"
       xmlns:s="http://jboss.com/products/seam/taglib"
       xmlns:riche="http://richfaces.org/rich"
       xmlns:c="http://java.sun.com/jstl/core"
       xmlns:fn="http://java.sun.com/jsp/jstl/functions"
       xmlns:a4j="http://richfaces.org/a4j"
       id="#{panelcartID}" width="350" height="550">
       <f:facet name="header">
       <h:panelGroup>
       <h:outputText value="My wish list"></h:outputText>
       </h:panelGroup>
       </f:facet>
       <f:facet name="controls">
       <h:panelGroup>
       <h:graphicImage value="/close-button-large.gif" styleClass="hidelink" id="hidelinkForCart#{panelcartID}"/>
       <rich:componentControl for="#{panelcartID}" attachTo="hidelinkForCart#{panelcartID}" operation="hide" event="onclick"/>
       </h:panelGroup>
       </f:facet>
       <h:panelGrid columns="3" width="255">
       <h:outputText value="Style" styleClass="detaillabel"/>
       <h:outputText value="Color" styleClass="detaillabel"/>
       <h:outputText value=""/>
      
      
       <c:forEach var="cartItem" items="#{cartContent}" varStatus="status">
       <c:forEach var="colCodes" items="#{cartItem.value}">
       <h:outputText value="#{cartItem.key}" styleClass="label"/>
       <h:outputText value="#{colCodes}" styleClass="label"/>
       <a4j:commandButton value="Remove" actionListener="#{cartAction.removeItem}" reRender="#{cartID},noOfItem#{cartID},#{panelcartID}">
       <f:setPropertyActionListener value="#{cartItem.key}" target="#{cartAction.itemKey}" />
       <f:setPropertyActionListener value="#{colCodes}" target="#{cartAction.itemColor}" />
       </a4j:commandButton>
       </c:forEach>
       </c:forEach>
       </h:panelGrid>
       <form name="campaignForm" method="post" id="campaignForm" action="http://localhost:8041/ordercapture/campaignLanding.do">
      
       <input type="hidden" name="campaignSnippet" id="campaignSnippet"
       value="#{cartAction.campaignSnippet}"/>
      
       <br/>
       <br />
       <h:panelGrid width="200" columns="3">
       <h:outputText value="" />
       <input type="submit" value="Enter quantities"/>
       <h:outputText value="" />
       </h:panelGrid>
       </form>
      
      
      </rich:modalPanel>
      


      What I am looking for in the above code is a replacement for the below mentioned code:

      CODE SNIPPET TWO
       <form name="campaignForm" method="post" id="campaignForm" action="http://localhost:8041/ordercapture/campaignLanding.do">
      
       <input type="hidden" name="campaignSnippet" id="campaignSnippet"
       value="#{cartAction.campaignSnippet}"/>
      
       <br/>
       <br />
       <h:panelGrid width="200" columns="3">
       <h:outputText value="" />
       <input type="submit" value="Enter quantities"/>
       <h:outputText value="" />
       </h:panelGrid>
       </form>
      
      


      The reason why I am looking for replacement of CODE SNIPPET TWO from CODE SNIPPET ONE is because CODE SNIPPET ONE works fine in firefox but fails in IE.


      In richfaces or JSF, how can I mention an URL as value for action attribute.
      eg: <h:commandButton action="http://localhost:8041/ordercapture/campaignLanding.do" />

      Please let me know your observations and workarounds.

      Regards
      Sarfaraz




        • 1. Re: Call to Struts action from richfaces
          nbelaevski

          1. rich:modalPanel needs its own form inside. Forms mustn't be nested. I do not see own panel's form in the code snippet posted.

          2. Why not output plain HTML instead of using JSF components?

          • 2. Re: Call to Struts action from richfaces

            Hi Nbelaevski,
            I thank you for your response. You confirmed my optimism that I would get response from you.

            1. After your response, I googled that IE doesn't supports nested forms. However, Safari and Firefox does. Hence the code worked in Firefox and failed in IE.

            " rich:modalPanel needs its own form inside. Forms mustn't be nested. I do not see own panel's form in the code snippet posted. "....do you mean to say we must have h:form tag inside rich:modalPanel??? I tried that....result was not on expected line.

            2. "Why not output plain HTML instead of using JSF components? "...I request you to elaborate this statement.


            Warm regards
            Sarfaraz

            • 3. Re: Call to Struts action from richfaces
              nbelaevski

              1. Yes, rich:modalPanel should have own h:form inside (if necessary; you use a4j:commandButton components, so it's necessary) and forms shouldn't be nested - JSF doesn't allow this. If you are using RF 3.3.0+ you can use this: https://jira.jboss.org/jira/browse/RF-5588 - read about possible issues in JIRA and documentation.

              2. Code snippet two should do it's job well, just remove forms nesting. It's doubtful for me that you'll be able to call Struts action using h:commandLink/h:commandButton.

              • 4. Re: Call to Struts action from richfaces

                Hi Nbelaevski,

                I followed your advise and it worked....just removed the form nest.
                Thank you Nbelaevski!!!

                Warm regards
                Sarfaraz