tags:

views:

31

answers:

2

I am making changes to an existing web application based on Struts1 - which already is made up of various forms & actions.

What I am trying to do is

  • Add a few pages for the mobile version of website.
  • For example, I want to add a JSP page that contains a form with a few fields (same as that in the PC version) with a submit button. On submit, I would like to call the same ACTION class which handled the form in the PC version.

Is this possible? Please point me to any links that explain the above.


Edit1:

a few lines from my struts-config.xml action-mappings.

  <action path="/signupPC"
          name="signupPCForm"
          validate="true"
          input="/signupFailedPC.jsp">
      <forward name="success" path="/signupSuccessPC.jsp" />
      <forward name="failure" path="/signupFailedPC.jsp" />
  </action>


@Nathan How do I add mobile specific pages here?

Should I add a new action path="/signupMobile" here? - which means adding < html:form action="/signupMobile.do" method="post" > to my mobile jsp?

I hope I don't have to add a new Form bean as I would like to make use of the same Form.java meant for PC based version.

+1  A: 

In your struts-config you have a set of action-mapping elements. For each actionMapping you have one or more forward elements. Each forward maps a relative url in the app to a string. Add a mobile-specific forward to the action mapping. ActionMapping has one entry for each forward for that mapping, you look them up by the string identifier you give it in struts-config. Then in your Action you'll need code to pull the right ActionForward out of the ActionMapping based on whether the action is being called from a PC url or a mobile url.

Nathan Hughes
Thanks @Nathan - could you give an example? I m new to struts.
Van de Graff
@Van de Graff: Changed this answer to a simpler approach. Check out your webapp and see if you recognize the pieces I'm talking about.
Nathan Hughes
+1  A: 

Nathan told you everything you need to know, I'm just adding an example of how I would write the struts-config file:

 <action path="/signup" 
      name="signupForm" 
      validate="true" 
      input="/signup.jsp"> 
      <forward name="successPC" path="/PC/signupSuccess.jsp" /> 
      <forward name="failurePC" path="/PC/signupFailed.jsp" />
      <forward name="successMobile" path="/mobile/signupSuccess.jsp" />
      <forward name="failureMobile" path="/mobile/signupSuccess.jsp" />
 </action>

You will call the same action(method of the java class) and depending on the device who called the method, you will forward to the PC success or the mobile success webpages.

Carlos Pastor
Thanks @carlos. what about **input="/signup.jsp"**? shouldn't a **mobile version** be specified also?The **name="signupForm"** here refers to the FORM bean used for **both MOBILE and PC versions** - is that right?
Van de Graff
Well, I added the input because you had it in your example. I believe I haven't ever used it in any of my actions but I can't be sure about that. Related to your second question: yes, it refers to the java form bean you have created and it should be the same as long as the behaviour is the same for both PC and mobile devices.
Carlos Pastor