You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Cyril Gambis <cy...@gmail.com> on 2007/06/22 14:57:20 UTC

[S2] Action with wildcard not found and strange behavior of s:form

Hi everybody!

I have a strange behavior while using Struts 2, s:form, and action with
wildcard. Can you please help me?

Here is my struts.xml file, with a wildcard mapping, very straightforward:

<action name="Authentification!*" method="{1}"
class="com.authentification.AuthentificationAction">
	<result>/jsp/login.jsp</result>
</action>

When I go to http://localhost:8080/Authentification.action, I got a "no
action found" error.


If I change struts.xml file like:
<action name="Authentification"
class="com.authentification.AuthentificationAction">
	<result>/jsp/login.jsp</result>
</action>

(I removed the wildcard mapping)
everything goes fine, the action is found.

It's surprising since I have another action with a wildcard:

<action name="Banner!*" method="{1}" class="banner.BannerAction">
	<result>/bannersAdministration.jsp</result>
</action>

and it works fine!


And here is the mysterious part:
when I have the struts xml version without the wildcard mapping, like:
<action name="Authentification"
class="com.authentification.AuthentificationAction">
	<result>/jsp/login.jsp</result>
</action>

and if I have the following in my jsp:
<s:form action="Authentification!displayQuestion" id="displayQuestionForm" >
	<s:hidden id="aliasFieldForQuestionForm" name="alias" value=""/>
</s:form>

everything work perfectly! It calls the action, and the displayQuestion
method (not the execute method), as if I put a wildcard mapping for this
action (but I did not, since the action is not found when I put one).

Isn't all of this very strange?

My action is:

public class AuthentificationAction extends ActionSupport {

	private AuthentificationService loginService = new
AuthentificationServiceWebServiceImpl();

	private String alias = "";
	private String question = "";
	
	public String execute() {
		return display();
	}
	public String display() {
		return SUCCESS;
	}
	public String displayQuestion() {
		
		question = loginService.getQuestion(alias);
		
		return display();
	}
	public String getAlias() {
		return alias;
	}
	public void setAlias(String alias) {
		this.alias = alias;
	}
	public String getQuestion() {
		return question;
	}
	public void setQuestion(String question) {
		this.question = question;
	}
}

Do you have an idea about that?

Thanks!
Cyril
-- 
View this message in context: http://www.nabble.com/-S2--Action-with-wildcard-not-found-and-strange-behavior-of-s%3Aform-tf3964495.html#a11251637
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: [S2] Action with wildcard not found and strange behavior of s:form

Posted by Cyril Gambis <cy...@gmail.com>.
Well thanks. I don't know why my first struts.xml doesn't work, but it's okay
since putting the action without wildcard is considered as normal behavior,
and since it works.



Zarar Siddiqi wrote:
> 
> The only mysterious part here is figuring out why you would want to use !
> in your action name.
> 

I wrote this from the struts 2 tutorial here:
http://struts.apache.org/2.x/docs/validating-input.html.

There is this code there:
struts.xml

<action name="Logon_*" method="{1}" class="tutorial.Logon">

I replaced the underscore ("_") with "!" since I saw other example on the
web using "!".

Cheers,
Cyril


Zarar Siddiqi wrote:
> 
> The only mysterious part here is figuring out why you would want to use !
> in your action name.  The default behavior of Struts 2 is for the URL
> http://localhost:8080/actionName!myMethod.action to actually execute
> myMethod instead of execute() when the action is called so you don't need
> to make your struts.xml that complicated.  
> 
> Having it like this:
> 
> <action name="Authentification"
> class="com.authentification.AuthentificationAction">
> 	<result>/jsp/login.jsp</result>
> </action>
> 
> and calling 
> 
> Authentification!myMethod.action
> 
> is good enough.
> 
> Zarar
> 
> 
> 
> Cyril Gambis wrote:
>> 
>> Hi everybody!
>> 
>> I have a strange behavior while using Struts 2, s:form, and action with
>> wildcard. Can you please help me?
>> 
>> Here is my struts.xml file, with a wildcard mapping, very
>> straightforward:
>> 
>> <action name="Authentification!*" method="{1}"
>> class="com.authentification.AuthentificationAction">
>> 	<result>/jsp/login.jsp</result>
>> </action>
>> 
>> When I go to http://localhost:8080/Authentification.action, I got a "no
>> action found" error.
>> 
>> 
>> If I change struts.xml file like:
>> <action name="Authentification"
>> class="com.authentification.AuthentificationAction">
>> 	<result>/jsp/login.jsp</result>
>> </action>
>> 
>> (I removed the wildcard mapping)
>> everything goes fine, the action is found.
>> 
>> It's surprising since I have another action with a wildcard:
>> 
>> <action name="Banner!*" method="{1}" class="banner.BannerAction">
>> 	<result>/bannersAdministration.jsp</result>
>> </action>
>> 
>> and it works fine!
>> 
>> 
>> And here is the mysterious part:
>> when I have the struts xml version without the wildcard mapping, like:
>> <action name="Authentification"
>> class="com.authentification.AuthentificationAction">
>> 	<result>/jsp/login.jsp</result>
>> </action>
>> 
>> and if I have the following in my jsp:
>> <s:form action="Authentification!displayQuestion"
>> id="displayQuestionForm" >
>> 	<s:hidden id="aliasFieldForQuestionForm" name="alias" value=""/>
>> </s:form>
>> 
>> everything work perfectly! It calls the action, and the displayQuestion
>> method (not the execute method), as if I put a wildcard mapping for this
>> action (but I did not, since the action is not found when I put one).
>> 
>> Isn't all of this very strange?
>> 
>> My action is:
>> 
>> public class AuthentificationAction extends ActionSupport {
>> 
>> 	private AuthentificationService loginService = new
>> AuthentificationServiceWebServiceImpl();
>> 
>> 	private String alias = "";
>> 	private String question = "";
>> 	
>> 	public String execute() {
>> 		return display();
>> 	}
>> 	public String display() {
>> 		return SUCCESS;
>> 	}
>> 	public String displayQuestion() {
>> 		
>> 		question = loginService.getQuestion(alias);
>> 		
>> 		return display();
>> 	}
>> 	public String getAlias() {
>> 		return alias;
>> 	}
>> 	public void setAlias(String alias) {
>> 		this.alias = alias;
>> 	}
>> 	public String getQuestion() {
>> 		return question;
>> 	}
>> 	public void setQuestion(String question) {
>> 		this.question = question;
>> 	}
>> }
>> 
>> Do you have an idea about that?
>> 
>> Thanks!
>> Cyril
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-S2--Action-with-wildcard-not-found-and-strange-behavior-of-s%3Aform-tf3964495.html#a11338256
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: [S2] Action with wildcard not found and strange behavior of s:form

Posted by Zarar Siddiqi <za...@gmail.com>.
The only mysterious part here is figuring out why you would want to use ! in
your action name.  The default behavior of Struts 2 is for the URL
http://localhost:8080/actionName!myMethod.action to actually execute
myMethod instead of execute() when the action is called so you don't need to
make your struts.xml that complicated.  

Having it like this:

<action name="Authentification"
class="com.authentification.AuthentificationAction">
	<result>/jsp/login.jsp</result>
</action>

and calling 

Authentification!myMethod.action

is good enough.

Zarar



Cyril Gambis wrote:
> 
> Hi everybody!
> 
> I have a strange behavior while using Struts 2, s:form, and action with
> wildcard. Can you please help me?
> 
> Here is my struts.xml file, with a wildcard mapping, very straightforward:
> 
> <action name="Authentification!*" method="{1}"
> class="com.authentification.AuthentificationAction">
> 	<result>/jsp/login.jsp</result>
> </action>
> 
> When I go to http://localhost:8080/Authentification.action, I got a "no
> action found" error.
> 
> 
> If I change struts.xml file like:
> <action name="Authentification"
> class="com.authentification.AuthentificationAction">
> 	<result>/jsp/login.jsp</result>
> </action>
> 
> (I removed the wildcard mapping)
> everything goes fine, the action is found.
> 
> It's surprising since I have another action with a wildcard:
> 
> <action name="Banner!*" method="{1}" class="banner.BannerAction">
> 	<result>/bannersAdministration.jsp</result>
> </action>
> 
> and it works fine!
> 
> 
> And here is the mysterious part:
> when I have the struts xml version without the wildcard mapping, like:
> <action name="Authentification"
> class="com.authentification.AuthentificationAction">
> 	<result>/jsp/login.jsp</result>
> </action>
> 
> and if I have the following in my jsp:
> <s:form action="Authentification!displayQuestion" id="displayQuestionForm"
> >
> 	<s:hidden id="aliasFieldForQuestionForm" name="alias" value=""/>
> </s:form>
> 
> everything work perfectly! It calls the action, and the displayQuestion
> method (not the execute method), as if I put a wildcard mapping for this
> action (but I did not, since the action is not found when I put one).
> 
> Isn't all of this very strange?
> 
> My action is:
> 
> public class AuthentificationAction extends ActionSupport {
> 
> 	private AuthentificationService loginService = new
> AuthentificationServiceWebServiceImpl();
> 
> 	private String alias = "";
> 	private String question = "";
> 	
> 	public String execute() {
> 		return display();
> 	}
> 	public String display() {
> 		return SUCCESS;
> 	}
> 	public String displayQuestion() {
> 		
> 		question = loginService.getQuestion(alias);
> 		
> 		return display();
> 	}
> 	public String getAlias() {
> 		return alias;
> 	}
> 	public void setAlias(String alias) {
> 		this.alias = alias;
> 	}
> 	public String getQuestion() {
> 		return question;
> 	}
> 	public void setQuestion(String question) {
> 		this.question = question;
> 	}
> }
> 
> Do you have an idea about that?
> 
> Thanks!
> Cyril
> 

-- 
View this message in context: http://www.nabble.com/-S2--Action-with-wildcard-not-found-and-strange-behavior-of-s%3Aform-tf3964495.html#a11277516
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