4 Replies Latest reply on Jun 8, 2010 2:03 PM by Leonid Sokolin

    Passing component value via aj4:actionparam

    Leonid Sokolin Newbie

      I need to add a command button to the screen, which will perform DB delete operation without regard to the data entered on the screen. To avoid validation issues I use immediate attribute for it set to true, but then it doesn't update bean value for the single parameter I need to pass to the delete function. Its value does appear on the screen, but I need to assign it to the backing bean variable.

       

      I thought, I could pass it using a4j:actionparam, but it doesn't seem to be working could somebody tell me, what might be wrong?

       

      Code is below. I need to pass the value of comboBox with id "template" to the command button "deleteTemplate".

       

      XHTML:

       

       

      <

      h:panelGrid id="templateParams" columns="8">

       

      <h:outputText value="Templates:" style="font-weight:bold" />

       

      <rich:comboBox id="template" width="160" value="#{qtBeanParam.templateName}" enableManualInput="true" >

       

      <f:selectItems id="templateList" value="#{qtBeanParam.templateList}" />

       

      </rich:comboBox>

       

      <h:outputText value="Owners:" style="font-weight:bold" />

       

      <rich:comboBox id="templateOwner" width="160" value="#{qtBeanParam.templateOwner}" enableManualInput="false" >

       

      <f:selectItems id="templateOwnerList" value="#{qtBeanParam.templateOwnersList}" />

       

      </rich:comboBox>

       

      <a4j:commandButton id="saveTemplate" value="Save"

       

      action="#{qtBeanParam.saveTemplate}" immediate="false" reRender="template,templateList,templateOwner,templateOwnerList"

       

      styleClass="blue-button">

       

      </a4j:commandButton>

       

      <a4j:commandButton id="deleteTemplate" value="Delete"

       

      action="#{qtBeanParam.deleteTemplate}" immediate="true" reRender="template,templateList,templateOwner,templateOwnerList"

       

      styleClass="blue-button">

       

      <a4j:actionparam name="tempname" value="#{template}" assignTo="#{qtBeanParam.templateName}"></a4j:actionparam>

       

      </a4j:commandButton>

       

      </h:panelGrid>

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      Backing bean method:

       

      public

      void deleteTemplate()

      {

       

           final String user = usrSecurityBean.getUserID();

       

           // templateName is shown on the screen, but is null or empty when at this point

           if ( templateName == null || templateName.equals(""))

           {

                showMessage("piPerformanceReturnsForm:templateParams", "Template name should be selected.");

       

                return;

           }

      ...

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      Thanks a lot in advance,

       

      Leonid

        • 1. Re: Passing component value via aj4:actionparam
          Ilya Shaikovsky Master

          1) I guess f:setPropertyActionListener will works for you instead of a4j:param. Or you could add converter to your #{template} objects. This caused by the fact that a4j:param encodes params to the client and passes it back on submit. And f:setProp - operates just at server side so it operatees with object.

           

          2) B.t.w. you could use ajaxSingle="true" instead of immediate and use process attribute if will ever need to process single action component and some additional data. But current solution looks better for now.. So this just a note for future

          1 of 1 people found this helpful
          • 2. Re: Passing component value via aj4:actionparam
            Leonid Sokolin Newbie

            Ilya,

             

            I actually, went another way and added valueChangeListener to template combo box to make sure that I always have its value when I attempt to delete it.

             

            Your solution seems to be more simple, but I am not exactly suer how to pass the value of "template" object to "templateName" property using it. Could you provide a small sample?

             

            BTW, I noticed that value of rich:comboBox is not changed after I delete the record from DB and remove it from the list. It still shows on the screen even though I reRender the component. Why would it happen and how could I make sure that it is cleared?

             

            Code is below:

             

            <

            h:outputText value="Templates:" style="font-weight:bold" />

             

            <rich:comboBox id="template" width="250" value="#{qtBeanParam.templateName}" enableManualInput="true"

             

            valueChangeListener="#{qtBeanParam.changeTemplate}" >

             

            <a4j:support event="onselect" reRender="template,templateList" ajaxSingle="true" />

             

            <a4j:support event="onchange" reRender="template,templateList" ajaxSingle="true" />

             

            <f:selectItems id="templateList" value="#{qtBeanParam.templateList}" />

             

            </rich:comboBox>

             

            <h:outputText value="Owners:" style="font-weight:bold" />

             

            <rich:comboBox id="templateOwner" width="160" value="#{qtBeanParam.templateOwner}"

             

            immediate="true" enableManualInput="false" >

             

            <f:selectItems id="templateOwnerList" value="#{qtBeanParam.templateOwnersList}" />

             

            </rich:comboBox>

             

            <a4j:commandButton id="saveTemplate" value="Save"

             

            action="#{qtBeanParam.saveTemplate}" immediate="true" reRender="template,templateList,templateOwner,templateOwnerList"

             

            styleClass="blue-button">

             

            </a4j:commandButton>

             

            <a4j:commandButton id="deleteTemplate" value="Delete"

             

            action="#{qtBeanParam.deleteTemplate}" immediate="true" reRender="template,templateList,templateOwner,templateOwnerList"

             

            styleClass="blue-button">

             

            </a4j:commandButton>

            • 4. Re: Passing component value via aj4:actionparam
              Leonid Sokolin Newbie

              Ilya,

               

              It was exactly what you said and wrapping the button in "a4j:region" eliminated the issue.

               

              Thanks a lot!

               

              Leonid