ops, I just see: if you have an form with more than one form componente, that behavior will not work. So, it was just an idea :)
On Wed, Nov 25, 2009 at 2:13 PM, Pedro Santos <[email protected]> wrote: > Possible alternative that will work on current wicket version, since > MessageContainer is an private inner class > > public class AdjustLabel extends AbstractBehavior > { > @Override > public void beforeRender(Component component) > { > if (component instanceof FormComponent) > { > final FormComponent formComponent = > (FormComponent)component; > component.getParent().visitChildren(MarkupContainer.class, > new IVisitor<MarkupContainer>() > { > > public Object component(MarkupContainer > component) > { > if > (component.getId().startsWith("_message_")) > { > formComponent.setLabel(new > ResourceModel(component > > .getDefaultModelObjectAsString())); > return IVisitor.STOP_TRAVERSAL; > } > else > { > return null; > } > } > }); > } > } > } > > then you set: > > input.add(new AdjustLabel()); > > > On Wed, Nov 25, 2009 at 1:51 PM, Xavier López <[email protected]> wrote: > >> I forgot, >> >> A possible solution would be using a shared StringResourceModel for both >> the >> setLabel() method and providing the <label> tag like this: >> >> <label wicket:id="labelX"><span wicket:id="labelXText"></span></label> >> >> StringResourceModel m = new StringResourceModel("form.x.label", this, >> null); >> x.setLabel(m); >> FormComponentLabel labelX = new FormComponentLabel("labelX", x); >> form.add(labelX); >> Label labelXText = new Label("labelXText", m); >> >> But I'm looking for a less intrusive solution on pages already >> developed... >> >> Thanks, >> Xavier >> >> ---------- Forwarded message ---------- >> From: Xavier López <[email protected]> >> Date: 2009/11/25 >> Subject: Component.setLabel and <label> tags >> To: [email protected] >> >> >> Hi, >> >> In a form, I have multiple fields each one with its corresponding >> FormComponentLabel, with proper <wicket:message> content in the markup >> file. >> Now, I'm facing the fact that I need to provide the same keys I provided >> in >> <wicket:message> in a StringResourceModel in component's setLabel() >> method. >> >> Although I'm aware it's not straightforward (setLabel requires a Model, >> and >> <label>'s body is just body markup), it would be great if there was some >> way >> to avoid this duplication telling Wicket to use the same key provided in >> the >> FormComponentLabel's body... >> >> Does anyone have a hint ? >> >> Thanks, >> Xavier >> >> >> >> >> -- >> "Klein bottle for rent--inquire within." >> > > > > -- > Pedro Henrique Oliveira dos Santos > -- Pedro Henrique Oliveira dos Santos
