You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by RogerV <ro...@googlemail.com> on 2009/10/09 08:47:06 UTC

More Convention Confusion.

This is a continuation of the problem I posted about last week.

<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
  <head>
   </head>
  <body>
    
    <s:form action="process-template" method="post">
    <ul>
    <s:iterator value="templateDataList" status="status">
      <li>
    <s:submit type="button" label="Display"
method="display?templateId=%{#status.index}" /> 
    </li>
    </s:iterator>
    </ul>
    </s:form>
  </body>
</html>


This simple jsp should generate a submit button for each entry in the
templateDataList and pass
the index of the list element selected back to the action. The action
contains a display() method with getter & setter for templateId. When the
first  button in the list is pressed, Struts complains
"java.lang.NoSuchMethodException:
com.blackbox.actions.ProcessTemplate.display?templateId=0()". 
If I annotate the display method with @Action("display?templateId=0()") then
everything works (provided I select the button with the index value 0)

I can't believe that I've discovered a major flaw in the plugin, so it must
mean that I'm doing something stupid but I can't work out what. I've posted
a demo for a similair problem in JIRA WW-3276 if anyone would like to take a
look.

I'd appreciate some help as otherwise I'm going to have to convert my app
back to Struts "Classic"

Regards

  
-- 
View this message in context: http://www.nabble.com/More-Convention-Confusion.-tp25816249p25816249.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: More Convention Confusion.

Posted by RogerV <ro...@googlemail.com>.


Greg Lindholm-2 wrote:
> 
> 
> I have thought about extending the DefaultActionMapper to accept a name
> parameter with a syntax sorta like:
> 
>    name="action:myAction:method:MyMethod:param:name=value"
> 
> I think this would be a useful enhancement. (Maybe someone with more time
> on
> there hands will add it.)
> 
> 

I've had a quick look at the DefaultActionMapper source and it looks like it
might be relatively straight forward to implement a parameter: prefix with a
comma seperated list of key=value and load it into a HashMap and set it on
the ActionMapping.setParms(). However, I'd need to change the <s:submit>
tag.  Would I need to enforce a rule that says that the method: must be
defined to have the parameter: prefix and, if so, where would I do that? I
think that if I just added the parameters: prefix, then Struts would try to
set them on whatever action it decided to map to. It looks like it might be 
easier to persuade it to handle the format
method:MyMethod?parm1=xyz&parm2=abc rather than the format you suggest -
unless I'm misunderstanding the code. By doing it this way, I won't need to
change the <s:submit> tag and I think all I'd need to do is parse the method
name, pull out the ?parm ... string into a hashMap and call setParms on the
ActionMapping in the constructor when prefixTrie is being set up. This would
be more of a hack though.

As an aside are there any reasons why this is not a good idea. There a large
number of better qualified people than me, and that makes me wonder why this
hasn't been done before.


Regards



-- 
View this message in context: http://www.nabble.com/More-Convention-Confusion.-tp25816249p25826108.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: More Convention Confusion.

Posted by Greg Lindholm <gr...@gmail.com>.
>From what I can tell you cannot pass extra parameters with the 'method'
attribute

> <s:submit type="button" label="Display"
>    method="display?templateId=%{#status.index}" />

Whatever you specify for method will be taken as the method name.
So it is looking for a method named "display?templateId=0" which is invalid
and not found.
The ?templateId will not be processed as a parameter.

I have asked before; How do you pass a reference id with a submit button so
you can have a column of submit buttons so you can determine which row is
associated with the button pressed?  There doesn't seem to be a way that
doesn't use javascript.

One way is to use onclick and set the id in a hidden field.  LIke this:

<s:hidden name="templateId" value="" />
<s:submit type="button" label="Display" method="display"
   onclick="templateId.value=%{#status.index};"  />

The other way is to use links which you can used to pass parameters but you
can't also pass form fields (unless you use some javascript).

I have thought about extending the DefaultActionMapper to accept a name
parameter with a syntax sorta like:

   name="action:myAction:method:MyMethod:param:name=value"

I think this would be a useful enhancement. (Maybe someone with more time on
there hands will add it.)