How to set B2B Unit in session (Hybris)?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















How can I set B2B Unit in session. I have facade class which implements logic to set units in session (ex. When one user is login in storefront give me his units and set these units in session). This is my method in custom class which extedns DefaultCustomerFacade.class



 @Override
public void loginSuccess()
Set<B2BUnitModel> allUserGroupsForUser = getUserService().getAllUserGroupsForUser(getCurrentUser(), B2BUnitModel.class);
List<String> b2bunitIds = allUserGroupsForUser.stream()
.map(B2BUnitModel::getName)
.collect(Collectors.toList());
if(!allUserGroupsForUser.isEmpty())
getSessionService().setAttribute("availableB2BUnits", b2bunitIds);

super.loginSuccess();



Then in storefront, I showed in select tag in jsp, drop-down with these units. Ok, so I have attribute now with these units which is in session and I want when I click for some B2B Unit, this one unit to set in session. I think, I shoud do some controller to implement logic ( set currentUnit in session ) and in one js file to make some ajax call with some method onChange, or some ajax api, but I don't know how to do this. Can someone help me, i am new in hybris and I will be glad if someone help me










share|improve this question






















  • Please see: Why is “Can someone help me?” not an actual question?

    – Progman
    Nov 15 '18 at 13:43

















2















How can I set B2B Unit in session. I have facade class which implements logic to set units in session (ex. When one user is login in storefront give me his units and set these units in session). This is my method in custom class which extedns DefaultCustomerFacade.class



 @Override
public void loginSuccess()
Set<B2BUnitModel> allUserGroupsForUser = getUserService().getAllUserGroupsForUser(getCurrentUser(), B2BUnitModel.class);
List<String> b2bunitIds = allUserGroupsForUser.stream()
.map(B2BUnitModel::getName)
.collect(Collectors.toList());
if(!allUserGroupsForUser.isEmpty())
getSessionService().setAttribute("availableB2BUnits", b2bunitIds);

super.loginSuccess();



Then in storefront, I showed in select tag in jsp, drop-down with these units. Ok, so I have attribute now with these units which is in session and I want when I click for some B2B Unit, this one unit to set in session. I think, I shoud do some controller to implement logic ( set currentUnit in session ) and in one js file to make some ajax call with some method onChange, or some ajax api, but I don't know how to do this. Can someone help me, i am new in hybris and I will be glad if someone help me










share|improve this question






















  • Please see: Why is “Can someone help me?” not an actual question?

    – Progman
    Nov 15 '18 at 13:43













2












2








2








How can I set B2B Unit in session. I have facade class which implements logic to set units in session (ex. When one user is login in storefront give me his units and set these units in session). This is my method in custom class which extedns DefaultCustomerFacade.class



 @Override
public void loginSuccess()
Set<B2BUnitModel> allUserGroupsForUser = getUserService().getAllUserGroupsForUser(getCurrentUser(), B2BUnitModel.class);
List<String> b2bunitIds = allUserGroupsForUser.stream()
.map(B2BUnitModel::getName)
.collect(Collectors.toList());
if(!allUserGroupsForUser.isEmpty())
getSessionService().setAttribute("availableB2BUnits", b2bunitIds);

super.loginSuccess();



Then in storefront, I showed in select tag in jsp, drop-down with these units. Ok, so I have attribute now with these units which is in session and I want when I click for some B2B Unit, this one unit to set in session. I think, I shoud do some controller to implement logic ( set currentUnit in session ) and in one js file to make some ajax call with some method onChange, or some ajax api, but I don't know how to do this. Can someone help me, i am new in hybris and I will be glad if someone help me










share|improve this question














How can I set B2B Unit in session. I have facade class which implements logic to set units in session (ex. When one user is login in storefront give me his units and set these units in session). This is my method in custom class which extedns DefaultCustomerFacade.class



 @Override
public void loginSuccess()
Set<B2BUnitModel> allUserGroupsForUser = getUserService().getAllUserGroupsForUser(getCurrentUser(), B2BUnitModel.class);
List<String> b2bunitIds = allUserGroupsForUser.stream()
.map(B2BUnitModel::getName)
.collect(Collectors.toList());
if(!allUserGroupsForUser.isEmpty())
getSessionService().setAttribute("availableB2BUnits", b2bunitIds);

super.loginSuccess();



Then in storefront, I showed in select tag in jsp, drop-down with these units. Ok, so I have attribute now with these units which is in session and I want when I click for some B2B Unit, this one unit to set in session. I think, I shoud do some controller to implement logic ( set currentUnit in session ) and in one js file to make some ajax call with some method onChange, or some ajax api, but I don't know how to do this. Can someone help me, i am new in hybris and I will be glad if someone help me







java hybris






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 13:05









rrusevrrusev

439




439












  • Please see: Why is “Can someone help me?” not an actual question?

    – Progman
    Nov 15 '18 at 13:43

















  • Please see: Why is “Can someone help me?” not an actual question?

    – Progman
    Nov 15 '18 at 13:43
















Please see: Why is “Can someone help me?” not an actual question?

– Progman
Nov 15 '18 at 13:43





Please see: Why is “Can someone help me?” not an actual question?

– Progman
Nov 15 '18 at 13:43












1 Answer
1






active

oldest

votes


















2














You have already halfway through as you have already populated availableB2BUnits from the backend(Façade) to the frontend(JSP). Similarly, you have to send back the "b2bunitIds" to the backend.



Implement the following steps:



  1. Find/ create the javascript file from where you can make ajax (or normal post) call. Make sure that js file is loaded for the current page on which you need all these actions to be performed otherwise your javascript method won't be executed.


  2. Write required logic in above js file to obtain b2bunitId from the selection made. Use b2bunitId to invoke Controller's method (RequestMapping).


  3. From the invoked method of the Controller set the selected b2bunitId in session as you did it in the above method (getSessionService().setAttribute("availableB2BUnits", b2bunitIds);).






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320155%2fhow-to-set-b2b-unit-in-session-hybris%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    You have already halfway through as you have already populated availableB2BUnits from the backend(Façade) to the frontend(JSP). Similarly, you have to send back the "b2bunitIds" to the backend.



    Implement the following steps:



    1. Find/ create the javascript file from where you can make ajax (or normal post) call. Make sure that js file is loaded for the current page on which you need all these actions to be performed otherwise your javascript method won't be executed.


    2. Write required logic in above js file to obtain b2bunitId from the selection made. Use b2bunitId to invoke Controller's method (RequestMapping).


    3. From the invoked method of the Controller set the selected b2bunitId in session as you did it in the above method (getSessionService().setAttribute("availableB2BUnits", b2bunitIds);).






    share|improve this answer



























      2














      You have already halfway through as you have already populated availableB2BUnits from the backend(Façade) to the frontend(JSP). Similarly, you have to send back the "b2bunitIds" to the backend.



      Implement the following steps:



      1. Find/ create the javascript file from where you can make ajax (or normal post) call. Make sure that js file is loaded for the current page on which you need all these actions to be performed otherwise your javascript method won't be executed.


      2. Write required logic in above js file to obtain b2bunitId from the selection made. Use b2bunitId to invoke Controller's method (RequestMapping).


      3. From the invoked method of the Controller set the selected b2bunitId in session as you did it in the above method (getSessionService().setAttribute("availableB2BUnits", b2bunitIds);).






      share|improve this answer

























        2












        2








        2







        You have already halfway through as you have already populated availableB2BUnits from the backend(Façade) to the frontend(JSP). Similarly, you have to send back the "b2bunitIds" to the backend.



        Implement the following steps:



        1. Find/ create the javascript file from where you can make ajax (or normal post) call. Make sure that js file is loaded for the current page on which you need all these actions to be performed otherwise your javascript method won't be executed.


        2. Write required logic in above js file to obtain b2bunitId from the selection made. Use b2bunitId to invoke Controller's method (RequestMapping).


        3. From the invoked method of the Controller set the selected b2bunitId in session as you did it in the above method (getSessionService().setAttribute("availableB2BUnits", b2bunitIds);).






        share|improve this answer













        You have already halfway through as you have already populated availableB2BUnits from the backend(Façade) to the frontend(JSP). Similarly, you have to send back the "b2bunitIds" to the backend.



        Implement the following steps:



        1. Find/ create the javascript file from where you can make ajax (or normal post) call. Make sure that js file is loaded for the current page on which you need all these actions to be performed otherwise your javascript method won't be executed.


        2. Write required logic in above js file to obtain b2bunitId from the selection made. Use b2bunitId to invoke Controller's method (RequestMapping).


        3. From the invoked method of the Controller set the selected b2bunitId in session as you did it in the above method (getSessionService().setAttribute("availableB2BUnits", b2bunitIds);).







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 19:58









        ApsAps

        215




        215





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320155%2fhow-to-set-b2b-unit-in-session-hybris%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kleinkühnau

            Makov (Slowakei)

            Deutsches Schauspielhaus