no this won't work.

getValue() returns the modelvalue as a string (if now invalid input is found) and that getModelValue will alays be one of those that are in the selection list.

then objects you finally want to have are should be ints (or Integers) ?
then the choices/selectionlist must contain ints/Integers

using 1.1:

                        IChoiceRender renderer = new IChoiceRender()
                       {
                           public String getDisplayValue(Object object);
                           {
if(object.equals(new Integer(1)) return "Mand"; // If value == integer 1 then Mand;
                                 return "Kvinde";
                           }
public String getIdValue(Object object, int index) { return object.toString(); // The integer string representation so 1 or 2
                           }
                       }

           List selectionList = new ArrayList();
           selectionList.add(new Integer(1));
           selectionList.add(new Integer(2));
           gender = new DropDownChoice("gender", new Model(new Integer(1)), 
selectionList, renderer);
           add(gender);


            ((Integer)gender.getModelObject()).intValue()


There are ofcourse other objects. Like making a real Gender object with an id (the integer) and display value and set that in the choices/selection list.
then call gender.getModelObject() to get the Gender object and then get the id 
to get the integer.




frank bengtsson wrote:
Simple solution to a simple problem:

in form constructor:

            List selectionList = new ArrayList();
            selectionList.add("Mand");
            selectionList.add("Kvinde");
            gender = new DropDownChoice("gender", new Model(new String()), 
selectionList);
            add(gender);


onSubmit() :

             int genderPojo = Integer.parseInt(gender.getValue()); // Index on 
selected item in dropdown
                member.setGender(genderPojo == 0 ? 1:2); // Convert gender to 
int in pojo


/Frank B.


On Monday 18 July 2005 20:52, frank bengtsson wrote:
using 1.1 from the 14th of juli..

My pojo model(memberModel) has ONE int describing gender selection in a
dropdown ("Male","Female")

1) I have tried all the new combinations without any luck,it seems no
matter what i put in the genderlist i cannot convert to int ??

2) if i have to make other classes for this to work i dont see the benefit
of attaching my pojo to the dropdown this is to comlicated...all i want is
the selected string from the dropdown..anyway i can get that ?

Please explain how to do it !

here is one of the shots:

DropDownChoice gender = null;
 gender = new DropDownChoice("gender", new PropertyModel(this.memberModel,
"gender", int.class), genderList, new ChoiceRenderer("gendername"));

public class Gender implements Serializable {


    private String gendername;
    private String genderid;

    public String getGendername() {
        return gendername;
    }

    public void setGendername(String gendername) {
        this.gendername = gendername;
    }

    public String getGenderid() {
        return genderid;
    }

    public void setGenderid(String genderid) {
        this.genderid = genderid;
    }

}


i even tried with my own render...but i dont see how i get from either a
gender bean or something else to my int ?

public class GenderRender implements IChoiceRenderer, Serializable {


    public String getDisplayValue(Object object) {

        System.out.println();
        return "1";
    }

    public String getIdValue(Object object, int i) {
        System.out.println();

        return "1";
    }

}


i also tried to out gender class into model..no luck..

any is greatly appreciated..






/Frank B.

On Wednesday 13 July 2005 00:03, Johan Compagner wrote:
no you don't have to change them

if you are using wicket 1.0 make youre IChoice implementation (inside
youre IChoiceList implementation)
and on the getDisplayName() for gender == 1 you return male
and for getIdValue() you return the 1

in 1.1 you just have to implement a IChoiceRender this one has also just
displayvalue and idvalue methods.

johan

frank bengtsson wrote:
public class mypojo {

        private int gender;

        public setGender(int gender) {
                this.gender = gender;
        }

        public int getGender() {
                return gender
        }
}

this pojo cannot/must not be changed. du you follow ?
i think you say, that i have to change my pojo to have 2 fields ?

/Frank

On Tuesday 12 July 2005 23:09, Johan Compagner wrote:
why would you change the pojos?
what do they look like now?
They have a name i take?

frank bengtsson wrote:
Problem is, i cant change the pojo's. So i think it will be simpler to
get the selection value(String) and manually convert to an int and
then set it on my pojo

agree ?

/Frank

On Tuesday 12 July 2005 22:37, Johan Compagner wrote:
with Wicket 1.0 you have to create 2 Choice object for the
IChoiceList imlementation.

In wicket 1.1 (the current cvs)  you could do this:

new DropDownChoice("gender",new Model(),new
ChoiceRenderer("name","id"),list);

and in that list you have 2 pojo's that have a getId() and a
getName()

johan

frank bengtsson wrote:
Hi there,

I have "Male" + "Female" in my dropdownchoice and they are
represented as int's in my pojo's. How do i get "Male" converted to
an int with value 1 ?

Is there a way to set a number for each list item instead of
returning the list item("Male") ?

Or do i have to make a model for that dropdown, which then returns
and int for the get method and takes a string for the set method ?

/Frank
-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar
happening July 14 at 8am PDT/11am EDT. We invite you to explore the
latest in dual core and dual graphics technology at this free one
hour event hosted by HP, AMD, and NVIDIA.  To register visit
http://www.hp.com/go/dualwebinar
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to