Domanda

First, please note I know the following code is not in JavaScript or jQuery but I just added them as tags of this question in hope of finding a solution for it using Javascript or jQuery.

I have a form with three submit buttons. The problem is that, when I submit the form with either of the buttons the result page will be sent to the same address. I need it to be in a different address.

Purpose:

The code is supposed to show a list of items for a specific category in a page called view. User selects few items and submit the form. Server needs to show the details of the selected items in a page called update (separate address with view page). Then user is able to edit the details of items and submit the form to update the details of those items.

Requirement:

lets say address is

myexample.com/Product/view      //shows view page

after clicking on edit, it should redirect to following address.

myexample.com/Product/update     //shows update page ( show details of selected products)

Potential Solution:

Based on Roman C's answer, after receiving the request, I pass the products list to the other action to show update page, but it shows it as following on the address; therefore, update page does not recognize products parameter as a list.

...products=[1%2C+2]&id=1

Java:

List <Integer> products = new ArrayList();
   

Struts redirect:

   <result name="updateProducts" type="redirectAction">
            <param name="actionName">update</param>
            <param name="namespace">/products/Update</param>
            <param name="products">${products}</param>
            <param name="id">${id}</param>
   </result>

Even if I manually send the following request, the action class does not recognize products parameter as a list. It shows it's size is Zero.

 ...products=[1,2]&id=1
È stato utile?

Soluzione

You should add a redirectAction result to the action config of the action that processes a submit request. In your case it has an edit name, that is confusing, should name like save or update because when you name it edit many programmers think like you are making a request to populate some textfields. But it's not true, your edit action doesn't populate, rather than submits to the server. After submit you should follow the Post-Redirect-Get pattern and return a redirectAction or redirect result to the other action or URL not nessesary to view or edit actions if you don't want to stay on the page after redirecting. Remove the edit action config as it has covered by the wildcard mapping. Add the save button

<s:submit id="saveBtn" action="save" value="Save"/>

add and return redirect action result from the save action

<action name="save" method="save" class="myexample.Product">
  <result type="redirectAction" name="list" />
</action>   

Altri suggerimenti

How to redirect user to different pages based on the submit button of the form that is pressed:

URL redirection is a World Wide Web technique for making a web page available under more than one URL address. When a web browser attempts to open a URL that already has been redirected, a page with a different URL is opened.

For example, www.example.com is redirected to example.iana.org. 

Similarly, Domain redirection or domain forwarding is when all pages in a URL domain are redirected to a different domain, as when wikipedia.com and wikipedia.net are automatically redirected to wikipedia.org.

URL redirection can be used for URL shortening, to prevent broken links when web pages are moved, to allow multiple domain names belonging to the same owner to refer to a single web site, to guide navigation into and out of a website, for privacy protection, and for less innocuous purposes such as phishing attacks.

<form action="http://example.org/ jmail1.java">
<input type="submit" value="Go To jmail1.java">
</form>

<form action="http://example.org/jmail2.java">
<input type="submit" value="Go To jmail2.java">
</form>

Techniques:

Several different kinds of response to the browser will result in a redirection. These vary in whether they affect HTTP headers or HTML content. The techniques used typically depend on the role of the person implementing it and their access to different parts of the system.

For example, a web author with no control over the headers might use a Refresh meta tag whereas a web server administrator redirecting all pages on a site is more likely to use server configuration.

<action name="foo"> 
   <result type="redirectAction"> 
      <param name="actionName">bar</param> 
      <param name="namespace">/</param> 
   </result> 
</action>

Although Info path gives you the ability to create a custom message after submission, lots of users have requested more than that. They haven’t been happy with the way the form just leaves you sitting there in the List, it can be confusing. So we have a way in which you can make an InfoPath form function like a traditional web form wherein you fill out the form and upon clicking the ‘Submit’ button, the user is taken to a Thank You page

Resolution:

  1. Create a Thank You page and save it somewhere on your site. We recommend using any editor, like Notepad or SharePoint Designer to create an html page with a message of your choosing such as “Thank You for your submission”

  2. Click on that Thank You page and record the URL I.E., it will look something like this: http://mydomain.com/sites/YourSite/YourDocLibrary/ThankYou.html

  3. Now you need to figure out the URL to your InfoPath form. Either click on it and record the URL or if you have attached the InfoPath form to a SharePoint List, then you will need to alter the URL like this: http://mydomain.com/sites/YourSite/YourList/NewForm.aspx, as you can see we just added the NewForm.aspx to the end of it.

  4. Take the URL you recorded in step 3 and add the following:? Source=http://mydomain.com/sites/YourSite/YourDocLibrary/ThankYou.html, So the URL should look like this: http://mydomain.com/sites/YourSite/YourList/NewForm.aspx?Source=http://mydomain.com/sites/YourSite/YourDocLibrary/ThankYou.html << this is the link you will send to your users in order to fill out your form. When your users click on this new link, it will tell SharePoint to automatically redirect them to your Thank You page after they submit.

  5. On that Thank you page you can add a link to go to another page or you can get real fancy and add a Meta refresh tag to automatically take redirect your users, for example, to the home page of your site. How do you do that? Simple. Add this line: <meta http-equiv="refresh" content="2;url=http://mydomain.com/sites/yourSite/"> in between the tags of your HTML page. Just to explain a little more about that line, the number 2 in this case represents 2 seconds. So you can modify that to keep the user on that page longer or shorter by replacing that number with a different one. The url would be the url of your home page or any other site you want to redirect the user to.

<table><tr> <td><s:submit name="update" value="Update" action="update" ></s:submit></td> <td><s:submit name="delete" value="Delete" action="delete" ></s:submit></td> </tr></table>

<action name="update"
        class="net.viralpatel.struts2.action.MemberCrudOpertaions"
        method="updateUser">
        <result>members.jsp</result>
</action>

<action name="delete"
        class="net.viralpatel.struts2.action.MemberCrudOpertaions"
        method="deleteUser">
        <result>members.jsp</result>
</action>`

Manual redirect:

The simplest technique is to ask the visitor to follow a link to the new page, usually using an HTML anchor like:

Please follow <a href="http://www.example.com/">this link</a>.

This method is often used as a fall-back — if the browser does not support the automatic redirect, the visitor can still reach the target document by following the link.

Default redirect:

The Default redirect technique is to ask the visitor to follow a link to the new page, usually using an HTML with JSP like:

<html>
<%
String redirectURL = "http://stackoverflow.com/";
response.sendRedirect(redirectURL);
%>
</html>

http://struts.apache.org/release/2.2.x/docs/redirect-action-result.html

http://struts.apache.org/development/2.x/docs/multiple-submit-buttons.html

http://struts.apache.org/development/2.x/docs/submit.html

http://struts.apache.org/release/2.2.x/docs/interceptors.html

related source : http://en.wikipedia.org/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top