Re: Tabular form validation problem with checkboxes

2008-02-20 Thread Martin Makundi
>  inside validators you should use formcomponent.getconvertedinput() to
>  read the value that will be put into the model if validators succeed.

Thousand tnx, this solved the remaining problem.

**
Martin

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Tabular form validation problem with checkboxes

2008-02-20 Thread Igor Vaynberg
this line: textRequired = (Boolean) checkBox.getModelObject(); should not work

you are inside a validator, that means models haven not been updated
yet. models are only updated once all type conversion/validation
succeeds.

inside validators you should use formcomponent.getconvertedinput() to
read the value that will be put into the model if validators succeed.

-igor


On Wed, Feb 20, 2008 at 3:30 PM, Martin Makundi
<[EMAIL PROTECTED]> wrote:
> > a proper solution would be to use a validator or a formvalidator to do
>  >  this. generally you never iterate over components to do validation in
>  >  wicket. we have good plugin points for you in the form workflow.
>
>  Judging from the performance of the checkbox, I have a wrong plugin
>  point for the validator. How would you put it?
>
>
>  > you didnt show the part of code that generates the list...
>  >  > it is just a  dummy list of new todo items.
>  > they are unique but you are using a listview? so what you have is not
>  >  a list at all, it is a collection of random items.
>  > perhaps listview is not what you want. if you keep regenerating items 
> every request
>
>  They are not random. Here is the code generating the items:
>  List linkedTodos = new LinkedList();
>  {
>   Todo todo = new Todo();
>   todo.setDescription("Dummy");
>   todo.setSelected(true);
>   todo.setTodoDate(Convert.toDate("1.1.2008");
>   linkedTodos.add(todo);
>  }
>  // ... and I have repeated a number of these ... say 7 pcs
>  return linkedTodos;
>
>  The page uses a linkedTodos "singleton" in the sence that the list is
>  generated only the first time the page is loaded. So they are not
>  random.
>
>
>  >  >  Is there a bug with the checkbox?
>  > doubt it
>
>  Well.. the validator fails to receive the submitted checkbox state.
>  Did I attach the validator improperly? Or should I read the checkbox
>  value in some other way? The checkbox state submitted from the browser
>  is not received by the validator using the code I posted before. The
>  textfields function properly, but the checkboxes seem to somehow be
>  disconnected... they sometimes change state according to the selection
>  in the browser window, sometimes not. Mostly not ;) Odd times? Very
>  strange.
>
>
>
>  **
>  Martin
>
>  -
>  To unsubscribe, e-mail: [EMAIL PROTECTED]
>  For additional commands, e-mail: [EMAIL PROTECTED]
>
>

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Tabular form validation problem with checkboxes

2008-02-20 Thread Martin Makundi
> a proper solution would be to use a validator or a formvalidator to do
>  this. generally you never iterate over components to do validation in
>  wicket. we have good plugin points for you in the form workflow.

Judging from the performance of the checkbox, I have a wrong plugin
point for the validator. How would you put it?

> you didnt show the part of code that generates the list...
>  > it is just a  dummy list of new todo items.
> they are unique but you are using a listview? so what you have is not
>  a list at all, it is a collection of random items.
> perhaps listview is not what you want. if you keep regenerating items every 
> request

They are not random. Here is the code generating the items:
List linkedTodos = new LinkedList();
{
  Todo todo = new Todo();
  todo.setDescription("Dummy");
  todo.setSelected(true);
  todo.setTodoDate(Convert.toDate("1.1.2008");
  linkedTodos.add(todo);
}
// ... and I have repeated a number of these ... say 7 pcs
return linkedTodos;

The page uses a linkedTodos "singleton" in the sence that the list is
generated only the first time the page is loaded. So they are not
random.

>  >  Is there a bug with the checkbox?
> doubt it

Well.. the validator fails to receive the submitted checkbox state.
Did I attach the validator improperly? Or should I read the checkbox
value in some other way? The checkbox state submitted from the browser
is not received by the validator using the code I posted before. The
textfields function properly, but the checkboxes seem to somehow be
disconnected... they sometimes change state according to the selection
in the browser window, sometimes not. Mostly not ;) Odd times? Very
strange.

**
Martin

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Tabular form validation problem with checkboxes

2008-02-20 Thread Igor Vaynberg
On Tue, Feb 19, 2008 at 9:04 PM, Martin Makundi
<[EMAIL PROTECTED]> wrote:
> > in your validate method why dont you iterate over the todo items
>  > instead of components. isnt that what the checkboxes are bound to?
>
>  The idea is to validate the input before it gets updated into the todo
>  items, yes? That is why I iterate the components... ofcourse I could
>  validate it after the state has been updated (it wouldn't matter if I
>  want to keep the invalid input on screen) but that seems more like a
>  workaround than the proper solution.

a proper solution would be to use a validator or a formvalidator to do
this. generally you never iterate over components to do validation in
wicket. we have good plugin points for you in the form workflow.

>  > also you are using a LISTview, are todo items really identified
>  > uniquely by their index returned from todoList =
>  > TodoServices.browseWeek(currentWeekStartDate, user) ?
>
>  The todo items are unique (try running the code ;)..

you didnt show the part of code that generates the list...

> it is just a  dummy list of new todo items.

they are unique but you are using a listview? so what you have is not
a list at all, it is a collection of random items. perhaps listview is
not what you want. if you keep regenerating items every request and
their equality is determined by instance equality then listview thinks
they go out of view on every request.

>  Is there a bug with the checkbox?

doubt it

-igor


>
>
>
>  **
>  Martin
>
>  -
>  To unsubscribe, e-mail: [EMAIL PROTECTED]
>  For additional commands, e-mail: [EMAIL PROTECTED]
>
>

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Tabular form validation problem with checkboxes

2008-02-19 Thread Martin Makundi
> in your validate method why dont you iterate over the todo items
> instead of components. isnt that what the checkboxes are bound to?

The idea is to validate the input before it gets updated into the todo
items, yes? That is why I iterate the components... ofcourse I could
validate it after the state has been updated (it wouldn't matter if I
want to keep the invalid input on screen) but that seems more like a
workaround than the proper solution.

> also you are using a LISTview, are todo items really identified
> uniquely by their index returned from todoList =
> TodoServices.browseWeek(currentWeekStartDate, user) ?

The todo items are unique (try running the code ;).. it is just a
dummy list of new todo items.

Is there a bug with the checkbox?

**
Martin

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Tabular form validation problem with checkboxes

2008-02-19 Thread Igor Vaynberg
in your validate method why dont you iterate over the todo items
instead of components. isnt that what the checkboxes are bound to?

also you are using a LISTview, are todo items really identified
uniquely by their index returned from
 todoList = TodoServices.browseWeek(currentWeekStartDate, user) ?

-igor



On Feb 19, 2008 12:35 PM, Martin Makundi
<[EMAIL PROTECTED]> wrote:
> Now it appears I have a problem only with reading the checkbox values.
> Am I doing something wrong here?
>
> I added the listView.setReuseItems(true); after the anonymous listview class.
>
> Now, the checkbox value submissions do not arrive properly onto the
> server-side. It is wysiwyg only seldom. I often have to press the
> submit button twice or more for the validator to receive the same
> checkbox selections as seen on the browser screen. Sometimes it
> "hangs" and anything I do on the browser does not affect the checkbox
> values received by the validator. Simultaneously, the textfields seem
> to work just fine.
>
> How can I use the checkboxes properly?
>
> **
> Martin
>
> 2008/2/19, Igor Vaynberg <[EMAIL PROTECTED]>:
> > first step is to call listview.setreuseitems(true), that will get rid
> > of the disappearing input on invalidation. please read listview
> > javadoc.
> >
> > -igor
> >
> >
> > On Feb 18, 2008 9:23 PM, Martin Makundi
> > <[EMAIL PROTECTED]> wrote:
> > > Hi!
> > >
> > > I have a simple html table with checkboxes and input text fields. My
> > > goal is to validate that if the checkbox on the row is selected, the
> > > respective input field should contain text. And vice versa, if the
> > > input field contains text, the checkbox should be checked.
> > >
> > > I have now constructed a nearly working version of the page. The
> > > problems are as follows:
> > > a) Checking the checkbox and submitting it, returns
> > > checkBox.getModelObject() as False. Shouldn't it pick the value from
> > > the form, which is checked?
> > > b) If I write text in a textfield, the form gets invalidated due to
> > > the "unchecked" checkbox on the row, and the textfield gets cleared. I
> > > would like the typed text not to be cleared out.
> > > c) If I type anything into the form after the feedback, and submit
> > > again, the form is not validated, but the values remain on the screen,
> > > and the feedback messages are cleared. This seems weird, as if the
> > > form would be in some kind of tilt mode now. I get a warning on the
> > > logs: IFormValidator in form `todoForm` depends on a component that
> > > has been removed from the page or is no longer visible. Offending
> > > component id `todo`.
> > >
> > > Naturally I would like the form to behave more intuitively. Most
> > > likely I am doing something significantly wrong here now. And the
> > > warning message, why is that and how should I operate it insteaed?
> > > Please have a look, here is my code:
> > >
> > > http://wicket.sourceforge.net";>
> > > 
> > > Welcome to TODO application
> > > 
> > > 
> > >
> > > Todo weekdays descriptions
> > > Feedback messages will be here.
> > > 
> > > 
> > > 
> > > 
> > > Date
> > > Selected
> > > Description
> > > 
> > > 
> > > 
> > > 
> > >  > > wicket:id="date">
> > > 
> > >   
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > >
> > > public class Todos extends WebPage {
> > >   private static final String TODO_FORM = "todoForm";
> > >   private static final String DESCRIPTION = "description";
> > >   private static final String TODO = "todo";
> > >   private static final String DATE = "date";
> > >   private static final String LIST_VIEW = "listView";
> > >   private List todoList;
> > >
> > >   public Todos() {
> > > final FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
> > > User dummyUser = new User();
> > >
> > > Form todoForm = new Form(TODO_FORM);
> > > final List formComponentsToBeValidated = new
> > > LinkedList();
> > > @SuppressWarnings("serial")
> > > ListView listView = new PropertyListView(LIST_VIEW,
> > > getTodoList(dummyUser)) {
> > > protected void populateItem(ListItem item) {
> > >   Todo todo = (Todo) item.getModelObject();
> > >   item.add(new Label(DATE, new
> > > Model(Convert.toString(todo.getTodoDay();
> > >   CheckBox checkBox = new CheckBox(TODO, new
> > > PropertyModel(todo, Todo.SELECTED));
> > >   TextField textField = new TextField(DESCRIPTION, new
> > > PropertyModel(todo, Todo.DESCRIPTION));
> > >   item.add(checkBox);
> > >   formComponentsToBeValidated.add(checkBox);
> > >   item.add(textField);
> > >   formComponentsToBeValidated.add(textField);
> > > }
> > > };
> > >
> > > @SuppressWarnings("serial")
> > > AbstractFormValidator formValidator = n

Re: Tabular form validation problem with checkboxes

2008-02-19 Thread Martin Makundi
Now it appears I have a problem only with reading the checkbox values.
Am I doing something wrong here?

I added the listView.setReuseItems(true); after the anonymous listview class.

Now, the checkbox value submissions do not arrive properly onto the
server-side. It is wysiwyg only seldom. I often have to press the
submit button twice or more for the validator to receive the same
checkbox selections as seen on the browser screen. Sometimes it
"hangs" and anything I do on the browser does not affect the checkbox
values received by the validator. Simultaneously, the textfields seem
to work just fine.

How can I use the checkboxes properly?

**
Martin

2008/2/19, Igor Vaynberg <[EMAIL PROTECTED]>:
> first step is to call listview.setreuseitems(true), that will get rid
> of the disappearing input on invalidation. please read listview
> javadoc.
>
> -igor
>
>
> On Feb 18, 2008 9:23 PM, Martin Makundi
> <[EMAIL PROTECTED]> wrote:
> > Hi!
> >
> > I have a simple html table with checkboxes and input text fields. My
> > goal is to validate that if the checkbox on the row is selected, the
> > respective input field should contain text. And vice versa, if the
> > input field contains text, the checkbox should be checked.
> >
> > I have now constructed a nearly working version of the page. The
> > problems are as follows:
> > a) Checking the checkbox and submitting it, returns
> > checkBox.getModelObject() as False. Shouldn't it pick the value from
> > the form, which is checked?
> > b) If I write text in a textfield, the form gets invalidated due to
> > the "unchecked" checkbox on the row, and the textfield gets cleared. I
> > would like the typed text not to be cleared out.
> > c) If I type anything into the form after the feedback, and submit
> > again, the form is not validated, but the values remain on the screen,
> > and the feedback messages are cleared. This seems weird, as if the
> > form would be in some kind of tilt mode now. I get a warning on the
> > logs: IFormValidator in form `todoForm` depends on a component that
> > has been removed from the page or is no longer visible. Offending
> > component id `todo`.
> >
> > Naturally I would like the form to behave more intuitively. Most
> > likely I am doing something significantly wrong here now. And the
> > warning message, why is that and how should I operate it insteaed?
> > Please have a look, here is my code:
> >
> > http://wicket.sourceforge.net";>
> > 
> > Welcome to TODO application
> > 
> > 
> >
> > Todo weekdays descriptions
> > Feedback messages will be here.
> > 
> > 
> > 
> > 
> > Date
> > Selected
> > Description
> > 
> > 
> > 
> > 
> >  > wicket:id="date">
> > 
> >   
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> >
> > public class Todos extends WebPage {
> >   private static final String TODO_FORM = "todoForm";
> >   private static final String DESCRIPTION = "description";
> >   private static final String TODO = "todo";
> >   private static final String DATE = "date";
> >   private static final String LIST_VIEW = "listView";
> >   private List todoList;
> >
> >   public Todos() {
> > final FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
> > User dummyUser = new User();
> >
> > Form todoForm = new Form(TODO_FORM);
> > final List formComponentsToBeValidated = new
> > LinkedList();
> > @SuppressWarnings("serial")
> > ListView listView = new PropertyListView(LIST_VIEW,
> > getTodoList(dummyUser)) {
> > protected void populateItem(ListItem item) {
> >   Todo todo = (Todo) item.getModelObject();
> >   item.add(new Label(DATE, new
> > Model(Convert.toString(todo.getTodoDay();
> >   CheckBox checkBox = new CheckBox(TODO, new
> > PropertyModel(todo, Todo.SELECTED));
> >   TextField textField = new TextField(DESCRIPTION, new
> > PropertyModel(todo, Todo.DESCRIPTION));
> >   item.add(checkBox);
> >   formComponentsToBeValidated.add(checkBox);
> >   item.add(textField);
> >   formComponentsToBeValidated.add(textField);
> > }
> > };
> >
> > @SuppressWarnings("serial")
> > AbstractFormValidator formValidator = new AbstractFormValidator() {
> >   public FormComponent[] getDependentFormComponents() {
> > return formComponentsToBeValidated.toArray(new
> > FormComponent[formComponentsToBeValidated.size()]);
> >   }
> >
> >   public void validate(Form form) {
> > Boolean textRequired = null;
> > boolean checkedButDescriptionMissing = false;
> > boolean descriptionGivenButUnchecked = false;
> > for (FormComponent formComponent : formComponentsToBeValidated) {
> >   if (textRequired == null) {
> > CheckBox checkBox = (CheckBox) formComponent;
> >