how to insert a button that can not refresh a jsp page?

View: New views
3 Messages — Rating Filter:   Alert me  

how to insert a button that can not refresh a jsp page?

by katerinab :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

 hi,

 i have created a jsp page that appears some results and I want to add a button that performs an action. The problem is that when the user clicks on the button, an error appears and the log reports: "Caused by: java.lang.NullPointerException".
 Is there any way to make the button perform the action I want, without refreshing the page? Otherwise, I lose the results and that's why the error appears.

Thank you in advance.
Katerina

Re: how to insert a button that can not refresh a jsp page?

by Chris Kutler :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Because you wrote this to the visualweb users alias, I assume that you
are using JavaServer Faces. My answer is based on this assumption.

I also assume that the action you write about  is the action event
handler that you coded in the backing bean (the Java source) for the JSP
page.

The way it works with JavaServer Faces is that when the user clicks a
button the page is submitted, and, on the receiving end, the server
performs the action event handler. The page must be submitted in order
for the server to receive it and process the action.

If you do not want the button to submit the page, you can do one of the
following

o Write JavaScript to do the action handling. Stop the button from
submitting the page by modifying the onClick property. I do something
like that here http://blogs.sun.com/divas/entry/adding_a_popup_window_to

o Use virtual forms or dynamic faces to not submit the whole form. I
show an example of using dynamic faces to not submit the whole page
here:
http://blogs.sun.com/divas/entry/using_dynamic_faces_for_coordinated. A
virtual forms tutorial is here:
http://www.netbeans.org/kb/55/virtual-forms.html

o Write your own Ajax handlers or use jMaki. Resources include:
http://www.javapassion.com/handsonlabs/5655_ajaxcreator.zip,
http://developers.sun.com/learning/javaoneonline/j1lab.jsp?lab=LAB-4420&yr=2007&track=8,  
http://developers.sun.com/learning/javaoneonline/j1lab.jsp?lab=LAB-4450&yr=2007&track=8

If you are using JavaServer Faces, you should not be loosing the results
when the page is submitted. When the server sends the results (and the
page redisplays) the server should return all values that are bound to
the components, if they are are in the right scope. So the question is
what are the input components bound to such that you are loosing the
values?

To better understand, maybe you might want to try this tutorial:
http://www.netbeans.org/kb/60/web/scopes.html or
http://www.netbeans.org/kb/55/vwp-scopes.html depending on which version
of NetBeans you are using.


katerinab wrote:

>  hi,
>
>  i have created a jsp page that appears some results and I want to add a
> button that performs an action. The problem is that when the user clicks on
> the button, an error appears and the log reports: "Caused by:
> java.lang.NullPointerException".
>  Is there any way to make the button perform the action I want, without
> refreshing the page? Otherwise, I lose the results and that's why the error
> appears.
>
> Thank you in advance.
> Katerina
>  

--
Chris Kutler, Technical Writer for Ruby Support in the NetBeans IDE
http://blogs.sun.com/divas
------------------------------------------------------------------
Did you know a cat has 32 muscles in each ear.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: how to insert a button that can not refresh a jsp page?

by IOLAUS :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Disable the form submit Button with onClick="yourJavaScriptCode(); return false";
Notice, the Button must have the name "button1" for this example!


In the JavaScriptCode insert the following code:

function yourJavaScriptCode() {

     ...do somethink here;

     // your js submit the Form and get the action_Listener code for this button
     document.getElementById("form1:button1").click() = true;
}

I hope its helpfully




katerinab wrote:
 hi,

 i have created a jsp page that appears some results and I want to add a button that performs an action. The problem is that when the user clicks on the button, an error appears and the log reports: "Caused by: java.lang.NullPointerException".
 Is there any way to make the button perform the action I want, without refreshing the page? Otherwise, I lose the results and that's why the error appears.

Thank you in advance.
Katerina