I need to add components in a listView and associate all of them with a
model,for allow keep the state of each object saved in this listView. I'm
using wicket 1.4 with scala.
The code is showed bellow, isn't a short piece of code but I tried to keep
it simple as possible


add(new ListView[WorkSheet]("listWorkSheet", listData) {

    override protected def onBeforeRender() {
      super.onBeforeRender()
    }

    def populateItem(item: ListItem[WorkSheet]) = {
      var workSheet = item.getModelObject()

      // Render normally
      item.add(new LinkDate("initDate", workSheet, 1))

      // render normally
      item.add(new TextField("description"))
      // error on Render Page
      item.add(new TextDesc("description", workSheet))

      val listCustomer: java.util.List[Customer] = customerDAO.listCustomers

      // render normally
      item.add(new DropDownChoice("customerSelection", listCustomer, new
ChoiceRenderer[Customer]("name")))
      // error on Render Page
      item.add(new DropDownChoiceCustomer("customerSelection",
listCustomer, workSheet))

}

// Render normally, works
private class LinkDate(id: String, workSheet: WorkSheet, type: Int) extends
Link[String](id) {

  setEnabled(false)
  add(new Label("label", new Model[String]() {
    override def getObject(): String = {
      var result = ""
      if (type == 1) {
          result = workSheet.initDate.toString("dd/MM/YYYY HH:mm:ss")
      }
      return result
    }
  }))

  def onClick() {}
}

// doesn't work
private class TextDesc(id: String, workSheet: WorkSheet) extends
TextField[String](id) {

  add(new TextField("textField", new Model[String]() {
    override def getObject(): String = {
      var result = ""
      if (result.length != 0) {
          result = workSheet.description
      }
      return result
    }
  }))
}

// doesn't work
private class DropDownChoiceCustomer(id: String, listCustomer:
java.util.List[Customer], workSheet: WorkSheet) extends
DropDownChoice[String](id) {

    add(new DropDownChoice("customerSelection", listCustomer, new
ChoiceRenderer[Customer]("name")) {
      protected override def wantOnSelectionChangedNotifications: Boolean =
{
        true
      }
      protected override def onSelectionChanged(customerSelection:
Customer) {
        System.out.println("selected: " + customerSelection.id)
      }
    })
}

// I got the error messages bellow

WicketMessage: The component(s) below failed to render. A common problem is
that you have added a component in code but forgot to reference it in the
markup (thus the component will never be rendered).

1. [MarkupContainer [Component id = textField]]
2. [MarkupContainer [Component id = textField]]

Root cause:

org.apache.wicket.WicketRuntimeException: The component(s) below failed to
render. A common problem is that you have added a component in code but
forgot to reference it in the markup (thus the component will never be
rendered).

1. [MarkupContainer [Component id = textField]]
2. [MarkupContainer [Component id = textField]]

at org.apache.wicket.Page.checkRendering(Page.java:1201)
at org.apache.wicket.Page.renderPage(Page.java:941)
at
org.apache.wicket.protocol.http.WebRequestCycle.redirectTo(WebRequestCycle.java:201)


WicketMessage: The component(s) below failed to render. A common problem is
that you have added a component in code but forgot to reference it in the
markup (thus the component will never be rendered).

1. [MarkupContainer [Component id = customerSelection]]
2. [MarkupContainer [Component id = customerSelection]]

Root cause:

org.apache.wicket.WicketRuntimeException: The component(s) below failed to
render. A common problem is that you have added a component in code but
forgot to reference it in the markup (thus the component will never be
rendered).

1. [MarkupContainer [Component id = customerSelection]]
2. [MarkupContainer [Component id = customerSelection]]


// the markup

<TD>
   <SELECT wicket:id="customerSelection" name="id"></SELECT>
</TD>
<TD><INPUT wicket:id="description" type="text" name="obs" value="_"/></TD>

If someone could help me I'll appreciate, thanks.

Bera

Reply via email to