我在尝试获取一些值时遇到问题。这是我的情况(检票口)
我有一个下拉选择 study_template,我在填充 DDC 时没有问题,问题是当我尝试获取某个值(id 或名称)时。这是代码
ChoiceRenderer choiceRenderer = new ChoiceRenderer("name", "id");
study_template = new DropDownChoice( "study_template",new PropertyModel( this, "selectedTemplate" ),template_names , choiceRenderer);
template_names 是一个列表< SelectOption >,其值从数据库中获取。这工作正常。
这是我用来填充 DDC 的类
public class SelectOption implements java.io.Serializable {
private long id;
private String name;
public SelectOption(long id, String name ) {
this.id = id; this.name=name;
}
public long getId()
{return id; }
public String getName()
{return name; }
}
通常我可以使用 study_template.getModelObject() 获取值,但在这种情况下它不起作用,我对获取 id 和 name 没有任何想法,我知道我需要 GETID() 和 GETNAME( ),但我不知道如何使用它,任何帮助将不胜感激