You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by zuquirio <zu...@gmail.com> on 2008/01/07 15:11:20 UTC

Struts 2: Multiple methods in an action Class

Hi,
I've a strange bug. I create an action class with three methods: view(),
check(), do(). These three methods are in one class. In my
struts-config.xml, I have made the following entries:


&lt;action name="letterRequestIndex" class="springLetterRequestIndex"
method="view"&gt;
&nbsp; &nbsp; &nbsp; &nbsp; &lt;result
name="success"&gt;/WEB-INF/application/modules/letterrequest/index.jsp&lt;/result&gt;
&lt;/action&gt;
&lt;action name="letterRequestCheck" class="springLetterRequestCheck"
method="check"&gt;

&nbsp; &nbsp; &nbsp; &nbsp; &lt;result name="input"
type="redirectAction"&gt;letterRequestIndex&lt;/result&gt;
&nbsp; &nbsp; &nbsp; &nbsp; &lt;result
name="add"&gt;/WEB-INF/application/modules/letterrequest/addDetails.jsp&lt;/result&gt;
&nbsp; &nbsp; &nbsp; &nbsp; &lt;result name="success"
type="redirectAction"&gt;letterRequestDoRequest&lt;/result&gt;

&lt;/action&gt;
&lt;action name="letterRequestDoRequest"
class="springLetterRequestDoRequest" method="do"&gt;
&nbsp; &nbsp; &nbsp; &nbsp; &lt;result
name="success"&gt;/WEB-INF/application/modules/letterrequest/viewStatus.jsp&lt;/result&gt;
&nbsp; &nbsp; &nbsp; &nbsp; &lt;result
name="add"&gt;/WEB-INF/application/modules/letterrequest/index.jsp&lt;/result&gt;

&lt;/action&gt;


When I call an action, i.e.: letterRequestDoRequest, this method is repeated
3 to 5 times. My question is: Why this action is repeated 3 to 5 times? Can
you help me?
The method called within the letterRequestDoRequest action is:


public String do() throws PortletException{	
&nbsp; &nbsp; &nbsp; &nbsp; this.session =
PortletActionContext.getRequest().getPortletSession();
&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; LetterInfo letterInfo = new LetterInfo();

&nbsp; &nbsp; &nbsp; &nbsp;
letterInfo.setTypeOfLetter((TypeOfLetter)this.session.getAttribute(TYPE_OF_LETTER));
&nbsp; &nbsp; &nbsp; &nbsp; if
(letterInfo.getTypeOfLetter().getCode().equals(
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; TypeOfLetter.CONSULAR.getCode())){

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if
(this.getLetterInfo().getRecipient().trim().length() == 0){
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; setLetterInfo(letterInfo);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; return ADD;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; letterInfo.setRecipient(getLetterInfo().getRecipient());
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }

&nbsp; &nbsp; &nbsp; &nbsp; } else {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
letterInfo.setRecipient("");
&nbsp; &nbsp; &nbsp; &nbsp; }

&nbsp; &nbsp; &nbsp; &nbsp; letterInfo.setDateOfRequest(new Date());
&nbsp; &nbsp; &nbsp; &nbsp; letterInfo.setStatus(TypeOfStatus.UNPROCESSED);
&nbsp; &nbsp; &nbsp; &nbsp; if
(BasicUtils.isFromThursdayToFriday(letterInfo.getDateOfRequest())) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
setStatusMessage(getText("label.afterNextFriday"));

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
letterInfo.setDateOfDelivery(
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BasicUtils.getNextDay(

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; letterInfo.getDateOfRequest(), Calendar.FRIDAY, 1));

&nbsp; &nbsp; &nbsp; &nbsp; } else {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
setStatusMessage(getText("label.nextFriday"));
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
letterInfo.setDateOfDelivery(

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BasicUtils.getNextDay(

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; letterInfo.getDateOfRequest(), Calendar.FRIDAY, 0));

&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; setLetterInfo(letterInfo);
&nbsp; &nbsp; &nbsp; &nbsp; this.letterRequestService.create(letterInfo);
&nbsp; &nbsp; &nbsp; &nbsp; this.session.removeAttribute(TYPE_OF_LETTER);

&nbsp; &nbsp; &nbsp; &nbsp; return SUCCESS;
}


Thanks in advance!!
-- 
View this message in context: http://www.nabble.com/Struts-2%3A-Multiple-methods-in-an-action-Class-tp14666539p14666539.html
Sent from the Struts - User mailing list archive at Nabble.com.

Re: Struts 2: Multiple methods in an action Class

Posted by zuquirio <zu...@gmail.com>.
Thanks a lot! I will give it a try. Actually the real method's name is:
doRequest, I will try to put a different name. Thanks.


Ted Husted wrote:
> 
> What happens if you use a method name other than "do".
> 
> There's actually a feature in Struts 2 where we can name a method
> "doDefault" and then refer to it as "default" elsewhere. Naming a
> method "do" might be confusing.
> 
> HTH, Ted
>  * <http://www.StrutsMentor.com/>
> 
> On Jan 7, 2008 9:11 AM, zuquirio <zu...@gmail.com> wrote:
>>
>> Hi,
>> I've a strange bug. I create an action class with three methods: view(),
>> check(), do(). These three methods are in one class. In my
>> struts-config.xml, I have made the following entries:
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts-2%3A-Multiple-methods-in-an-action-Class-tp14666539p14671323.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: Struts 2: Multiple methods in an action Class

Posted by Ted Husted <hu...@apache.org>.
What happens if you use a method name other than "do".

There's actually a feature in Struts 2 where we can name a method
"doDefault" and then refer to it as "default" elsewhere. Naming a
method "do" might be confusing.

HTH, Ted
 * <http://www.StrutsMentor.com/>

On Jan 7, 2008 9:11 AM, zuquirio <zu...@gmail.com> wrote:
>
> Hi,
> I've a strange bug. I create an action class with three methods: view(),
> check(), do(). These three methods are in one class. In my
> struts-config.xml, I have made the following entries:

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