General question - business logic with Wicket, where to put it?
What is the best practice for where to put business logic in Wicket. At first, I had put logic in the page constructor, but now I have learned a little bit about the Lifecycle of a page, the serialization of the page. So putting any kind of logic there didn't seem like a good idea. I placed logic in the action buttons onSubmit methods and form onSubmit methods. Placing any logic here in the onSubmits methods are OK, but sometimes it is difficult to find all the dependent objects. I gues I am used to a Struts MVC approach, where you have one Page action and then communicate with all of your dependent objects (say a form bean with all of the data); With Wicket, I see these issues: 1. When will the page constructor get invoked (should any kind of business logic be placed here?) 2. Where and when will the onSubmit/onUpdate action methods get invoked (should any business logic be placed here and are all the dependent objects available) Berlin Brown
Additional attributes to ajax events
With the onblur ajax calls, is it possible to add my own javascript . final AjaxFormComponentUpdatingBehavior blurText = new AjaxFormComponentUpdatingBehavior(onblur) { @Override protected void onUpdate(AjaxRequestTarget target) { checkPageNextLink(target); } }; In the markup, can I simply add the onblur and it will get appended? onblur=alert('update') How do I add the ajax call and then add my own javascript call?
RE: Additional attributes to ajax events
Is it possible to add the javascript function in the markup and somehow copy that value and append to the ajax onblur. E.g. This is in my markup : onblur=alert('update') Based on what you said, it looks like you are suggesting adding the javascript method in the Java code. -Original Message- From: Pedro Santos [mailto:pedros...@gmail.com] Sent: Wednesday, July 21, 2010 2:15 PM To: users@wicket.apache.org Subject: Re: Additional attributes to ajax events You can override the getAjaxCallDecorator method from AjaxFormComponentUpdatingBehavior and return an IAjaxCallDecorator that append your custom javascript On Wed, Jul 21, 2010 at 10:26 AM, Brown, Berlin [GCG-PFS] berlin.br...@primerica.com wrote: With the onblur ajax calls, is it possible to add my own javascript . final AjaxFormComponentUpdatingBehavior blurText = new AjaxFormComponentUpdatingBehavior(onblur) { @Override protected void onUpdate(AjaxRequestTarget target) { checkPageNextLink(target); } }; In the markup, can I simply add the onblur and it will get appended? onblur=alert('update') How do I add the ajax call and then add my own javascript call? -- Pedro Henrique Oliveira dos Santos - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
wicket hell
There is a css hell, html hell, java web app hell. Is there a wicket hell or issues that are specific to wicket? Because I do believe web application development is wicket is pretty unique. I am still new to wicket but there are two gripes that get me every time. And maybe over time, I will get used to the problem. 1. Hierarchy issues - The hierarchy is very strict and not like the Java hierarchy. If you want to reference a component, it must be added properly in the markup and in the java code. This can be caught at compile time, but it is still takes time getting used to. 2. Unexpected behavior with the markup - Sometimes I expect a particular attribute or piece of code to get output but some tags I add in the markup get replaced by wicket. (E.g. I added class= to a div and the class attribute was removed) Note: I am not saying wicket is hell, or css or html is. But I was just pointing out that even wicket can have some quirks. Am I wrong here? Berlin Brown
RE: Welcome Martin Grigorov as a core team member
Cool, he has been helping me on IRC/Freenode -Original Message- From: Maarten Bosteels [mailto:mbosteels@gmail.com] Sent: Tuesday, July 20, 2010 10:16 AM To: users@wicket.apache.org Subject: Re: Welcome Martin Grigorov as a core team member Congratulations Martin ! On Tue, Jul 20, 2010 at 1:21 PM, Martin Grigorov martin.grigo...@gmail.comwrote: Thanks a lot for the voted trust in me, team! As a big open source believer it is an honour for me to be a part of the team that made such a great framework! Looking forward to make 1.5 production ready ! 2010/7/20 Ian Marshall ianmarshall...@gmail.com Many congratulations Martin! (In my extremely limited experience with web application frameworks, Wicket is just so excellent. Developing with Wicket really is fun, too.) -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Welcome-Martin-Grigorov-as- a-core-team-member-tp2294324p2295166.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Issues with form submit, not retaining values from session without ajax
I have a page that has a html components like a select list and radio buttons. And those components will invoke the onchange event to submit the form or move to the next page. It doesn't look like I am moving to the next page. My model values dont' seem to be retained, at least they aren't retained in for the radio buttons, text boxes. For example, I was thinking like Struts or Spring, I would call onchange on a radio button, the page would reload and all of my values would be retained. The values are NOT retained. Here are two radio buttons. I want to select one, do an onchange and have retain the value of radiogroup2. That is not happening: Also, I am losing the values of my textfields. What would I need to to keep the values of the widgets regardless if I submit the page or do an onchange. Source in a paste bin: http://paste.lisp.org/display/112321 = Snippet, two radio buttons. Radio two loses its values. final RadioChoice radioGroupYesNo2 = new RadioChoice(radioGroup2, new PropertyModel(bean, yesNo2), Arrays.asList(YES_NO)) { @Override public boolean wantOnSelectionChangedNotifications() { return true; } @Override public void onSelectionChanged(Object newSel) { this.setResponsePage(TestPage.class); } @Override public boolean isVisible() { return true; } }; // End of add radio group // radioGroupYesNo2.setPrefix(); radioGroupYesNo2.setSuffix(); form.add(radioGroupYesNo2); // Add Link // this.add(new SubmitLink(linkSubmit, form) { @Override public void onSubmit() { // Here what is the difference between the Class and the Object this.setResponsePage(TestPage.class); } }); } public final DropDownChoice createDropDown(final String str) { // Add list select elements. final ChoiceRenderer choiceRenderer = new ChoiceRenderer(name, value); final ListSelect list1 = new ArrayListSelect(); list1.add(new Select(select1, select1)); list1.add(new Select(select2, select2)); final DropDownChoice dropDown = new DropDownChoice(str, list1, choiceRenderer) { private static final long serialVersionUID = 3169945459254179351L; @Override protected boolean wantOnSelectionChangedNotifications() { return false; } @Override protected void onSelectionChanged(Object newSelection) { this.setResponsePage(TestPage.class); } }; dropDown.setRequired(true); return dropDown; } == Full Source: /** * File: TestPage.java */ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.markup.html.form.ChoiceRenderer; import org.apache.wicket.markup.html.form.DropDownChoice; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.RadioChoice; import org.apache.wicket.markup.html.form.SubmitLink; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.model.CompoundPropertyModel; import org.apache.wicket.model.PropertyModel; import TestBean.Select; public class TestPage extends WebPage { public static final String [] YES_NO = { Yes, No }; @SuppressWarnings(unchecked) public TestPage(final PageParameters parameters) { super(parameters); TestBean bean = new TestBean(); if (WicketSession.get().getTestBean() == null) { bean = new TestBean(); WicketSession.get().setTestBean(bean); } else { bean = WicketSession.get().getTestBean(); } final FormTestBean form = new FormTestBean(form, new CompoundPropertyModel(bean)); this.add(form); form.add(new TextField(firstName)); form.add(new TextField(lastName)); form.add(createDropDown(selectBox1)); form.add(createDropDown(selectBox2)); final RadioChoice radioGroupYesNo = new RadioChoice(radioGroup1, new PropertyModel(bean, yesNo1), Arrays.asList(YES_NO)) { @Override public boolean wantOnSelectionChangedNotifications() { return true; } @Override public void onSelectionChanged(Object newSel) { this.setResponsePage(TestPage.class); } @Override public boolean isVisible() { return true; } }; // End of add radio group // radioGroupYesNo.setPrefix(); radioGroupYesNo.setSuffix(); form.add(radioGroupYesNo); final RadioChoice radioGroupYesNo2 = new RadioChoice(radioGroup2, new PropertyModel(bean, yesNo2), Arrays.asList(YES_NO)) { @Override public boolean wantOnSelectionChangedNotifications() { return true; } @Override public void onSelectionChanged(Object newSel) { this.setResponsePage(TestPage.class); } @Override public boolean isVisible() { return true; } }; // End of add radio group // radioGroupYesNo2.setPrefix(); radioGroupYesNo2.setSuffix();
wantOnSelectionChangedNotifications and form components. and keeping state
I have an object in session and want to keep the state of those values when I refresh a page or my form submits back to the page. Do I have to add on every component? It seems that I do. Also, how do I add want on selection change but NOT have it perform a form submit. public boolean wantOnSelectionChangedNotifications() { return true; }
How to access above hierarchy in the markup
Pseudo Code: CompoundPropertyModelString labelModel = new CompoundPropertyModelString(labelProps); panel.setDefaultModel(labelModel); /* Load labels at the PANEL level */ panel.add(new Label(label[1])); form = new Form(new CompoundPropertyModel(myObj)) /* Load data at the form level */ panel.add(form); form.add(myObj.fieldName); ... Markup that will generate a error: panel.html: form wicket:id=theform div wicket:id=...someLabelFromPanelLevel / -- I want to access from the labelProps (this does not work) input wicket:id=someFieldFromMyObjFormLevel / -- I want to access from myObj (this works) /form ... With the current code, I can't access from the someLabelFromPanelLevel data or I will get a accessing outside of the hierarchy error message. I wish I could do the following (way to access higher up the hierarchy) Markup: panel.html: form wicket:id=theform div wicket:id=/PAGE:PANEL:someLabelFromPanelLevel / -- I want to access from the labelProps input wicket:id=someFieldFromMyObjFormLevel / -- I want to access from myObj /form - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Wicket: On RadioChoice component, invoke form submit, what am I missing
There are some components in wicket that seem to be associated with a form, but I can't get them to actually submit the form. Or at least, I can't get them to submit the form, if I have a hierarchy of FORM - PANEL - COMPONENT/RADIOCHOICE For example, I can create a submitlink or button and those components submit: return new SubmitLink(id, form) { @Override public void onSubmit() { this.setResponsePage(pageClass); } }; That works above. I want to be able to perform a submit on a radio choice, on change. E.g. new OnChangeHandler() { @Override public void onChange(final Object sel) { // On submission, submit back to form setResponsePage(Page.class); } // MY CONTAINER IS NOT A FORM BUT A CHILD OF A FORM (E.g. FORM - PANEL - RADIOCHOICE public RadioChoice addRadioGroup(final WebMarkupContainer container, final Object modelObject, final String groupName, final String propFieldName, final String [] optionsArr, final OnChangeHandler handler) { final RadioChoice radioGroupYesNo = new RadioChoice(groupName, new PropertyModel(modelObject, propFieldName), Arrays.asList(optionsArr)) { @Override public boolean wantOnSelectionChangedNotifications() { return (handler != null); /* When the handler is not null, enable on change */ } @Override public void onSelectionChanged(Object newSel) { if (handler != null) { handler.onChange(newSel); } else { super.onSelectionChanged(newSel); } } }; container.add(radioGroupYesNo); return radioGroupYesNo; } With the code shown above, the page refreshes, but I want to submit the form and do a page refresh. I don't see where I could associate the form with the RadioChoice? Does RadioChoice need to imlement IFormSubmittingComponent? Berlin Brown
Hierarchy mismatch with forms and hideable sections.
I am getting a hierarchy error message and the error makes sense, but how do you construct a form that also has hideable sections: This is what I had originally, a form and sub components. This works fine: Java: form = new Form(); panel.add(form); form.add(new TextField(t1)) form.add(new TextField(t2)) Html: form input wicket:id=t1 / input wicket:id=t2 / /form The above pseudo code works fine. Now I want to change to the following (html): Html: form input wicket:id=t1 / div wicket:id=hideableSectionDisabledInitially input wicket:id=t2 / /div /form ... What would I change in the java code so that the code is disaled initially, also such that the t2 text field is part of the form hierarchy (or at least I need to submit that with the form)? Berlin Brown
RE: Dynamic Resources, Properties
No, I was not using a properties file from the filesystem but it is an in memory string (the properties data). The properties data is loaded dynamically when the page is hit. -Original Message- From: Wilhelmsen Tor Iver [mailto:toriv...@arrive.no] Sent: Friday, June 18, 2010 2:29 AM To: users@wicket.apache.org Cc: Berlin Brown Subject: SV: Dynamic Resources, Properties add(new Label(weatherMessage, new StringResourceModel(weather.message, this, null))); If you put a property weather.message into the page's properties file then it will load from there (even if you provide a default in the panel's properties file). Is that what you mean? Properties are only read once no matter where they are resolved from. - Tor Iver - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Specific user/session properties and resources
I still want to use wicket message resource tags in my markup. But, I need a system to load and reload resources property data for each page and request. Or maybe load properties per user session. Is this possible using Wicket resource loader classes. Ideally, it looks like I should use a collection of labels, but I have code to use the wicket message tags. Can I have wicket messages reloaded at each page/request? This is what I am doing now, loading a property file on startup/init. But - import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.IOException; import java.util.InvalidPropertiesFormatException; import java.util.Locale; import java.util.Properties; import org.apache.wicket.Component; import org.apache.wicket.resource.loader.IStringResourceLoader; public class MyResourceLoader implements IStringResourceLoader { private Properties properties = new Properties(); public void loadProperties() { final BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(DevelopmentResources.XML_PROPS.getBytes())); try { properties.loadFromXML(bis); } catch (Exception e) { e.printStackTrace(); } finally { try { bis.close(); } catch (IOException e) { } } // End of try finally // } ... ... } Berlin Brown
Dynamic Resources, Properties
I want to be able to use the StringResourceModel, but I want to use a property string that is loaded when the page is loaded. Basically, I want to set a dynamic property object? With this code below, how can I do this. public class SomePanel extends BaseContentPanel { private static final long serialVersionUID = 1L; public SomePanel(String id) { super(id); add(new Label(weatherMessage, new StringResourceModel(weather.message, this, null))); } } Berlin Brown
Question about markup inheritance and page layouts
I was a little confused about page layouts and markup inheritance. I was thinking that a I could take a piece of HTML markup and reuse that component when I need to, and use it multiple times within page without ever having to create the content. I was not able to do this. What I have now, it seems I can only use parent child inheritance with one sub-component. Pseudo Code BasePage.java: public abstract class BasePage extends WebPage { public BasePage(final PageParameters parameters) { } } BasePage.html: html wicket:child / /html SomePage.java public class SomePage extends BasePage { public SomePage(final PageParameters parameters) { } } SomePage.html: wicket:extend div div wicket:id=myPanel/div div wicket:id=myPanel1/div /div /wicket:extend BasePanel.java ... BasePanel.html div wicket:child / /div MyPanel1.java extends BasePanel ... MyPane1l.html wicket:extend div /div /wicket:extend Basically: BasePage has child page - Some Page ... Some Page has child panels BasePanel - My Panel and My Panel1 ... I don't get the output I would expect. It looks like the markup inheritance stops at SomePage and doesn't recognize the BasePanel HTML child code. My intended goal is to avoid duplicating HTML content, what is the best way to achieve that. Maybe I should use markup inheritance for the panel instead of the page?
RE: Question about markup inheritance and page layouts
-Original Message- From: Jeremy Thomerson [mailto:jer...@wickettraining.com] Sent: Tuesday, June 15, 2010 11:26 AM To: users@wicket.apache.org Cc: Berlin Brown Subject: Re: Question about markup inheritance and page layouts On Tue, Jun 15, 2010 at 10:07 AM, Brown, Berlin [GCG-PFS] berlin.br...@primerica.com wrote: I was a little confused about page layouts and markup inheritance. I was thinking that a I could take a piece of HTML markup and reuse that component when I need to, and use it multiple times within page without ever having to create the content. I was not able to do this. What I have now, it seems I can only use parent child inheritance with one sub-component. Pseudo Code BasePage.java: public abstract class BasePage extends WebPage { public BasePage(final PageParameters parameters) { } } BasePage.html: html wicket:child / /html SomePage.java public class SomePage extends BasePage { public SomePage(final PageParameters parameters) { } } SomePage.html: wicket:extend div div wicket:id=myPanel/div div wicket:id=myPanel1/div /div /wicket:extend BasePanel.java ... BasePanel.html div wicket:child / /div MyPanel1.java extends BasePanel ... MyPane1l.html wicket:extend div /div /wicket:extend Basically: BasePage has child page - Some Page ... Some Page has child panels BasePanel - My Panel and My Panel1 ... I don't get the output I would expect. It looks like the markup inheritance stops at SomePage and doesn't recognize the BasePanel HTML child code. My intended goal is to avoid duplicating HTML content, what is the best way to achieve that. Maybe I should use markup inheritance for the panel instead of the page? Where did you place the wicket:panel tags in your markup? -- Jeremy Thomerson http://www.wickettraining.com They are in the SomePage: SomePage.html: wicket:extend div div wicket:id=myPanel/div div wicket:id=myPanel1/div /div /wicket:extend - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
RE: Question about markup inheritance and page layouts
-Original Message- From: Jeremy Thomerson [mailto:jer...@wickettraining.com] Sent: Tuesday, June 15, 2010 11:34 AM To: users@wicket.apache.org Cc: Berlin Brown Subject: Re: Question about markup inheritance and page layouts Where did you place the wicket:panel tags in your markup? -- Jeremy Thomerson http://www.wickettraining.com They are in the SomePage: SomePage.html: wicket:extend div div wicket:id=myPanel/div div wicket:id=myPanel1/div /div /wicket:extend No, the wicket:panel tags that must appear in the panel html files - where are they? Ooops, I got it working now and all the inheritance works as expected: In my base panel, I didn't include the wicket:panel (but I did put it in the implemeting panel html) Base Panel.html: wicket:panel ... /wicket:panel That change above, fixed the problem. -- Jeremy Thomerson http://www.wickettraining.com - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Newbie question anti-patterns and wicket, constructor component building
I am sorry, am just getting used to Wicket but I notice a lot of use of calling a lot of code in the constructor. Does it really matter? I mention it because this kind of style makes it difficult to test code because code in the constructor may fail and the object won't be created. Should I just create a method and call that method in the constructor?
RE: Newbie question anti-patterns and wicket, constructor component building
-Original Message- From: Jeremy Thomerson [mailto:jer...@wickettraining.com] Sent: Tuesday, June 15, 2010 3:25 PM To: users@wicket.apache.org Subject: Re: Newbie question anti-patterns and wicket, constructor component building On Tue, Jun 15, 2010 at 2:11 PM, Brown, Berlin [GCG-PFS] berlin.br...@primerica.com wrote: I am sorry, am just getting used to Wicket but I notice a lot of use of calling a lot of code in the constructor. Does it really matter? I mention it because this kind of style makes it difficult to test code because code in the constructor may fail and the object won't be created. Should I just create a method and call that method in the constructor? The constructor is supposed to construct the object. In Wicket, this also (typically) means constructing the component hierarchy. So, your constructor should be doing things like add(new FooPanel(foo, new SomeModel())); It should NOT be doing things like: ListFoo foos = SomeDao.loadAll(); new FooPanel(foo, foos); That's the kind of code I see newbs putting in their constructor all the time - and it should NOT be there. -- Jeremy Thomerson http://www.wickettraining.com - Well, the second version uses constructer injection. Some frameworks prefer that approach. But, I see your point. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org