1.button的
setDefaultFormProcessing(false)方法可以在表单提交的时候只调用button的onSubmit方法,
当true的情况将先调用form的onSubmit方法再调用button的onSubmit方法,默认为true。
2.在需要的时候增加js - public class JQueryValidateBehavior extends AbstractBehavior {
- private static final ResourceReference JQUERY_VALIDATE = new JavascriptResourceRefernce(JQueryValidateBehavior.class,"jquery.js");
-
- public void renderHead(IHeaderResponse response) {
- super.renderHead(response);
- response.renderJavascriptReference(JQUERY_VALIDATE);
- }
- }
- 在page的form中只需要add(new JQueryValidateBehavior());
public class JQueryValidateBehavior extends AbstractBehavior {private static final ResourceReference JQUERY_VALIDATE = new JavascriptResourceRefernce(JQueryValidateBehavior.class,"jquery.js");public void renderHead(IHeaderResponse response) {super.renderHead(response);response.renderJavascriptReference(JQUERY_VALIDATE);}}在page的form中只需要add(new JQueryValidateBehavior());
3.在使用DropDownChoice的时候如果想一直显示 "请选择" 或 "请选择省份" 或 根本不想显示 - DropDownChoice<Province> _province = new DropDownChoice<Province>("wicketId",new Model<Province>(province),List<Province>provinceList,new ChoiceRenderer("name","id")){
- @Override
- protected CharSequence getDefaultChoice(Object arg0){
- return new AppendingStringBuffer("\n<option selected="\"selected\" value=\"\">").append("请选择省份").append("</option>");
-
- }
- };
-
- _province.add(new AjaxFormComponentUpdatingBehavior("onchange")){
- protected void onUpdate(AjaxRequestTarget target){
- Province province = _province.getModelObject().getId());
- List<City> cityList = xxxManager.getCityByProvince(province.getId());
-
- _city.setChoice(new Model((Serializable)cityList));
- target.addComponent(_city);
- }
- };
DropDownChoice<Province> _province = new DropDownChoice<Province>("wicketId",new Model<Province>(province),List<Province>provinceList,new ChoiceRenderer("name","id")){@Overrideprotected CharSequence getDefaultChoice(Object arg0){return new AppendingStringBuffer("\n<option selected="\"selected\" value=\"\">").append("请选择省份").append("</option>");//return null; 根本不显示默认的"请选择"}};//如果想根据省份得到城市需要如下操作_province.add(new AjaxFormComponentUpdatingBehavior("onchange")){protected void onUpdate(AjaxRequestTarget target){Province province = _province.getModelObject().getId());List<City> cityList = xxxManager.getCityByProvince(province.getId());//_city同样是DropDownChoice或者 ListMultipleChoice_city.setChoice(new Model((Serializable)cityList));target.addComponent(_city);}};
4.隐藏 setVisible 使用 - xxx控件.setOutputMarkupPlaceholderTag(true).setVisible(true);
- 或者
- xxx控件.add(new SimpleAttributeModifier("style","display:none"));
xxx控件.setOutputMarkupPlaceholderTag(true).setVisible(true);//false;或者xxx控件.add(new SimpleAttributeModifier("style","display:none"));
5.AjaxButton 同样支持JQuery validate验证 自己做个AjaxButton和原有的AjaxButton一样
因为这里需要使用JQuery Validate 所以需要修改AjaxButton 里的 getEventHandler();
- protected CharSequence getEventHandler(){
- return new AppendingStringBuffer("if(jQuery('#"+AjaxButton2.this.getForm().getMarkupId()+"').valid()){"+super.getEventHandler()+";return false;}else{return false;}");
- }