tags:

views:

1899

answers:

7

I have an optiontransferselect in a form but i dont know how to get the selected items in the rightlist back in my action.

I need to get a list with all the visited countries' ids. i tried in my action List (Integer) countriesVisitedId; but it returns nullPointerException. then i tried Integer id but it returns null.

this is what i have:

s:optiontransferselect

        label="Select visited countries"
        name="countriesNotVisitedId"
        leftTitle="Not visited countries"
        rightTitle="Visited Countries"
        list="%{countriesNotVisited}"
        listKey="id"
        listValue="name"
        headerKey="countryNotVisitedId"
        headerValue="--- Please Select ---"

        doubleName="countriesVisitedId"
        doubleList="%{countriesVisited}"
        doubleHeaderKey="countryVisitedId"
        doubleHeaderValue="--- Please Select ---"
        doubleListKey="id"
        doubleListValue="name" />

how can I get the list with the Integers ids of the visited countries in my action?

A: 

In your action:

 public void setCountriesVisitedId(String[] countriesVisitedId) {
    this.countriesVisitedId = countriesVisitedId;
 }
A: 

I am also getting similar problem. Can some one help on this?

A: 

hi.... i tries this and it works fine

this i write in jsp to select the country from left hand side into right hand side step 1:

<s:optiontransferselect 
 label="Favourite Characters"
 name="leftSide"
 id="left"
 leftTitle="Left Title"
 rightTitle="Right Title"
 list="%{countriesNotVisited)"
 multiple="true"
 headerKey="headerKey"     
 doubleList="{}"
 doubleId="right"
 doubleName="rightSide"
 doubleHeaderKey="doubleHeaderKey"
 doubleMultiple="true" />

step 2: then i write javascript code to auto select all data from right hand side

function selectall() { var list = document.getElementById("right"); for (var i = 0; i < list.options.length; i++) { alert(list.options[i].value) list.options[i].selected = true; } var form = document.getElementById("right"); form.submit(); return true;

} step 3

i called this function on submit

jsp code:

step 4:

in action make getter setter of object name of left and right side take as string and not string array..

private String leftSide;
private String rightSide;


public String getLeftSide() {
 return leftSide;
}


public String getRightSide() {
 return rightSide;
}


public void setRightSide(String rightSide) {
 this.rightSide = rightSide;
}


public void setLeftSide(String leftSide) {
 this.leftSide = leftSide;
}

and if u tries to prnt value in action u will get values

System.out.println("right side list "+ad.getRightSide() ) ;

ANIK GARG

A: 

So it returns a String of the input selected?

I tried your code and having dramas getting it working. Nothing is returning to the Action class

Kris
A: 

I was banging my head on the wall wondering what I was doing wrong. It is pretty simple

doubleName="fields" is the tag field that is returned

public void setFields(String fields) { this is what needs to be in your action class.

The thing that I didn't realise is the elements need to be selected in order to be sent back. Or simple use ajax with in your header

Kris
A: 

how can i get this doubleList into the action ....

nish
A: 

Everyone here is the example!!!!! http://knishe.wordpress.com/

nish