My Vehicle class has the Customer class as instance variable[1]. Thus, I
must create my Select with the appropriated bind path -

Select customerSelect = new Select("customer.id");

are you using this approach?

[1]
http://code.google.com/p/construtor/source/browse/trunk/park-samples/park-jpa/src/main/java/park/model/Vehicle.java


2013/5/18 Bob Schellink <[email protected]>

>  Do you use a debugger?
>
> Does this line execute?
>  if (StringUtils.isNotBlank(id)) {
>
> or the else part?
>
> In your onGet the form.copyFrom should populate the Select. If not your
> naming is probably off. You can manually set the Select value with:
>
> select.setValue(idOfAnException);
>
> regards
>
> Bob
>
>
> On 2013/05/18 02:55, Kristian Lind wrote:
>
> I can simply not get this to work...
>
>  My PrintProviderMockEnt has a list of PrintProviderMockMTMExceptionEnt.
> The user can, for now, only choose on exception... so there is only one
> exception in that list.
> It looks the the name field in working...
>
>
>  package com.farheap.jsi.dashboard.pages.customer;
>
>  import java.util.ArrayList;
> import java.util.Iterator;
> import java.util.List;
>
>  import org.apache.click.ActionListener;
> import org.apache.click.Control;
> import org.apache.click.control.Form;
> import org.apache.click.control.HiddenField;
> import org.apache.click.control.Option;
> import org.apache.click.control.Select;
> import org.apache.click.control.Submit;
> import org.apache.click.control.TextField;
> import org.apache.click.dataprovider.DataProvider;
> import org.apache.click.util.ClickUtils;
> import org.apache.commons.lang.StringUtils;
> import org.slf4j.Logger;
> import org.slf4j.LoggerFactory;
>
>  import com.farheap.jsi.dashboard.utils.BorderedPage;
> import com.farheap.jsi.dashboard.utils.SessionBeanManager;
> import com.farheap.jsi.exceptions.BusinessException;
> import com.farheap.jsi.exceptions.SystemException;
> import com.farheap.jsi.model.PrintCustomerEnt;
> import com.farheap.jsi.model.ppmock.PrintProviderExceptionMockEnt;
> import com.farheap.jsi.model.ppmock.PrintProviderMockEnt;
> import com.farheap.jsi.session.DashboardSBBeanLocal;
>
>  /**
>  */
> public class CustomerPrintProvider extends BorderedPage {
>  private static final long serialVersionUID = 1L;
>  private static final Logger logger =
> LoggerFactory.getLogger(CustomerPrintProvider.class);
>  private static final String PAGE_TITLE_CREATE = "Add Test Print
> Provider";
>  private static final String PAGE_TITLE_EDIT = "Edit Test Print Provider";
>  private DashboardSBBeanLocal dashboardSBBeanLocal =
> SessionBeanManager.getDashboardSBBeanLocal();
>  private EditForm form;
>  private boolean newTestPrintProvider = false;
>  private PrintProviderMockEnt printProviderMockEnt;
>  private PrintCustomerEnt printCustomerEnt;
>  private String id;
>  private String customerName;
>
>  @Override
>  public final void onInit() {
>  super.onInit();
>  form = new EditForm("form");
>  addModel("newTestPrintProvider", newTestPrintProvider);
>  addControl(form);
>  }
>
>  @Override
>  public void onGet() {
>  super.onGet();
>  customerName = getContext().getRequest().getUserPrincipal().getName();
>  id = getContext().getRequest().getParameter("id");
>  try {
>  printCustomerEnt = dashboardSBBeanLocal.findCustomer(customerName);
>  if (StringUtils.isNotBlank(id)) {
>  printProviderMockEnt =
> dashboardSBBeanLocal.getPrintProviderMock(Long.parseLong(id));
>  form.copyFrom(printProviderMockEnt);
>  } else {
>  newTestPrintProvider = true;
>  }
>  } catch (BusinessException e) {
>  addModel("error", e.getMessage());
>  return;
>  } catch (SystemException e) {
>  // TODO show errorpage
>  logger.error(e.getMessage(), e);
>  }
>  }
>
>  @Override
>  public final String getTitle() {
>  if (printProviderMockEnt == null) {
>  return PAGE_TITLE_CREATE;
>  } else {
>  return PAGE_TITLE_EDIT;
>  }
>  }
>
>  public final boolean onSave() throws SystemException {
>  if (form.isValid()) {
>  try {
>  if (newTestPrintProvider) {
>  printProviderMockEnt = new PrintProviderMockEnt();
>  printProviderMockEnt.setName(form.nameField.getValue());
>  printProviderMockEnt.setPrintCustomerEnt(printCustomerEnt);
>  List<String> selectedValues = form.exception.getSelectedValues();
>  for (String strId : selectedValues) {
>  Long id = Long.parseLong(strId);
>  PrintProviderExceptionMockEnt printProviderExceptionMockEnt = new
> PrintProviderExceptionMockEnt();
>  printProviderExceptionMockEnt.setId(id);
>  printProviderMockEnt.addException(printProviderExceptionMockEnt, true);
>  }
>  dashboardSBBeanLocal.saveNewPrintProviderMock(printProviderMockEnt);
>  } else {
>  PrintProviderMockEnt printProviderMockEnt =
> dashboardSBBeanLocal.getPrintProviderMock((Long)
> form.printProviderMockEntId.getValueObject());
>  printProviderMockEnt.setName(form.nameField.getValue());
>  printProviderMockEnt.getMtmException().clear();
>  List<String> selectedValues = form.exception.getSelectedValues();
>  for (String strId : selectedValues) {
>  Long id = Long.parseLong(strId);
>  PrintProviderExceptionMockEnt printProviderExceptionMockEnt = new
> PrintProviderExceptionMockEnt();
>  printProviderExceptionMockEnt.setId(id);
>  printProviderMockEnt.addException(printProviderExceptionMockEnt, true);
>  }
>  dashboardSBBeanLocal.updatePrintProviderMock(printProviderMockEnt);
>  }
>  form.clearValues();
>  setRedirect(CustomerPrintProviders.class);
>  } catch (BusinessException e) {
>  addModel("error", e.getMessage());
>  return false;
>  } catch (SystemException e) {
>  logger.error(e.getMessage(), e);
>  throw e;
>  }
>  }
>  return true;
>  }
>
>  public final boolean onCancel() {
>  setRedirect(CustomerPrintProviders.class);
>  return false;
>  }
>
>  private class EditForm extends Form {
>
>  private HiddenField printProviderMockEntId;
>  private TextField nameField;
>  private Select exception;
>
>  public static final String DEFAULT_PRINT_PROVIDER_KEY = "Default";
>  public static final String DEFAULT_PRINT_PROVIDER_VALUE = "";
>
>  public EditForm(final String name) {
>  super(name);
>  printProviderMockEntId = new HiddenField("printProviderMockEntId",
> Long.class);
>  if (printProviderMockEnt != null) {
>  printProviderMockEntId.setValueObject(printProviderMockEnt.getId());
>  }
>  add(printProviderMockEntId);
>  nameField = new TextField("name", "Name", true);
>  nameField.setFocus(true);
>  add(nameField);
>
>  // Select exception
>  exception = new Select("exceptions", true);
>  exception.setMultiple(false);
>  exception.setDataProvider(new DataProvider() {
>  public List<Option> getData() {
>  List<Option> options = new ArrayList<Option>();
>  List<PrintProviderExceptionMockEnt> allExceptions = new
> ArrayList<PrintProviderExceptionMockEnt>();
>  try {
>  allExceptions = dashboardSBBeanLocal.getExceptions();
>  for (Iterator iterator = allExceptions.iterator(); iterator.hasNext();) {
>  PrintProviderExceptionMockEnt printProviderExceptionMockEnt =
> (PrintProviderExceptionMockEnt) iterator.next();
>  options.add(new Option(printProviderExceptionMockEnt.getId(),
> printProviderExceptionMockEnt.getExceptionCode() + " : "
>  + printProviderExceptionMockEnt.getName()));
>  }
>  } catch (SystemException e) {
>  // TODO show errorpage
>  logger.error(e.getMessage(), e);
>  }
>  return options;
>  }
>  });
>  exception.setDefaultOption(Option.EMPTY_OPTION);
>  add(exception);
>  // Submit button
>  Submit save = new Submit("save", "Save");
>  save.setActionListener(new ActionListener() {
>  public boolean onAction(final Control control) {
>  try {
>  return onSave();
>  } catch (SystemException e) {
>  // TODO show errorpage
>  logger.error(e.getMessage(), e);
>  return false;
>  }
>  }
>  });
>
>  save.addStyleClass("btn btn-primary");
>  add(save);
>
>  Submit cancel = new Submit("cancel", "Cancel");
>  cancel.setActionListener(new ActionListener() {
>  public boolean onAction(final Control control) {
>  return onCancel();
>  }
>  });
>
>  cancel.addStyleClass("btn");
>  add(cancel);
>
>  ClickUtils.bind(save);
>  ClickUtils.bind(cancel);
>  if (isFormSubmission() && !save.isClicked() && !cancel.isClicked()) {
>  setValidate(false);
>  }
>
>  setButtonAlign(Form.ALIGN_RIGHT);
>  }
>
>  @Override
>  public void validate() {
>  super.validate();
>  }
>  }
> }
>
>
>
>
>
>
> On Fri, May 17, 2013 at 2:02 PM, Gilberto <[email protected]> wrote:
>
>> Sorry, didn't answer you question. But here it is: DataProvider
>> interface[1].
>>
>> [1]
>> http://click.apache.org/docs/click-api/org/apache/click/control/Select.html#setDataProvider%28org.apache.click.dataprovider.DataProvider%29
>>
>>
>>
>> 2013/5/17 Gilberto <[email protected]>
>>
>>>  Complementing Bob's answer, here[1] you can see some examples.
>>>  Regards,
>>>
>>> Gilberto
>>> [1]
>>> http://code.google.com/p/construtor/source/browse/trunk/park-samples/park-jpa/src/main/java/park/web/page/EditVehicle.java
>>>
>>>
>>> 2013/5/17 Kristian Lind <[email protected]>
>>>
>>>> I tried to use setValueObject, but nothing is working.. what should be
>>>> the argument  ?? and Option... a String. ??
>>>>
>>>>
>>>> On Fri, May 17, 2013 at 8:57 AM, Bob Schellink <[email protected]>wrote:
>>>>
>>>>>  Hi,
>>>>>
>>>>> Use this:
>>>>>
>>>>> http://click.apache.org/docs/click-api/org/apache/click/control/Form.html#copyFrom%28java.lang.Object%29
>>>>>
>>>>> or:
>>>>>
>>>>> http://click.apache.org/docs/click-api/org/apache/click/control/Field.html#setValueObject%28java.lang.Object%29
>>>>>
>>>>> regards
>>>>>
>>>>> Bob
>>>>>
>>>>>
>>>>> On 2013/05/16 20:31, Kristian Lind wrote:
>>>>>
>>>>> Hi, I have a select where a user can select an option.
>>>>>
>>>>>  // Select exception
>>>>> exception = new Select("exception", true);
>>>>> exception.setMultiple(false);
>>>>> exception.setDataProvider(new DataProvider() {
>>>>>  public List<Option> getData() {
>>>>>  List<Option> options = new ArrayList<Option>();
>>>>>  List<PrintProviderErrorMockEnt> allErrors = new
>>>>> ArrayList<PrintProviderErrorMockEnt>();
>>>>>  try {
>>>>>  allErrors = printProviderMockSBBeanLocal.getErrors();
>>>>>  for (Iterator iterator = allErrors.iterator(); iterator.hasNext();) {
>>>>>  PrintProviderErrorMockEnt printProviderErrorMockEnt =
>>>>> (PrintProviderErrorMockEnt) iterator.next();
>>>>>  options.add(new Option(printProviderErrorMockEnt.getId(),
>>>>> printProviderErrorMockEnt.getErrorCode() + " : "
>>>>>  + printProviderErrorMockEnt.getName()));
>>>>>  }
>>>>>  } catch (SystemException e) {
>>>>>  // TODO show errorpage
>>>>>  logger.error(e.getMessage(), e);
>>>>>  }
>>>>>  return options;
>>>>>  }
>>>>> });
>>>>> exception.setDefaultOption(Option.EMPTY_OPTION);
>>>>>
>>>>>
>>>>>  When the user has selected a value and presses the submit button the
>>>>> value is stored in database.
>>>>> This same page is used when the user wants to edit the values....
>>>>>
>>>>>  How do I set the select control, to have the option selected, that
>>>>> the user did select previous when the wants the edit it...
>>>>>
>>>>>  Kris
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>  --
>>>> Best regards
>>>>
>>>> Kristian Lind
>>>>
>>>
>>>
>>
>
>
>  --
> Best regards
>
> Kristian Lind
>
>
>

Reply via email to