You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by kumar ramanathan <ku...@gmail.com> on 2014/06/27 06:33:51 UTC
how to handle null pointer exception while submit button
Hi Friends,
I have a text box and a submit button , If i pressed submit button without
entering anything in textbox , am getting null pointer exception . Can you
please help us on it ?
Thanks,
Kumar
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-handle-null-pointer-exception-while-submit-button-tp4666392.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: how to handle null pointer exception while submit button
Posted by Mihir Chhaya <mi...@gmail.com>.
Hmmm...then that leaves a question open on my side that why I didn't get
NPE with that code?
One more thing I observed and you might have already taken care of in your
actual code, but any reason not writing generics type
TextField<Type>/Model<Type> etc in your component?
-Mihir.
On Fri, Jun 27, 2014 at 10:51 PM, kumar ramanathan <kumarramanatha@gmail.com
> wrote:
> Thanks for reviewing the issue.I have actually fixed my problem.I have used
> setconvertemptyinputstrngtonull method.
>
> TextField memberIdField = new
> TextField("memberId",memberIdModel);
> *memberIdField.setConvertEmptyInputStringToNull(false);*
> TextField lossIdField = new
> TextField("lossId",lossIdModel);
> lossIdField.setConvertEmptyInputStringToNull(false);
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/how-to-handle-null-pointer-exception-while-submit-button-tp4666392p4666404.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: how to handle null pointer exception while submit button
Posted by kumar ramanathan <ku...@gmail.com>.
Thanks for reviewing the issue.I have actually fixed my problem.I have used
setconvertemptyinputstrngtonull method.
TextField memberIdField = new
TextField("memberId",memberIdModel);
*memberIdField.setConvertEmptyInputStringToNull(false);*
TextField lossIdField = new TextField("lossId",lossIdModel);
lossIdField.setConvertEmptyInputStringToNull(false);
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-handle-null-pointer-exception-while-submit-button-tp4666392p4666404.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: how to handle null pointer exception while submit button
Posted by Mihir Chhaya <mi...@gmail.com>.
Kumar,
I ran following (copied from your code) and it is showing me the value for
memberNumber. No NPE. Since you have String as memberID, I have assigned
String type to the models and property variable.
PropertyModel<String> memberIdModel=new
PropertyModel<String>(this,"memberNumber");
TextField<String> memberIdField = new
TextField<String>("memberId",memberIdModel);
Form<?> form = new Form<Void>("form"){
/**
*
*/
private static final long serialVersionUID = 1L;
/* (non-Javadoc)
* @see org.apache.wicket.markup.html.form.Form#onSubmit()
*/
@Override
protected void onSubmit() {
System.out.println(memberNumber.equals("5566"));
}
};
add(form);
As Sven has mentioned, stacktrace might be more helpful.
On Fri, Jun 27, 2014 at 6:16 AM, kumar ramanathan <ku...@gmail.com>
wrote:
>
> PropertyModel memberIdModel=new PropertyModel(this,"memberNumber");
> PropertyModel lossIdModel=new PropertyModel(this,"lossNumber");
> TextField memberIdField = new TextField("memberId",memberIdModel);
> TextField lossIdField = new TextField("lossId",lossIdModel);
>
> Form form=new Form("form1"){
> public void onSubmit(){
>
>
> flag=0;
> assignments.clear();
> estimates.clear();
> assignments.add(new
> AssignmentDB("MemberId","LossId","AssignemntId","DOL"));
> assignments.add(new
> AssignmentDB("1234","001","1357","10/12/1067"));
> assignments.add(new
> AssignmentDB("1234","001","1358","10/12/1067"));
> assignments.add(new
> AssignmentDB("1234","003","1357","10/12/1067"));
>
> for(int i=1;i<assignments.size();){
>
> if(memberNumber.equals(assignments.get(i).getMemberId())){
> System.out.println("inside2");
>
> if(lossNumber.equals(assignments.get(i).getLossId())){
> System.out.println("inside3");
> i=i+1;
> }
> else{
> assignments.remove(i);
> i=1;
> }
>
> }
> else{
> assignments.remove(i);
> i=1;
> }
>
> }
> if(assignments.size()<=1){
>
> setAsssignmentLabel("Assignments Output");
> assignments.clear();
> setAsssignmentResult("No Assignments for the given
> member number and loss number");
> setEstimateResult("");
> setEstimateLabel("");
> }
> else{
> setAsssignmentLabel("Assignments Ouput");
>
> setAsssignmentResult("");
> setEstimateResult("");
> }
> }//form submit
>
>
> };//form
>
> form.add(memberIdField);
> form.add(lossIdField);
> add(form);
>
>
> This is my code snippet . Kindly help me.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/how-to-handle-null-pointer-exception-while-submit-button-tp4666392p4666396.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: how to handle null pointer exception while submit button
Posted by kumar ramanathan <ku...@gmail.com>.
PropertyModel memberIdModel=new PropertyModel(this,"memberNumber");
PropertyModel lossIdModel=new PropertyModel(this,"lossNumber");
TextField memberIdField = new TextField("memberId",memberIdModel);
TextField lossIdField = new TextField("lossId",lossIdModel);
Form form=new Form("form1"){
public void onSubmit(){
flag=0;
assignments.clear();
estimates.clear();
assignments.add(new
AssignmentDB("MemberId","LossId","AssignemntId","DOL"));
assignments.add(new
AssignmentDB("1234","001","1357","10/12/1067"));
assignments.add(new
AssignmentDB("1234","001","1358","10/12/1067"));
assignments.add(new
AssignmentDB("1234","003","1357","10/12/1067"));
for(int i=1;i<assignments.size();){
if(memberNumber.equals(assignments.get(i).getMemberId())){
System.out.println("inside2");
if(lossNumber.equals(assignments.get(i).getLossId())){
System.out.println("inside3");
i=i+1;
}
else{
assignments.remove(i);
i=1;
}
}
else{
assignments.remove(i);
i=1;
}
}
if(assignments.size()<=1){
setAsssignmentLabel("Assignments Output");
assignments.clear();
setAsssignmentResult("No Assignments for the given
member number and loss number");
setEstimateResult("");
setEstimateLabel("");
}
else{
setAsssignmentLabel("Assignments Ouput");
setAsssignmentResult("");
setEstimateResult("");
}
}//form submit
};//form
form.add(memberIdField);
form.add(lossIdField);
add(form);
This is my code snippet . Kindly help me.
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-handle-null-pointer-exception-while-submit-button-tp4666392p4666396.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: how to handle null pointer exception while submit button
Posted by Mihir Chhaya <mi...@gmail.com>.
Can you share your code snippet? Which type of model are you using?
On Fri, Jun 27, 2014 at 1:17 AM, Sven Meier <sv...@meiers.net> wrote:
> #setConvertEmptyInputStringToNull(false) could help, but with a
> stacktrace we can give you a better advice.
>
> Sven
>
>
> On 06/27/2014 06:33 AM, kumar ramanathan wrote:
>
>> Hi Friends,
>> I have a text box and a submit button , If i pressed submit button without
>> entering anything in textbox , am getting null pointer exception . Can you
>> please help us on it ?
>>
>>
>> Thanks,
>> Kumar
>>
>> --
>> View this message in context: http://apache-wicket.1842946.
>> n4.nabble.com/how-to-handle-null-pointer-exception-while-
>> submit-button-tp4666392.html
>> Sent from the Users forum mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: how to handle null pointer exception while submit button
Posted by Sven Meier <sv...@meiers.net>.
#setConvertEmptyInputStringToNull(false) could help, but with a
stacktrace we can give you a better advice.
Sven
On 06/27/2014 06:33 AM, kumar ramanathan wrote:
> Hi Friends,
> I have a text box and a submit button , If i pressed submit button without
> entering anything in textbox , am getting null pointer exception . Can you
> please help us on it ?
>
>
> Thanks,
> Kumar
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-handle-null-pointer-exception-while-submit-button-tp4666392.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: how to handle null pointer exception while submit button
Posted by Paul Bors <pa...@bors.ws>.
Must be the wrong mailing list, ignore :)
On Sun, Oct 5, 2014 at 11:15 PM, Warren Bell <wa...@clarksnutrition.com>
wrote:
> OK, a little confused, AWT, Applet ? Is Wicket up to something I haven’t
> heard about ?
>
> Warren
>
> On Oct 5, 2014, at 7:57 PM, Taught by S&M <qa...@gmail.com>
> wrote:
>
> > This code will help to handle exceptions when there is a single
> TextField:
> >
> > import java.awt.*;
> > import java.awt.event.*;
> > import java.applet.*;
> >
> > /*
> > <applet code="throwsDemo.class" height=250 width=300>
> > </applet>
> > */
> >
> > class FieldZeroException extends Exception
> > {
> > FieldZeroException()
> > {
> > }
> >
> > public String toString()
> > {
> > return "Text field is empty.";
> > }
> > }
> >
> > public class throwsDemo extends Applet implements ActionListener
> > {
> > Button b1;
> > TextField tf1,tf2;
> > Label l1,l2;
> >
> > public void init()
> > {
> > setLayout(new FlowLayout(FlowLayout.LEFT));
> > l1=new Label("NULL");
> > l1.setForeground(Color.RED);
> > l2=new Label();
> > l2.setForeground(Color.GREEN);
> > tf1=new TextField(10);
> > b1=new Button("Check");
> > add(tf1);
> > add(b1);
> > add(l1);
> > add(l2);
> > b1.addActionListener(this);
> > }
> >
> > public void actionPerformed(ActionEvent ae)
> > {
> > if(ae.getSource()==b1)
> > {
> > String str1=tf1.getText();
> > int i=str1.length();
> > try
> > {
> > if(i==0)
> > {
> > throw new FieldZeroException();
> > }
> > else
> > {
> > l1.setText("Success");
> > }
> > }
> > catch(FieldZeroException fze)
> > {
> > l1.setText(fze.toString());
> > }
> > }
> > }
> > }
> >
> > --
> > View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/how-to-handle-null-pointer-exception-while-submit-button-tp4666392p4667826.html
> > Sent from the Users forum mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
> > --
> > This email was Virus checked by Clark's Nutrition's Astaro Security
> Gateway.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: how to handle null pointer exception while submit button
Posted by Warren Bell <wa...@clarksnutrition.com>.
OK, a little confused, AWT, Applet ? Is Wicket up to something I haven’t heard about ?
Warren
On Oct 5, 2014, at 7:57 PM, Taught by S&M <qa...@gmail.com> wrote:
> This code will help to handle exceptions when there is a single TextField:
>
> import java.awt.*;
> import java.awt.event.*;
> import java.applet.*;
>
> /*
> <applet code="throwsDemo.class" height=250 width=300>
> </applet>
> */
>
> class FieldZeroException extends Exception
> {
> FieldZeroException()
> {
> }
>
> public String toString()
> {
> return "Text field is empty.";
> }
> }
>
> public class throwsDemo extends Applet implements ActionListener
> {
> Button b1;
> TextField tf1,tf2;
> Label l1,l2;
>
> public void init()
> {
> setLayout(new FlowLayout(FlowLayout.LEFT));
> l1=new Label("NULL");
> l1.setForeground(Color.RED);
> l2=new Label();
> l2.setForeground(Color.GREEN);
> tf1=new TextField(10);
> b1=new Button("Check");
> add(tf1);
> add(b1);
> add(l1);
> add(l2);
> b1.addActionListener(this);
> }
>
> public void actionPerformed(ActionEvent ae)
> {
> if(ae.getSource()==b1)
> {
> String str1=tf1.getText();
> int i=str1.length();
> try
> {
> if(i==0)
> {
> throw new FieldZeroException();
> }
> else
> {
> l1.setText("Success");
> }
> }
> catch(FieldZeroException fze)
> {
> l1.setText(fze.toString());
> }
> }
> }
> }
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-handle-null-pointer-exception-while-submit-button-tp4666392p4667826.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
> --
> This email was Virus checked by Clark's Nutrition's Astaro Security Gateway.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: how to handle null pointer exception while submit button
Posted by Taught by S&M <qa...@gmail.com>.
This code will help to handle exceptions when there is a single TextField:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="throwsDemo.class" height=250 width=300>
</applet>
*/
class FieldZeroException extends Exception
{
FieldZeroException()
{
}
public String toString()
{
return "Text field is empty.";
}
}
public class throwsDemo extends Applet implements ActionListener
{
Button b1;
TextField tf1,tf2;
Label l1,l2;
public void init()
{
setLayout(new FlowLayout(FlowLayout.LEFT));
l1=new Label("NULL");
l1.setForeground(Color.RED);
l2=new Label();
l2.setForeground(Color.GREEN);
tf1=new TextField(10);
b1=new Button("Check");
add(tf1);
add(b1);
add(l1);
add(l2);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b1)
{
String str1=tf1.getText();
int i=str1.length();
try
{
if(i==0)
{
throw new FieldZeroException();
}
else
{
l1.setText("Success");
}
}
catch(FieldZeroException fze)
{
l1.setText(fze.toString());
}
}
}
}
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/how-to-handle-null-pointer-exception-while-submit-button-tp4666392p4667826.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org