Optiontransferselect is a Struts2 UI component which allows to create UI component like shown below:
https://github.com/knishe/knishe-public (you can simply clone and try the example https://help.github.com/articles/fork-a-repo) with following command it can be clone into to the local machine(you need git installed to perform this command).
git clone https://github.com/knishe/knishe-public.git
It been generated and build using Maven and configure with jetty which allows to run the application instantly with one command "mvn install -Dmaven.test.skip=true jetty:run" (for this Maven should be configured) and you can browse to http://localhost:8080/struts-webapp/HelloWorld to see the UI component in action.
The web application is structure as shown below and newbies do not confuse with complex folder structure because created by maven struts2 archetype. All we need to care about is these five files.
- HelloWold.java (Action class)
- Module (Just Java Bean to hold "moduleId" and "moduleName")
- Success.jsp (Just to ensure the results)
Create HelloWorld Action classFirst create the HelloWorld action class with four lists, two lists to display modules and two lists to hold the left list and right list once submit.
Create Module bean classCreate the Module bean class to hold the "moduleId" and the "moduleName"
Edit the struts.xmlEdit the struts.xml and copy the following code snippet. In this XML I have created two action to direct to load the HelloWorld page with left and right list and another action to invoke a method "registerModule" during the submit and redirect to Success page.
Create HelloWorld.jspCreate HelloWorld jsp file with optiontranferselect UI component. You should place the
Create Success.jspCreate Success jsp file display the selected left list and right list after the submission.
Wish you all the best.