Thanks Igor,  I was having the same issue as Jason (see [Wicket-user]
Getting value of a text field via Ajax, no form )

I changed to using AjaxFormComponentUpdatingBehavior and all is happy.  

Thanks again, Tim


Igor Vaynberg wrote:

havent looked at your code but here is how i would do it

class mypanel extends panel {

   private String value;
   //getter+setter

   public mypanel() {
        TextField tf=new TextField("tf", new PropertyModel(this,
"value"));
        Label l=new Label("l", new propertyModel(this, "value"));

        .....
     }
}


-igor


On 3/8/07, Tim Squires <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm trying to get working a panel containing a TextField and a Label.
> The label contains the hex value for the TextField content.  The 
> TextField is Ajaxed so that it updates the label on each key press.
>
> Unfortunalty, I cannot retrieve the value from the TextField, it 
> always returns a null.  Will someone elighten me to the best way to 
> retrieve the current TextField value?
>
> Code is included below.
>
> Thanks for your help,
> Tim
>
> public class TextFieldWithHexValue extends Panel {
>
>         private static final Log logger = LogFactory
>                         .getLog(TextFieldWithHexValue.class);
>
>         @SuppressWarnings("serial")
>         public TextFieldWithHexValue(String id, final PropertyModel 
> model,
>                         int tabindex) {
>                 super(id);
>                 final TextField textField = new TextField("text field 
> with hex", model);
>                 textField.setOutputMarkupId(true);
>                 add(textField);
>
>                 textField.add(new AttributeModifier("tabindex", true, 
> new Model(
>                                 tabindex)));
>                 textField.setOutputMarkupId(true);
>
>                 // Server Port Hex
>                 Model hexModel = new Model() {
>                         public Object getObject(Component arg0) {
>                                 logger.debug("Calculating hex 
> value...");
>                                 String value = model.getObject(null) +

> "";
>                                 logger.debug("Pre hexed value = " + 
> value);
>
>                                 if (StringUtils.isNotEmpty(value)) {
>                                         StringBuffer buffer = new 
> StringBuffer();
>                                         StringTokenizer tokens = new 
> StringTokenizer(value, ".");
>                                         while (tokens.hasMoreTokens())
{
>                                                 String token = 
> tokens.nextToken();
>                                                 try {
>                                                         Integer hex = 
> new Integer(token);
>
> buffer.append(StringUtils.leftPad(Integer
>
> .toHexString(hex), 2, '0'));
>                                                 } catch 
> (NumberFormatException e) {
>
> logger.warn("Unable to format >>" + token
>
> + "<< to hex");
>                                                 }
>                                         }
>                                         return 
> buffer.toString().toUpperCase();
>                                 } else
>                                         return "";
>                         }
>                 };
>                 final Label hexLabel = new Label("hex for text field",
>                                 hexModel);
>                 hexLabel.setOutputMarkupId(true);
>
>                 textField.add(new AjaxEventBehavior("onkeypress") {
>                         protected void onEvent(AjaxRequestTarget 
> target) {
>                                 logger.debug("value has changed, 
> recalculate hex value....");
>                                 target.addComponent(hexLabel);
>                         }
>                 });
>                 add(hexLabel);
>         }
> }
>

________________________________________________________________________
The Information contained in this e-mail message is intended only for
the individuals named above. If you are not the intended recipient,
you should be aware that any dissemination, distribution, forwarding
or other duplication of this communication is strictly prohibited.
The views expressed in this e-mail are those of the individual
author and not necessarily those of LINK Interchange Network Ltd.
Prior to taking any action based upon this e-mail message you should
seek appropriate confirmation of its authenticity. If you have
received this e-mail in error, please notify the sender immediately.
________________________________________________________________________

LINK Interchange Network Limited
Tel: 01423 356000, Fax: 01423 356356
email: [EMAIL PROTECTED]  http://www.link.co.uk
Registered in ENGLAND Number. 3565766
Registered Office: Arundel House * 1 Liverpool Gardens * Worthing * West 
Sussex* BN11 1SL

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to