I have a web page in jsp extension , which is built using jsf. There are command links for some user ids, i.e. every user id is a command link. When a user id is clicked, it goes to another page, where some action can be done.
<h:commandLink value="#{user.userId}" rendered="#{bean.myName == 'ID1'}" action="#{bean.userIdHasBeenSelected}" immediate="true"/>
Now if the action returns a string called "notDone", i want to show an alert pop up in the jsp and the page will not be navigated and will remain in the same page. But , if the action returns the afore mentioned string , the page will just be not navigated..it will not be reloaded or refreshed..then how can i use window.onload here ?
If not window.onload , then is there any other way of doing it ? One point to be remembered is that, the action is evaluated at java side.
Any suggestions will be deeply appreciated.
Related
I am using Struts2, JSP for web development. Whenever a form is submitted the Java action class after updating the Database returns SUCCESS or ERROR, I am rendering on home page, but when I reload that home page again then I am getting null pointer exception because the variables (which were to be set when form submit button is clicked and action was called) are null in the action class. I want if the page is reloaded it remains in the same page.
One solution that I came up with is validate method of ActionSupport where i can check if the variables are null or not. Are there some other solutions which are better than this as this solution is not clean.
I am creating a web application in Java. I created some JSP pages each having some form fields. All are post method type so it hides all the form fields. In each page it will call servlet and forward to next JSP page(like a step by step process.)) Welcome page is index.jsp. In the last JSP page also I am having form field which is also post method type. When I press sumbit button, it will call servlet and should forwartd to home page(That is index.jsp).
Last page action value is finish. In my servlet, I am using RequestDispatcher and forwarding to index.jsp. The the URL will be
http://localhost:8080/myproject/finish.
As it is the home page, I wanted to hide that action value. So instead of RequestDispatcher I used
response.sendRedirect("index.jsp"); And then URL becomes
http://localhost:8080/myproject/index.jsp.
This is not a big issue. But still I am asking is there anyway to hide this index.jsp in the URL? It should be like when we open the site for the first time(http://localhost:8080/myproject/).
I got the answer finally. Thanks to #Sayem Ahmed for his reply as comments.
I tried this only
response.sendRedirect("/myproject");
In the base template for the pages of my Wicket application, there's a form I don't want Wicket to handle, like this:
<form id="myForm" action="">
<!-- input fields and submit button -->
</form>
I left the action attribute empty to always send it to the current page. On the application's main page, it works, but on other pages, Wicket adds a "../" in the action attribute, which seems to be meant well but is not what I want.
I'm using Wicket 1.4.17. How can I stop or change this behaviour?
The form is meant to enable the user to submit a short message as feedback to the site admin. It appears on every page and the input is collected from the PageParameters in the constructor of my pages' base class. If there is a more Wicket way to do this, I'll appreciate hints, but this should be a) stateless and b) very very simple.
I'd go the Wicket way and write a component for your feedback form which is then inserted into every page. As you have an (abstract) base class for all of your pages, you can simply add it there and it will appear on every page.
In your feedback form component, simply overwrite the onSubmit() method and send the message to the site admin.
I have a portlet which involves displaying several JSP pages.
In first JSP page A, when I click the Submit button on Page A the processAction() method takes action and a JSP page B appears.
Now if I use Web Browser's Back button to page A and click the Submit button again, the
JSP page B appears but I noticed the processAction() didn't take any action. (Usually clicking Submit button in a JSP page can result in the processAction() to take action).
Can anyone help for this problem? In my Porlet, it MUST go to the process action but it doesn't after back button.
This is the default behavior. Portal has "Multiple Action URL Protection " enabled by default. When a page loads, an action link is created and that link contains an action ID. The same action ID cannot be used again in the same session. So when you click on Back Button, if the page is loaded from the history cache, your Form contains the same action link which was used before. So portal simple reloads the page, rather than calling the processAction().
You can disable this by adding the following configuration for your portlet in portlet.xml file.
<init-param>
<name>wps.multiple.action.execution</name>
<value>true</value>
</init-param>
Without seeing any code, it sounds as if your form response may be cached. What is the method attribute on your <form> ? Forms submitted via GET (or no method attribute at all) are allowed to be cached; in which case neither the server nor your portlet's processAction(...) will be invoked - the browser will re-render the previous response from cache.
If you post some code there may be more offers to help...
Here is my situation: the user selects a section (for example from a dropdown) such as "Section1," "Section2" or "Section3." Then he clicks the OK button (or some link).
What I need to happen: after he clicks on that button/link, he will be redirected to the selected section, e.g. www.homepage.com/docs#section2.
So far, I have not been able to process the form from Link's onClick method, nor have I been able to call some clickLink on Link from the Button method onSubmit().
I would prefer not to use AJAX or JavaScript. How can I do this?
That's because a Link doesn't submit the form. It just acts as a link to somewhere. To access your formdata you'll need to submit the form first. Try using a SubmitLink instead of a Link and call
getRequestCycle().setRequestTarget
(new RedirectRequestTarget("www.homepage.com/docs#section2"));
from the onSubmit function of the SubmitLink.
Judging from the Javadoc this should work but I can't test it right now.
A RequestTarget that will send a redirect url to the browser. Use this if you
want to direct the browser to some external URL, like Google etc, immediately.
Or if you want to redirect to a Wicket page. If you want to redirect with a
delay the RedirectPage will do a meta tag redirect with a delay.
Did you try Link.setAnchor(Component)?