Struts2 optiontransferselect get and display value from database

On the jsp page, I have <s:optiontransferselect> for swap values ​​between the left and right sides and a submit button to save.

 <s:optiontransferselect allowUpDownOnLeft="false" allowUpDownOnRight="false" allowSelectAll="false" allowAddAllToLeft="false" allowAddAllToRight="false" addToRightLabel="Go to right" addToLeftLabel="Go to left" leftTitle="Left side values" headerKey="0" name="option" list= "optionList" rightTitle="Right side values" doubleHeaderKey="0" doubleList="selectedOptionList" doubleName="selectOption" doubleId="selectedValues" > </s:optiontransferselect> <s:submit /> 

I run the program, it can actually save the value on the right side. However, it does not display the stored values.

I am thinking about using javascript and using the onchange event in <s:optiontransferselect> to achieve this

 <script> function show(){ var list =document.getElementById("selectedValues"); for (var i = 0; i< list.options.length;i++) { //seems something not correct in this part but I am not sure how solve in this way list.options[i].selected = true; } return true; } </script> <s:optiontransferselect allowUpDownOnLeft="false" allowUpDownOnRight="false" allowSelectAll="false" allowAddAllToLeft="false" allowAddAllToRight="false" addToRightLabel="Go to right" addToLeftLabel="Go to left" leftTitle="Left side values" headerKey="0" name="option" list= "optionList" rightTitle="Right side values" doubleHeaderKey="0" doubleList="selectedOptionList" doubleName="selectOption" doubleId="selectedValues" onchange ="show()"> <!-- onchange seems not work here --> </s:optiontransferselect> 

When I run the program, the right side still cannot display the saved value.

Additional information on the transferselect option in case it is useful.

I have an action class for it.

 public class OptionTransferSelectAction extends ActionSupport { private List<String> optionList; private List<String> selectedOptionList; //private String option; private List<String> option; private List<String> selectOption; public OptionTransferSelectAction (){ optionList=new ArrayList<String>(); //display on the left side for selection optionList.add("Section A"); optionList.add("Section B"); optionList.add("Section C"); optionList.add("Section D"); optionList.add("Section E"); optionList.add("Section F"); optionList.add("Section G"); optionList.add("Section H"); selectedOptionList=new ArrayList<String>(); //display on the right side //pretend it does not have any values in the first time (does not //trigger the save yet) } public List<String> getOptionList() { return optionList; } public void setOptionList(List<String> optionList) { this.optionList = optionList; } public List<String> getSelectedOptionList() { return selectedOptionList; } public void setSelectedOptionList(List<String> selectedOptionList) { this.selectedOptionList = selectedOptionList; } /* public String getOption() { return option; } public void setOption(String option) { this.option = option; } */ public List<String> getOption() { return option; } public void setOption(List<String> option) { this.option = option; } public List<String> getSelectOption() { return selectOption; } public void setSelectOption(List<String> selectOption) { this.selectOption = selectOption; } } 

Update

I am changing the parameter from String to List<String> with the correct receiver and setter. I run the code, optiontransferselect still can not display the stored values.

Which part have I done wrong? Anyone let me know please? Thanks.

Update I created a new jsp, for example success.jsp. If I selected some values ​​to select Option and click submit. The jsp file can display the values ​​I just presented. I see the stored values ​​in the database. However, the transferselect option still cannot display the stored values.

Success.jsp has one code that can display the value just presented.

 Selected Value(s) : <s:property value="selectOption"/> 

In the database, I can see the stored values, so I would like to know how to allow optiontransferselect show stored values?

another update

I am trying to use a button to call a javascript function to show selectedValues before submitting.

 <script> function testshow() { var value = document.getElementById("selectedValues"); for(var i=0;i<value.options.length; i++) { alert(value.options[i].innerHTML); } return true; } </script> //button to call the function <s:submit onclick="return testshow()"/> 

I run the program when I'm on the button, it can display the selected values ​​before sending, so I still do not understand why optiontransferselect can not get the saved selected values.

+8
java javascript jquery jsp struts2
source share

No one has answered this question yet.

See related questions:

7494
How to remove a specific element from an array in JavaScript?
6170
Is Java pass-by-reference or pass-by-value?
5722
How to remove a property from a JavaScript object?
5129
How to return a response from an asynchronous call?
3953
What href should be used for JavaScript, "#" or "javascript: void (0)" references?
3393
Create ArrayList from Array
2701
How to get query string values ​​in JavaScript?
2256
Set the default value for the JavaScript function
2132
Get selected text from drop-down list (select field) using jQuery
1818
How to get enum value from string value in Java?

All Articles