You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Gábor Kovács <ko...@gmail.com> on 2009/09/09 14:13:39 UTC

[S2]All the methods with "get" prefix are invoked

Hi everyone,

I'm confused, because I don't understand this problem:

I've made a simple Struts2 project. Here are the codes (they're short)

ACTION CLASS
---------------------------

package test.action;

import com.opensymphony.xwork2.ActionSupport;

public class TestAction extends ActionSupport{

public String getTest1(){
System.out.println("getTest1");
return SUCCESS;
}

}

STRUTS.XML
------------------------
<struts>
<package name="test" extends="struts-default">

<action name="test" class="test.action.TestAction">
<result>/test.jsp</result>
</action>
</package>
</struts>

WEB.XML
-----------------------
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="
http://java.sun.com/xml/ns/javaee" xmlns:web="
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
version="2.5">
<display-name>TEST</display-name>

<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
<welcome-file>test.jsp</welcome-file>
</welcome-file-list>
</web-app>

TEST.JSP
------------------
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
.
.
.
.

<style> .errorMessage { color:red; }</style>
</head>
<body>
<s:url id="test" namespace="/test" action="test" />
<s:a href="%{test}">TEST</s:a>

 <s:debug/>

</body>
</html>

----------------------------------------------------------------------------------------------------------------------------
When I click the link which calls the action named test, I expect that:
Struts can see the struts.xml, then calls the TestAction's execute method().
Yes, it does, but besides, it calls the TestAction's getTest1() method (it
writes "getTest1" to the console)...and if I write another method, which is
public and it's return type is String AND it has a GET prefix (getFOO)
....it will be called, too.
I don't get it...Why?

Thanks in advance!

Gábor

Re: [S2]All the methods with "get" prefix are invoked

Posted by Gábor Kovács <ko...@gmail.com>.
Hi Dennis,

You are right! Thank you very much!

Gábor

Re: [S2]All the methods with "get" prefix are invoked

Posted by Denis Cabasson <ca...@gmail.com>.
Hi,

The debug tag is "inspecting" the status of your action to build its 
HTML output, which include knowing the value of test1, and thus calling 
the corresponding getter.

Take out the debug tag, and everything should be back to normal.

Denis.

Gábor Kovács a écrit :
> Hi everyone,
>
> I'm confused, because I don't understand this problem:
>
> I've made a simple Struts2 project. Here are the codes (they're short)
>
> ACTION CLASS
> ---------------------------
>
> package test.action;
>
> import com.opensymphony.xwork2.ActionSupport;
>
> public class TestAction extends ActionSupport{
>
> public String getTest1(){
> System.out.println("getTest1");
> return SUCCESS;
> }
>
> }
>
> STRUTS.XML
> ------------------------
> <struts>
> <package name="test" extends="struts-default">
>
> <action name="test" class="test.action.TestAction">
> <result>/test.jsp</result>
> </action>
> </package>
> </struts>
>
> WEB.XML
> -----------------------
> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="
> http://java.sun.com/xml/ns/javaee" xmlns:web="
> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="
> http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
> version="2.5">
> <display-name>TEST</display-name>
>
> <filter>
> <filter-name>struts2</filter-name>
> <filter-class>
> org.apache.struts2.dispatcher.FilterDispatcher
> </filter-class>
> </filter>
>
> <filter-mapping>
> <filter-name>struts2</filter-name>
> <url-pattern>/*</url-pattern>
> </filter-mapping>
>
> <welcome-file-list>
> <welcome-file>test.jsp</welcome-file>
> </welcome-file-list>
> </web-app>
>
> TEST.JSP
> ------------------
> <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
> pageEncoding="ISO-8859-1"%>
> <%@ taglib uri="/struts-tags" prefix="s" %>
> .
> .
> .
> .
>
> <style> .errorMessage { color:red; }</style>
> </head>
> <body>
> <s:url id="test" namespace="/test" action="test" />
> <s:a href="%{test}">TEST</s:a>
>
>  <s:debug/>
>
> </body>
> </html>
>
> ----------------------------------------------------------------------------------------------------------------------------
> When I click the link which calls the action named test, I expect that:
> Struts can see the struts.xml, then calls the TestAction's execute method().
> Yes, it does, but besides, it calls the TestAction's getTest1() method (it
> writes "getTest1" to the console)...and if I write another method, which is
> public and it's return type is String AND it has a GET prefix (getFOO)
> ....it will be called, too.
> I don't get it...Why?
>
> Thanks in advance!
>
> Gábor
>
>   


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