Good to know :) Ursprüngliche Nachricht Von:[email protected] Gesendet:19. April 2016 9:02 nachm. An:[email protected] Antworten:[email protected] Betreff:Re: Component disabled if it contains data
On Tue, Apr 19, 2016 at 7:28 PM, sub es <[email protected]> wrote: > In my opinion one should always validate inputs coming from a submit even if > the inputs were disabled. Using tools like firebug, one can easily change > values of disabled inputs and submit those changed values. Atleast I don't > know about wicket not submitting disabled inputs, though I would not expect > that behavior and would not rely on it. You can bet that Wicket protects you from disabled components, **as long as they are disabled for wicket on the server**. Disabling components on the server will render them as disabled on the client, and then prohibit updates and other actions to be triggered. Wicket prohibits any action directed at a disabled component, e.g. will fail a click request when the server-side component was disabled, or not process the input when a form is submitted. Merely adding a disabled attribute to the markup tag, and not disabling the server-side component is a disaster waiting to happen though. So: use Wicket for disabling inputs: textfield.setEnabled(false); And Wicket will take care of the rest. Martijn > > Best regards, > Edwin > > Ursprüngliche Nachricht > Von:[email protected] > Gesendet:19. April 2016 7:18 nachm. > An:[email protected] > Antworten:[email protected] > Betreff:Component disabled if it contains data > > Hello, > I'm using Wicket 6, with Java 1.7. > I'm new to Wicket and I would like to know what is the best way to implement > the following: > -I have a webpage with several input fields bound to a db table, and a > submit button. > - two of the fields can be empty when submitting the changes to the db. > - however, if the fields are filled once, after submitting the page, the > user should not be allowed anymore to change the values(even if leaves and > reenters the page for the same registrations) > > Could you please tell me what is the best way to achieve this? > > What I have done so far is: > - on the page load, when the wicket components are added to the page, I > check if the db fields have values, and if they do, then I set the > components to disabled: > > Component myComp = new TextField<Integer>("project", new > PropertyModel<Integer>(getModelObject(), "project")); > if (getModelObject().getProject() != null) > myComp.setEnabled(false); > dtForm.add(myComp ).add(RangeValidator.<Integer>range(0, 999999999)); > > - also on submit, I check if I have a value in my component and if yes, set > the component to disable: > if (getModelObject().getProject() != null ){ > Component myComp = get("project"); > if (myComp.isEnabled()){ > myComp.setEnabled(false); > dtForm.replace(tf); > } > } > > what bothers me is that I need to do all the validation again in the submit > button, every time the submit will be pressed. > > Is there a better way? > > Thank you > > -- > View this message in context: > http://apache-wicket.1842946.n4.nabble.com/Component-disabled-if-it-contains-data-tp4674313.html > Sent from the Users forum mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > -- Become a Wicket expert, learn from the best: http://wicketinaction.com --------------------------------------------------------------------- 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]
