DropDownChoice
을 미리 정의 된 매개 변수로 확장하는 것이 좋으며 DropDownChoice
이 아닌 Panel
이 아닌 것이 좋습니다.
이 방법의 적어도 두 가지 장점이 있습니다
- 당신이
Panel
-approach 함께 제공으로 별도의 마크 업 파일을 만들 필요가 없습니다.
DropDownChoice
메서드를 직접 사용할 수 있습니다. 그렇지 않으면 Panel
의 메서드를 전달하거나 DDC의 getter 메서드를 구현해야합니다.
그래서,이 같은 더 나은 것 :
public class CityDropDownChoice extends DropDownChoice<City> // use your own generic
{
/* define only one constructor, but you can implement another */
public CityDropDownChoice (final String id)
{
super (id);
init();
}
/* private method to construct ddc according to your will */
private void init()
{
setChoices (/* Your cities model or list of cities, fetched from somewhere */);
setChoiceRenderer (/* You can define default choice renderer */);
setOutputMarkupId (true);
/* maybe add some Ajax behaviors */
add(new AjaxEventBehavior ("change")
{
@Override
protected void onEvent (final AjaxRequestTarget target)
{
onChange (target);
}
});
}
/*in some forms you can override this method to do something
when choice is changed*/
protected void onChange (final AjaxRequestTarget target)
{
// override to do something.
}
}
그리고 당신의 형태
단순히 사용
Form form = ...;
form.add (new CityDropDownChoice ("cities"));
이 방법이 귀하의 필요에 적합하다고 생각.
주위를 돌리려면 드롭 다운에서 특별한 마크 업을 원한다면 '패널'을 선택하십시오. – biziclop
@biziclop, 동의 함. –