Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I'm building a STRUTS applic

Status
Not open for further replies.

Exie

Programmer
Sep 3, 2003
156
AU
Hi,

I'm building a STRUTS application and I have a results page which iterates through a number or rows. On each row it places a checkbox.

I have an onClick event which invokes a javascript function to ensure only 1 row is ever checked.

I then have a button which picks up the selected row and places it's ID on the URL and posts the form. It looks a bit like:

<SCRIPT LANGUAGE=&quot;JavaScript&quot; >
function do_submit(action) {
var number = getChecked();
document.myform.action=action + number;
}
</SCRIPT>

The resulting URL then looks like:

The struts-config.xml has a mapping like so:
<action path=&quot;/classresults&quot;
type=&quot;xx.xxx.xxx.xxxx.action.ClassResultsAction&quot;
parameter=&quot;id&quot;
validate=&quot;false&quot;>
<forward name=&quot;success&quot; path=&quot;/classresults.jsp&quot; />
</action>

The problem I have is in the action class (ClassResultsAction) I want to know what the ID is. If I look in the debugger there is crap all in the request stack and there is no form or anything available.

As you can see I tried using 'parameter' option hoping it would pass the variable in. But it didn't :(

I dont really want to use a form to make my 1 variable available to the Action class, is there any other way I can pass my variable in ?
 
The Action.execute() method has an HttpServletRequest object passed in, so can you not just do :

Code:
String id = request.getParameter(&quot;id&quot;);
 
Hi,

It should work as sedj said. But if you look at actionMapping you are passing a prameter id, remove that parameter it should work.

<action path=&quot;/classresults&quot;
type=&quot;xx.xxx.xxx.xxxx.action.ClassResultsAction&quot;
parameter=&quot;id&quot;
validate=&quot;false&quot;>
<forward name=&quot;success&quot; path=&quot;/classresults.jsp&quot; />
</action>

If you spacify the parameter in the actionMapping then the
ClassResultsAction should extend DispatchAction and should have a method 1234() as it is dynamic value in your case it is not possible to have dynamic methods.

The best way would be remove the parameter from the actionMapping and u can use request.getParameter(&quot;id&quot;);

There is strut forums available in tek-tips you can post struts related questions in there...

Cheers,
Venu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top