Apache Wicket:尝试在null对象上设置属性值。属性表达式:metaCarrier值:SearchFormSelectOption [key = 367,value = KPN]

时间:2014-04-25 14:34:43

标签: apache jsf gwt wicket wicket-1.5

我正在尝试使用以下代码。

我收到错误   尝试在null对象上设置属性值。属性表达式:metaCarrier值:SearchFormSelectOption [key = 367,value = KPN]

关于Ajax调用

任何想法可能出错?

代码如下

   final DropDownChoice<SearchFormSelectOption> metaCarrier = new DropDownChoice<SearchFormSelectOption>("metaCarrier", carrierChoices, new ChoiceRenderer<SearchFormSelectOption>("value")
        {
           @Override
           public Object getDisplayValue(SearchFormSelectOption option)
           {
              LOG.error("check display object ....." + option.getValue());
              return option.getValue();
           }

           @Override
           public String getIdValue(SearchFormSelectOption option, int index)
           {
              return option.getKey();
           }

        });
     metaCarrier.setNullValid(true);
     metaCarrier.setOutputMarkupId(true);
     ruleCreationListView.add(metaCarrier);  
     metaCarrier.add(new AjaxFormComponentUpdatingBehavior("onchange")
        {
           /**
            * 
            */
           private static final long serialVersionUID = 1L;

           @Override
           protected void onUpdate(AjaxRequestTarget target)
           { 
           LOG.info("Carrier===============" + (getModelObject()).getMetaComSelectCarrier());
     }});





 public class SearchFormSelectOption implements Serializable
 {

   /** The Constant serialVersionUID. */
   private static final long serialVersionUID = 1L;

    /** The key. */
   private String key;

    /** The value. */
    private String value;
   //getter and setters

1 个答案:

答案 0 :(得分:0)

请直接从Customizing the display of choices查看以下示例代码。在这里找到更多样本。

public class SelectOption {
    private String key;
    private String value;

    public SelectOption(String key, String value) {
      this.key = key;
      this.value = value;
    }

  //...[getters and setters]...
  }

//create an instance of DropDownChoice with appropriate ChoiceRenderer.

 SelectOption[] options = new SelectOption[] { new SelectOption("&", "AND"),
            new SelectOption("|", "OR") };
 ChoiceRenderer choiceRenderer = new ChoiceRenderer("value", "key");
 DropDownChoice dropDownChoice = new DropDownChoice("connective", model, Arrays.asList(options), choiceRenderer);