7 Replies Latest reply on Dec 19, 2007 4:04 PM by alok

    simple problem

       

      i have a task at which i need to create a community for each user on registering, i found the action resposible for registering (CreateProfile), and i just appened a couple of lines to extend the functionality of the execute method, however, the call is never made in execution. i tried to log things and write messages on the system but nothing had happened which means either:

       

       

      1- the action is called with a not updated version from the .War or something.

       

       

      2-  i am writing my lines in a wrong action.

       

       

      i tried recompiling the source code and generated a new .Jar and .War file but nothing happened, please help me

       

       

        • Re: simple problem

          hi youssef,

           

          Can you explain a little bit about how you got this custom class into the war file?

           

          Cheers,

           

          AJ

          • Re: simple problem

            youssef,

             

            AJ of course is the expert but I've had to extend quite a few actions in my project so you may just want to create a plugin which would keep things nice and modularized and make maintenace easier rather than hacking jive's source files and rebuilding their war every release.  Assuming you're familiar with plugins (there are tutorials on the site),  you would have to override the action in your custom xwork-plugin.xml - there are 2 actions using CreateProfile (create-account and account but sounds like you would only need to override account):

             

            <action name="account" class="com.youssef.MyCustomCreateProfile">

            <result name="unavailable">/template/global/registration-unavailable.ftl</result>

            <result name="cancel" type="redirect">index.jspa</result>

            <result name="input">/template/global/create-profile.ftl</result>

            <result name="success" type="redirect">account-success.jspa</result>

            </action>

             

            <action name="create-account" class="com.youssef.MyCustomCreateProfile" method="input">

            <result name="unavailable">/template/global/registration-unavailable.ftl</result>

            <result name="input">/template/global/create-profile.ftl</result>

            </action>

             

            If you wanted to override the ftls, then you would change those paths accordingly.

             

            Then in MyCustomCreateProfile.java (which extends CreateProfile), you would have public String execute() { your custom code; return super.execute();}

             

            If you want to be sure your action is firing, import com.jivesoftware.base.Log and then just add some logging as the first statements in your execute() method. Then just build your plugin jar and drop it into clearspace.

              • Re: simple problem

                Couldn't have said it better myself. Thanks for piping up James!

                • Re: simple problem

                   

                  dear james,

                   

                   

                  my problem is that i must add the couple of lines into the original class in the execute method as some information related to the user being created must be aquired first , for example the user id, because i will create a community with that id, the user object is being created in the body of the execute method, so i just add a couple of lines, but it is not called......the original problem was not how can add custom functionality with extending the class, but, why doesnt it work like this?

                   

                   

                  thanks very much for both aaron and james

                   

                   

                    • Re: simple problem

                      Well I'm not sure how you're building it and everything - perhaps your modified class isn't getting included - if you add some logging statements you could check for sure (I've never gone the route of modifying the core source files themselves and rebuilding).  But aside from that, even if you were to get it working, building it as a plugin would probably be a better approach as it would be isolated on its own so maintenance would be a lot easier (plus, the plugin approach might work if your custom building of the war continues failing).  If you extend the action, you should still have access to everything you need as there are likely getters and setters for all those properties you need in the original action that you could refer to in your overridden execute method which you could play with and then call super.execute() (or call super.execute() first and then have your custom code run depending on what your needs are).

                      • Re: simple problem

                        You will be better off writing a UserEventListener and adding the code in the userCreated(UserEvent) method. It will be a much cleaner approach and you do not have to worry about modifying the create profile action. I think you can set up listeners in plugin by calling UserEventDispatcher.getInstance().addListener() method. You should call this method inside the init() method of the plugin class and unregister the listener in the destroy method. Unregistering is done in the same way: UserEventDispatcher.getInstance().removeListener(listener).