You should use a writable model like PropertyModel. Read the documentation
for more info.

So i rewrite your code like this:

try this

First, Create a Backing Bean which will hold 2 values, the value of the
TICKER SYMBOL and the value of the Stock Answer
class StockBean implements Serializable {
  private String stockSymbol;
  private int stockValue;
 ..getter
..setter
}

public class GetQuoteSymbol extends WebPage {
   //declare the backing bean
   private StockBean beanModel;

   public GetQuoteSymbol() {

       Form form = new Form("f") {

           protected void onSubmit() {
               String sym = beanModel.getStockSymbol();  //(String)
model.getObject();
               int stockValue = sym.hashCode() % 100;
               beanModel.setStockValue(stockValue);
          if you want it to display the answer, dont bother forwarding the
pag
              // setResponsePage(this);
           }
       };
// create the backing bean
       beanModel = new StockBean();

//Use propertymodels to map the attributes of a backing bean to a Textfield
or other components
//First parameter is the expression that shows the bean property to map to.
and the other parameter is the bean to map to

       PropertyModel stockSymModel= new
PropertyModel("stockSymbol",beanModel); // this model will be used by the
textfield

       TextField stockField = new TextField("stockField ", stockSymModel);


       PropertyModel stockValModel= new
PropertyModel("stockValue",beanModel); // this model will be used by the
Label that will tell us the answer

       Label valueLabel= new Label("stockLabel", beanModel);

       form.add(stockField );
        form.add(valueLabel);
       add(form);

   }

}

 <form wicket:id="f">
Please Provide your Symbol
           <input type="text" wicket:id="stockField ">
The Present Stock Quote is
<span wicket:id="stockLabel">
0.00
</span>
           <input type="submit" value="Ok">
       </form>

Hope this helps

On 5/11/08, kengimel <[EMAIL PROTECTED]> wrote:
>
>
> Hi,
>
> I am new to wicket and while trying out this snippet of code.
>
>
> public class GetQuoteSymbol extends WebPage {
>
>     private Model model;
>
>     public GetQuoteSymbol() {
>
>         Form form = new Form("f") {
>
>             protected void onSubmit() {
>                 String sym = (String) model.getObject();
>                 int stockValue = sym.hashCode() % 100;
>                 QuoteResult quoteResult = new QuoteResult(stockValue);
>                 setResponsePage(quoteResult);
>             }
>         };
>         Model model = new Model("MSFT");
>         TextField symbol = new TextField("sym", model);
>
>         form.add(symbol);
>         add(form);
>
>     }
>
> }
>
>
>
>     <head>
>
>         <title>GetQuoteSymbol</title>
>         <link rel="stylesheet" type="text/css" href="style.css"/>
>     </head>
>     <body>
> <!--         -->
>
>         <form wicket:id="f">
>             <input type="text" wicket:id="sym">
>             <input type="submit" value="Ok">
>         </form>
>     </body>
> </html>
>
>
> public class QuoteResult extends WebPage {
>     public QuoteResult(int stockValue) {
>
>         add(new Label("v", Integer.toString(stockValue)));
>     }
>
> }
>
> <html xmlns:wicket>
>     <head>
>         <meta http-equiv="Content-Type" content="text/html;
> charset=UTF-8"/>
>         <title>QuoteResult</title>
>         <link rel="stylesheet" type="text/css" href="style.css"/>
>     </head>
>     <body>
>         <!--         -->
>         The stock value is: 100.
>     </body>
> </html>
>
> when i execute the code i encountered.
>
> this error::
>
> WicketMessage: Method onFormSubmitted of interface
> org.apache.wicket.markup.html.form.IFormSubmitListener targeted at
> component
> [MarkupContainer [Component id = f, page =
> myapp.stockquote.GetQuoteSymbol,
> path = 2:f.GetQuoteSymbol$1, isVisible = true, isVersioned = true]] threw
> an
> exception
>
> Root cause:
>
> java.lang.NullPointerException
> at myapp.stockquote.GetQuoteSymbol$1.onSubmit(GetQuoteSymbol.java:26)
> at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1328)
> at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:776)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
>
> org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:183)
> at
>
> org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
> at
>
> org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91)
> at
>
> org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1166)
> at org.apache.wicket.RequestCycle.step(RequestCycle.java:1243)
> at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1331)
> at org.apache.wicket.RequestCycle.request(RequestCycle.java:493)
> at
> org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:363)
> at
>
> org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:194)
> at
>
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
> at
>
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
> at
>
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
> at
>
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
> at
>
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
> at
>
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
> at
>
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
> at
>
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
> at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
> at
>
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
> at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
> at java.lang.Thread.run(Thread.java:619)
>
> Complete stack:
>
> org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of
> interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted
> at
> component [MarkupContainer [Component id = f, page =
> myapp.stockquote.GetQuoteSymbol, path = 2:f.GetQuoteSymbol$1, isVisible =
> true, isVersioned = true]] threw an exception
> at
>
> org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:194)
> at
>
> org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
> at
>
> org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91)
> at
>
> org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1166)
> at org.apache.wicket.RequestCycle.step(RequestCycle.java:1243)
> at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1331)
> at org.apache.wicket.RequestCycle.request(RequestCycle.java:493)
> at
> org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:363)
>
> java.lang.reflect.InvocationTargetException
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
>
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
>
> org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:183)
> at
>
> org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
> at
>
> org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91)
> at
>
> org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1166)
> at org.apache.wicket.RequestCycle.step(RequestCycle.java:1243)
> at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1331)
> at org.apache.wicket.RequestCycle.request(RequestCycle.java:493)
> at
> org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:363)
>
> can someone tell me what might be wrong..... thanks
>
> --
> View this message in context:
> http://www.nabble.com/Problem-with-Textfield-tp17170575p17170575.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


-- 
Aladejebi Ayodeji A.,
DabarObjects Solutions
Phone: +234 9 481 7 156
Mobile: +234 803 589 1780
Email: [EMAIL PROTECTED]
Web: www.dabarobjects.com
Blog: blog.dabarobjects.com

Participate, Collaborate, Innovate
Join Community:
http://www.cowblock.net/

Get A Free Blog:
http://blogs.cowblock.net/

Reply via email to