10 Replies Latest reply: Oct 16, 2012 2:59 AM by RMishra RSS

    ATG Servlet Beans - serviceLocalParameter vs serviceParameter

    srinivas302
      can you explain the difference between serviceLocalParameter and serviceParameter used in ATG Servlet Beans?
        • 1. Re: ATG Servlet Beans - serviceLocalParameter vs serviceParameter
          893966
          If you use

          serviceLocalParameter in the droplet java class then in the jsp out put param whatever variables set in the droplet class will be available within the open and close dsp:droplet tags.

          Eg:


          <dsp:droplet name="xyz">
          <dsp:param name="username" value="meerasaab">
          <dsp:oparam name="output">

          <dsp:valueof param="uname"/>

          </dsp:oparam>
          </dsp:droplet>


          public void service(){


          request.setparameter("uname",request.getParameter("username"));

          request.serviceLocalParameter("output",request,response);


          }


          So uname will be accessed within droplet scope ( i,e open and close oparam tags)

          If you use serviceParameter you can access whatever you set in the droplet ( Java class ) will be accessed out side the invocation of droplet.


          Eg:


          <dsp:droplet name="xyz">
          <dsp:param name="username" value="meerasaab">
          <dsp:oparam name="output">

          Accessed in oparam: <dsp:valueof param="uname"/>

          </dsp:oparam>
          </dsp:droplet>


          Accessed outside of droplet oparam tags <dsp:valueof param="uname"/>


          public void service(){


          request.setparameter("uname",request.getParameter("username"));

          request.serviceParameter("output",request,response);


          }

          Hope this helps....

          Edited by: 890963 on Oct 11, 2011 11:54 PM
          • 2. Re: ATG Servlet Beans - serviceLocalParameter vs serviceParameter
            srinivas302
            Thanks for the reply.

            Is this the only difference or there exists some other advantages/disadvantages of using serviceLocalParameter/ serviceParameter?
            • 3. Re: ATG Servlet Beans - serviceLocalParameter vs serviceParameter
              enzo_rio
              @ 890963.

              i tried the above given example and its not working. If i use the serviceparameter and access the parameter out side the droplet, i am unable to access the value set in the droplet. Please verify and let me know what needs to be changed in the code.
              • 4. Re: ATG Servlet Beans - serviceLocalParameter vs serviceParameter
                891571
                @ezno rio:

                You have to get the value of parameter into a variable, before you use it somewhere.
                saying


                <dsp:getvalueof var="uname" param="uname"/>

                Try this, it should work

                THanks

                Sridhar
                • 5. Re: ATG Servlet Beans - serviceLocalParameter vs serviceParameter
                  srinivas302
                  Guys,

                  I am not too sure about the usage of serviceLocalParameter, but sure about the parameters which are rendered by the droplet in the oparam.
                  If you assign the value of a parameter to a global variable it will be available globally. This has nothing to do with the params rendered by the droplet.
                  As far as I have seen the params rendered by droplet is never accessible outside the <dsp:oparam></dsp:oparam> tags.

                  It would help if someone can explain the exact difference. ATG programming guide says - "Local parameters are useful because they allow the ATG servlet bean to determine which parameters are defined for a particular ATG servlet bean call. Without local parameters, it can be easy to get into an infinite loop by nesting different ATG servlet beans, as the inner ATG servlet bean always sees all parameters defined to the outer one."

                  Thanks,
                  Srini
                  • 6. Re: ATG Servlet Beans - serviceLocalParameter vs serviceParameter
                    srinivas302
                    Can someone please have a look and answer?
                    • 7. Re: ATG Servlet Beans - serviceLocalParameter vs serviceParameter
                      Gautam Singh
                      The parameters set by Servlet beans are only visible inside the Droplet <dsp:oparam> tag (unless set to an attribute).

                      Let me explain this with an example
                      Let's assume we have to droplets used one inside other
                      <droplet1>
                      <droplet2>
                      </droplet2>
                      </droplet1>
                      droplet1 set parameter "user" with value user item "user1" and droplet sets parameter "email" which it does by getting the parameter value for "user" parameter and then fetching it's email property.

                      With serviceLocalParameter:
                      The user parameter will be only visible inside droplet 1 so droplet 2 won't be able to access it through Request.getParameter() method.
                      It has to call Request.getLocalParameter()

                      With serviceParameter:
                      The user parameter will be visible inside droplet 2 since its used inside droplet 1. So droplet 2 get request parameter by calling Request.getParameter() method.

                      Generally speaking serviceLocalParameter should always be used unless you have multiple droplets communicating each other like our example.
                      • 8. Re: ATG Servlet Beans - serviceLocalParameter vs serviceParameter
                        RMishra
                        Hi Gautam,
                        I have tried to run following example:

                        //my custom droplet page
                        public class PrintDroplet extends DynamoServlet{
                             ParameterName name=ParameterName.getParameterName("name");
                             public void service(DynamoHttpServletRequest pRequest,DynamoHttpServletResponse pResponse)throws ServletException,IOException{
                                       pRequest.setParameter("myvalue", pRequest.getParameter(name));
                                       pRequest.serviceParameter("output2", pRequest, pResponse);
                             }

                        }

                        //my .jsp page code
                        dsp:page>
                             <dsp:importbean bean="/com/training/club/tools/PrintDroplet"/>     
                             <dsp:droplet name="PrintDroplet">
                                  <dsp:param name="name" value="Mishra"/>
                                  <dsp:oparam name="output2">
                                       output is :
                                       <dsp:valueof param="myvalue"/>......................(1)
                                  </dsp:oparam>
                             </dsp:droplet>
                             
                             <dsp:getvalueof id="v" param="myvalue">
                                  Global value is :<dsp:valueof value="<%=v %>" />..........................(2)
                             </dsp:getvalueof>
                        </dsp:page>

                        I am able to print value of .....(1) but not of ....(2).
                        Am I implementing right? If no, Kindly provide right way to understand it with this implementation.

                        Thanks in advance.
                        -RMishra
                        • 9. Re: ATG Servlet Beans - serviceLocalParameter vs serviceParameter
                          000201
                          Try this....PrintDroplet scope should be Global.

                          <dsp:importbean bean="/com/training/club/tools/PrintDroplet"/>
                          <dsp:droplet name="PrintDroplet">
                          <dsp:param name="name" value="Mishra"/>
                          <dsp:oparam name="output2">
                          <dsp:getvalueof id="v" param="myvalue" scope="request"/>
                          output is :
                          <dsp:valueof param="myvalue"/>......................(1)
                          </dsp:oparam>
                          </dsp:droplet>


                          Global value is :<%=request.getAttribute("v")%>..........................(2)

                          </dsp:page>
                          • 10. Re: ATG Servlet Beans - serviceLocalParameter vs serviceParameter
                            RMishra
                            Thanks,
                            In droplet I'm using serviceParameter and serviceLocalParameter in both cases it is woking. so i'm unable to understand difference b/w both.
                            -RMishra