Creating a form dynamically
I'm trying to build a form dynamically and am having a little problem. Basically I have a class that takes a List and then passes them into a ListView for display on screen. The problem is that they were created elsewhere and I have no control over two things: 1) The order/type of each FormComponent 2) The wicket:id that was chosen for them when the FormComponents were created I think I've solved 1) by creating wrapper classes for each supported FormComponent type... for example, I have a DropDownChoicePanel which simply adds the DropDownChoice it is passed to its html, which is simply a . This way I can simply wrap each FormComponent in the list with a panel and add all the panels to my listview rather than the components themselves -- this solves the problem of homogenizing the listview's HTML. But 2) is causing me problems, because unless I require all FormComponents to be given a wicket:id which is prespecified and is the same as that in the DropDownChoicePanel (wicket:id="component") then it will not work. Am I going about this all wrong? Is there any way I can receive a FormComponent and then change its wicket:id so that it will always be "component" in my ListView? Or is there a solution for this problem already? Much thanks for any advice.
Getting the display string for the selected option in a DropDownChoice
I am trying to write a generic behavior which needs to work for any DropDownChoice. I need to retrieve the selected option's display string. The problem is, much of the time I only store the ID (not the display), so using getModelObject() and running it through the DropDownChoice.getChoiceRenderer().getDisplayValue(T) does not work and only returns null. i.e. ddc.getChoiceRenderer().getDisplayValue(ddc.getModelObject()); I also cannot guarantee that the ID class's equals and hashcode functions will be implemented as expected, so this will not work: i.e. ddc.getChoices().get(ddc.getChoices().indexOf(ddc.getModelObject())); Is there a method I'm missing which I can call to return the dropdownchoice's display value of its internal list's selected option? Any other ideas?
Behavior to replace the contents between open and close ComponentTag tags
Can I remove/replace the contents between an open and close tags in the onComponentTag(component, tag) method of AbstractBehavior? I'm able to change the tag from an , or to as I wanted, but I am unable to remove the guts of the previous form component. When I do this with a it leaves behind all the tags. Here's what I have so far. I am able to update the attributes of the tag itself, but I can't seem to remove/replace the text between open and close tags: public void onComponentTag(final Component component, final ComponentTag tag) { if (!component.isEnabled()) { tag.setName("span"); tag.put("value", component.getDefaultModelObjectAsString()); //This only updates the "value" attribute of the tag, not the contents } I am trying to find a non-intrusive way to replace disabled components with labels. I started working on a Visitor but it does not seem to work since my page uses multiple ajax refreshes of various subsections of a form -- the Visitor works better for full page refreshes. I was about to subclass the various form elements (TextField, TextArea, DropDownChioce, etc) and then override their onBeforeRender methods to replace the components with labels if they were disabled, but I'm wondering if I can achieve this with a behavior instead.
Weird DatePicker / DateTextField off by one hour
I have a DateTextField to which I am adding a DatePicker. The Display works fine: if I select 4/1/2009 using the DatePicker and I save the form data to my database, then populate the form again from values in the database, I am seeing 4/1/2009. But when I look at my database I see that the stored date is actually 3/31/2009 23:00:00, which is 1 hour before 4/1/2009. This does not seem to be a Locale issue (that I can tell), as I am running everything on my local machine. Also, the odd thing is that when I select 4/1/2009 through 4/5/2009 I get a date stored in my database which is 1 hour before the selected date. But when I select anything from 4/6/2009 through 4/30/2009 the date is stored correctly. I added log statements when the info is loaded from the database and before it is persisted, and the issue is within the web application. When I print the dates before persisting them to the database they are wrong by 1 hour, for 4/1/2009 through 4/5/2009. I had the same issue with yui.DateField, but I'm not sure if this is a YUI DatePicker issue or something else I am not considering or doing correctly. Here's a snippet of my code: DateTextField appointmentPickerTextField = new DateTextField("dayOfYear", new PropertyModel(appointment, "dayOfYear"), new StyleDateConverter(false)) { @Override public boolean isVisible() { return appointment.getScheduledDate() != null; } }; appointmentPickerTextField .setRequired(true); appointmentPickerTextField .add(new DatePicker()); Any thoughts?
Reversing checkbox behavior or negating a property model expression
I'm scratching my head trying to figure out the best way to reverse the behavior of a checkbox, i.e. display an unchecked box when the model behind is true, and a checked box when the model behind is false. I don't want to negate all my domain objects' getters/setters to accomodate this. I was going to override the CheckBox.getConverter class to point to an extension of CheckBoxConverter with an overridden convertToObject method and simply reverse the: if ("on".equals(value) || "true".equals(value)) { return Boolean.TRUE; } else { return Boolean.FALSE; } Unfortunately the CheckBox.getConverter method is marked final, so this is not a possibility. I could override the onComponentTag method but I do not think it would be a good idea since there is a lot going on in there. Alternatively if there was a simple way to negate the value of the setter/getter in a PropertyModel I think that would do the trick, i.e. new CheckBox("checkbox", new PropertyModel(domainObject, "!blue")); Any suggestions?
Retrieving/serializing the javascript for an AjaxLink
I am trying to embed javascript links in some JSON which I pass to Open Flash Chart. I am able to test this by giving the "on-click" attribute of a chart element the value of "alert('testing')" and it pops up the alert as I expect. Now I need to create links to a Wicket page. All the links will go to the same page but I need to have different parameters depending on which element of my chart was clicked. I tried something like this but got null for the markup stream: AjaxLink lateLink = new AjaxLink ("late") { public void onClick(AjaxRequestTarget target) { setResponsePage(new CarPage(make, model, year)); return; } }; chart.setOnClick(lateLink.getMarkupStream()); How can I go about building a dynamic javascript link to a wicket page which I can pass into the flash object? The chart object is just a bean which I run through a converter to seralizize its attributes to JSON. Thanks for any help.
ResourceReferences not working as expected
I'm having trouble getting ResourceReferences to work for some reason, and was hoping somebody could give me some pointers. I'm using wicket 1.4. As a simple test I added a new page and put a "test.png" image in the same directory in my project. My structure is like so: project |--src |mypkg |--test |TestResource.java |test.png |--public_html |images |--test.png Java class: mypkg.test.TestResource.java ... ResourceReference ref = new ResourceReference(TestResource.class, "test.png"); System.out.println("Valid resource: " + (ref.getResource() != null)); ... This always returns false. I also tried putting the "test.png" in my public_html/images directory but no luck. I don't seem to have any luck getting these Resources to load correctly, so I've had to resort to hardcoding my javascript references into my html files. Anybody have any suggestions? I've verified that all the files are being copied to my output classes folder.