Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Iterating with struts

Posted on 2011-10-29
4
Medium Priority
?
412 Views
Last Modified: 2012-05-12
Hi,

I have the following code:

<form method="POST" action="details.jsp?code=">
      <table>
            <tr><td><input type="button" value="Back" onClick="history.go(-1);" class='Commandbutton'/></td><td><input type="submit" align='right' value="New" class='Commandbutton'/></tr>
            <tr><th><b>Code</b></th><th><b>Decode</b></th></tr>
<%
      for(int ii=0; ii<code.length; ii++) {
%>
            <tr><td><a href="details.jsp?code=<%=code[ii]%>&decode=<%=decode[ii]%>"><%=code[ii]%><a></td><td><%=decode[ii]%></td></tr>
<%
      }
%>
            <tr><td><input type="button" value="Back" onClick="history.go(-1);" class='Commandbutton'/></td><td><input type="submit" align='right' value="New" class='Commandbutton'/></td></tr>
      </table>
</form>

where I'm using a for loop index to pull values out of previously defined "code" and "decode" string arrays. How would I do this in struts? The only thing that I see if a foreach and iterate tag but it only iterates through one collection and does not allow indexing to multiple collections at once.  

Thanks!
0
Comment
Question by:tomsawyer213
  • 3
4 Comments
 
LVL 1

Accepted Solution

by:
dhruvpratap earned 2000 total points
ID: 37052516
Seeing your above code it looks like the code and decode array have the same number of elements. Assuming that you can use the "indexId" attribute of the Struts "iterate" tag to achieve the same above logic.

Something in the lines of -
<logic:iterate name="code" id="element" indexId="index">
       <html:text property="code[index]" />
       <html:text property="decode[index]" />
</logic:iterate>

Hope this helps.
0
 

Author Comment

by:tomsawyer213
ID: 37053928
Ok I've got one more question for you. if I have the following code in my jsp

<html:form method="POST" action="/details">
                <tr><td><b>Attribute</b></td><td><b>Value</b></td></tr>
            <tr><td>Code</td>
                    <td><html:text name="detailsActionForm" property="code"/></td></tr>
            <tr><td>Decode</td>
            <td><html:text name="detailsActionForm" property="decode"/></td></tr>
            <tr><td><html:submit value="Save"/></td><td><input type="reset" value="Reset"/></td></tr>
      </html:form>

and the following action in my struts-config.xml file which the jsp code points to

<action input="/" name="detailsActionForm" path="/details" scope="session" type="com.partners.action.detailsAction" validate="false">
          <forward name="success" path="/listDetails.jsp?update=true&amp;oldcode="/>
        </action>

if you notice the URL on the success path is "listDetails.jsp?update=true&amp;oldcode=".

How to i pass the value of the oldcode parameter from my jsp to this URL in struts-config.xml?

Thanks!



0
 

Author Comment

by:tomsawyer213
ID: 37053932
i was under the assumption i could use request.setAttribute("oldcode", listDetailsActionForm.getOldCode()); in my action class to set this uri parameter value.
0
 

Author Comment

by:tomsawyer213
ID: 37053999
Im assuming something like this in my Action class would suffice

        ActionForward forward = mapping.findForward( "success" );
        StringBuffer path = new StringBuffer( forward.getPath() );
        //&amp;oldcode=
        boolean isQuery = ( path.indexOf( "?" ) >= 0 );
        if( isQuery )
        {
        path.append( "&oldcode=" );
        path.append(  details.getoldcode());
         }  
        else
        {
            path.append( "?oldcode=" );
            path.append( details.getoldcode() );
        }
        return new ActionForward( path.toString() );

where the parameter &oldcode is taking out of the url string in struts-config and replaced here
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you a startup company? Being a startup, you may be using shared hosting, or maybe even dedicated hosting. But have you ever given a thought to using cloud computing now? Yes, don’t be surprised, it is possible for startups to opt for cloud compu…
If you try to migrate from Elastix to Issabel, you will face a lot of issues. These problems are inevitable but fortunately, you can fix them. In the guide below, I will explain how I performed the migration while keeping all data and successfully t…
Screencast - Getting to Know the Pipeline
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question