You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rubens Gomes <Ru...@appia.com> on 2011/02/03 07:31:33 UTC

S2 Action Setter Not Called

Hello,

I am running Struts 2 (version 2.2.1.1) and the struts2-convention-plugin to annotate all Actions.

My action parameter setters are not being called by the ParametersInterceptor.  The form does submit the email
parameter to my action.  And the logs show that parameter on the ParametersInterceptor DEBUG log.  However, the corresponding action  email setter is not called.  I did verify that the of the parameter matches both setter / getter.

Any ideas?

02/03/11 12:42:50 AM [com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler] DEBUG: Entering nullPropertyValue [target=[com.opensymphony.xwork2.DefaultTextProvider@101bc44], property=struts]
02/03/11 12:42:50 AM [com.opensymphony.xwork2.config.ConfigurationManager] DEBUG: Checking ConfigurationProviders for reload.
02/03/11 12:42:50 AM [com.opensymphony.xwork2.DefaultActionProxy] DEBUG: Creating an DefaultActionProxy for namespace /account and action name request-pwd
02/03/11 12:42:50 AM [com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler] DEBUG: Entering nullPropertyValue [target=[com.softlagos.web.struts2.action.account.RequestPwdAction@4ba679, com.opensymphony.xwork2.DefaultTextProvider@101bc44], property=fontSize]
02/03/11 12:42:50 AM [com.opensymphony.xwork2.interceptor.I18nInterceptor] DEBUG: intercept '/account/request-pwd' {
02/03/11 12:42:50 AM [com.opensymphony.xwork2.interceptor.I18nInterceptor] DEBUG: applied invocation context locale=pt_BR
02/03/11 12:42:50 AM [com.opensymphony.xwork2.interceptor.I18nInterceptor] DEBUG: before Locale=pt_BR
02/03/11 12:42:50 AM [com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler] DEBUG: Entering nullPropertyValue [target=[{browser=mobile}, com.softlagos.web.struts2.action.account.RequestPwdAction@4ba679, com.opensymphony.xwork2.DefaultTextProvider@101bc44], property=struts]
02/03/11 12:42:51 AM [org.apache.struts2.interceptor.FileUploadInterceptor] DEBUG: Ignorando /account/ request-pwd
02/03/11 12:42:51 AM [com.opensymphony.xwork2.interceptor.StaticParametersInterceptor] DEBUG: Setting static parameters {}
02/03/11 12:42:51 AM [com.opensymphony.xwork2.interceptor.ParametersInterceptor] DEBUG: Setting params NONE
02/03/11 12:42:51 AM [com.opensymphony.xwork2.interceptor.ParametersInterceptor] DEBUG: Setting params email => [ rgomes@ezlista.com ] mobile => [ true ] recoverPwdButton => [ Submit ]
02/03/11 12:42:51 AM [org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor] DEBUG: Validating /account/request-pwd with method execute.
02/03/11 12:42:51 AM [com.opensymphony.xwork2.validator.ValidationInterceptor] DEBUG: Invoking validate() on action com.softlagos.web.struts2.action.account.RequestPwdAction@4ba679
02/03/11 12:42:51 AM [com.opensymphony.xwork2.interceptor.PrefixMethodInvocationUtil] DEBUG: cannot find method [validateExecute] in action [com.softlagos.web.struts2.action.account.RequestPwdAction@4ba679]
02/03/11 12:42:51 AM [com.opensymphony.xwork2.interceptor.PrefixMethodInvocationUtil] DEBUG: cannot find method [validateDoExecute] in action [com.softlagos.web.struts2.action.account.RequestPwdAction@4ba679]
02/03/11 12:43:03 AM [com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler] DEBUG: Entering nullPropertyValue [target=[{email=[Ljava.lang.String;@1adf96a, browser=mobile, recoverPwdButton=[Ljava.lang.String;@d1d45a, mobile=[Ljava.lang.String;@1cc6f7e}, com.softlagos.web.struts2.action.account.RequestPwdAction@4ba679, com.opensymphony.xwork2.DefaultTextProvider@101bc44], property=error]
02/03/11 12:43:03 AM [com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler] DEBUG: Entering nullPropertyValue [target=[{email=[Ljava.lang.String;@1adf96a, browser=mobile, recoverPwdButton=[Ljava.lang.String;@d1d45a, mobile=[Ljava.lang.String;@1cc6f7e}, com.softlagos.web.struts2.action.account.RequestPwdAction@4ba679, com.opensymphony.xwork2.DefaultTextProvider@101bc44], property=error]
02/03/11 12:43:03 AM [com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor] DEBUG: Errors on action com.softlagos.web.struts2.action.account.RequestPwdAction@4ba679, returning result name 'input'
02/03/11 12:43:03 AM [com.opensymphony.xwork2.ognl.accessor.XWorkMapPropertyAccessor] DEBUG: Entering getProperty (ognl.OgnlContext@fa455359,{email=[Ljava.lang.String;@1adf96a, browser=mobile, recoverPwdButton=[Ljava.lang.String;@d1d45a, mobile=[Ljava.lang.String;@1cc6f7e},browser)
02/03/11 12:43:03 AM [org.apache.struts2.dispatcher.ServletDispatcherResult] DEBUG: Forwarding to location /WEB-INF/content/mobile/account/request-pwd.jsp

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


Re: S2 Action Setter Not Called

Posted by Dave Newton <da...@gmail.com>.
I can't make heads or tails of that.

How about you get a "sanity check" version going first then revisit
all that? Sounds like you changed several fundamental behaviors all at
once without a safety net. Can you revert?

Dave

On Thu, Feb 3, 2011 at 7:31 PM, Rubens Gomes <Ru...@appia.com> wrote:
> I am still having issues with the action setters not being called.  I have already spent several hours on this problem.  Here is additional information:
>
> Struts 2 + Struts 2 struts2-convention-plugin version: 2.2.1.1
>
> Absolutely *none* of my actions setters are called.  This problem is happening across board with all my actions.  I have re-factored all my actions recently to make use of Struts 2 annotations. I have also done some refactoring on the JSPs and Spring security filters.  All actions were working fine before.  And I *did* see the parameters passed from the browser to the struts 2 ParameterInterceptor (see previous logs).
>
> Below is my struts.xml and an action class with the setters that are *not* being called.
>
> Am I doing something wrong on my configurations and java code?
>
> <?xml version="1.0" encoding="UTF-8" ?>
> <!--
>  * @(#)  $$Id: struts.xml 3763 2011-02-03 06:56:24Z rgomes $$
> -->
> <!DOCTYPE struts PUBLIC
>    "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
>    "http://struts.apache.org/dtds/struts-2.1.7.dtd">
>
> <struts>
>  <constant name="struts.devMode" value="false" />
>
>  <constant name="struts.action.extension" value="do" />
>  <constant name="struts.convention.default.parent.package" value="defaultPackage" />
>  <constant name="struts.convention.package.locators" value="action" />
>  <constant name="struts.custom.i18n.resources" value="struts/resources" />
>  <constant name="struts.date.format" value="dd/MM/yyyy hh:mm" />
>  <constant name="struts.freemarker.templatesCache" value="true" />
>  <constant name="struts.i18n.encoding" value="UTF-8"/>
>  <constant name="struts.serve.static" value="true" />
>  <constant name="struts.ui.theme" value="simple" />
>
>  <include file="struts-default.xml" />
>
>  <package name="ajaxPackage" extends="json-default">
>    <interceptors>
>      <interceptor name="secureInterceptor" class="com.softlagos.web.struts2.interceptor.SecureInterceptor" />
>
>      <interceptor-stack name="ajaxStack">
>        <interceptor-ref name="params" />
>      </interceptor-stack>
>
>      <interceptor-stack name="secureAjaxStack">
>        <interceptor-ref name="ajaxStack" />
>        <interceptor-ref name="secureInterceptor" />
>      </interceptor-stack>
>    </interceptors>
>  </package>
>
>
>  <package name="defaultPackage" extends="struts-default">
>    <interceptors>
>      <interceptor name="fontSizeInterceptor" class="com.softlagos.web.struts2.interceptor.FontSizeInterceptor" />
>      <interceptor name="valueStackInterceptor" class="com.softlagos.web.struts2.interceptor.ValueStackInterceptor" />
>      <interceptor name="localeInterceptor" class="com.softlagos.web.struts2.interceptor.LocaleInterceptor" />
>      <interceptor name="secureInterceptor" class="com.softlagos.web.struts2.interceptor.SecureInterceptor" />
>
>      <interceptor-stack name="myDefaultStack">
>        <interceptor-ref name="fontSizeInterceptor" />
>        <interceptor-ref name="valueStackInterceptor" />
>        <interceptor-ref name="defaultStack">
>          <param name="exception.logEnabled">true</param>
>          <param name="exception.logLevel">ERROR</param>
>        </interceptor-ref>
>        <interceptor-ref name="localeInterceptor" />
>      </interceptor-stack>
>
>      <interceptor-stack name="secureStack">
>        <interceptor-ref name="myDefaultStack" />
>        <interceptor-ref name="secureInterceptor" />
>      </interceptor-stack>
>    </interceptors>
>
>    <default-interceptor-ref name="myDefaultStack" />
>
>    <default-action-ref name="default-action" />
>
>    <global-results>
>      <result name="exception">/WEB-INF/content/${browser}/error.jsp</result>
>    </global-results>
>
>    <global-exception-mappings>
>      <exception-mapping exception="java.lang.Exception" result="exception" />
>    </global-exception-mappings>
>
>    <action name="default-action" class="com.softlagos.web.struts2.action.DefaultAction">
>      <result>/WEB-INF/content/${browser}/error.jsp</result>
>    </action>
>  </package>
>
>  <package name="home" extends="defaultPackage" namespace="/">
>    <action name="about">
>      <result>/WEB-INF/content/${browser}/about.jsp</result>
>    </action>
>    <action name="error">
>      <result>/WEB-INF/content/${browser}/error.jsp</result>
>    </action>
>    <action name="help">
>      <result>/WEB-INF/content/${browser}/help.jsp</result>
>    </action>
>    <action name="language-help">
>      <result>/WEB-INF/content/${browser}/language-help.jsp</result>
>    </action>
>    <action name="pending-email-help">
>      <result>/WEB-INF/content/${browser}/pending-email-help.jsp</result>
>    </action>
>    <action name="privacy">
>      <result>/WEB-INF/content/${browser}/privacy.jsp</result>
>    </action>
>    <action name="remember-help">
>      <result>/WEB-INF/content/${browser}/remember-help.jsp</result>
>    </action>
>    <action name="terms">
>      <result>/WEB-INF/content/${browser}/terms.jsp</result>
>    </action>
>    <action name="terms-service">
>      <result>/WEB-INF/content/${browser}/terms-service.jsp</result>
>    </action>
>  </package>
>
>  <package name="secure-tools" extends="defaultPackage" namespace="/secure/tools">
>    <default-interceptor-ref name="secureStack" />
>    <action name="view-google-contacts-import">
>      <result>/WEB-INF/content/${browser}/tools/google-contacts-import.jsp</result>
>    </action>
>    <action name="view-export-tools">
>      <result>/WEB-INF/content/${browser}/tools/export.jsp</result>
>    </action>
>    <action name="view-tools">
>      <result>/WEB-INF/content/${browser}/tools/tools.jsp</result>
>    </action>
>  </package>
>
>  <package name="account" extends="defaultPackage" namespace="/account">
>    <action name="request-pwd-confirmation">
>      <result>/WEB-INF/content/${browser}/account/request-pwd-confirmation.jsp</result>
>    </action>
>    <action name="reset-pwd-confirmation">
>      <result>/WEB-INF/content/${browser}/account/reset-pwd-confirmation.jsp</result>
>    </action>
>  </package>
>
>  <package name="secure-account" extends="defaultPackage" namespace="/secure/account">
>    <default-interceptor-ref name="secureStack" />
>    <action name="confirm-email">
>      <result>/WEB-INF/content/${browser}/account/confirm-email.jsp</result>
>    </action>
>    <action name="view-change-user-language">
>      <result>/WEB-INF/content/${browser}/account/change-user-language.jsp</result>
>    </action>
>  </package>
>
>  <package name="secure-ssl-account" extends="defaultPackage" namespace="/secure/ssl/account">
>    <default-interceptor-ref name="secureStack" />
>    <action name="change-login">
>      <result>/WEB-INF/content/${browser}/account/change-login.jsp</result>
>    </action>
>    <action name="view-change-email">
>      <result>/WEB-INF/content/${browser}/account/change-email.jsp</result>
>    </action>
>    <action name="view-change-password">
>      <result>/WEB-INF/content/${browser}/account/change-password.jsp</result>
>    </action>
>  </package>
>
> </struts>
>
>
> package com.softlagos.web.struts2.action.account;
>
> import java.util.ArrayList;
> import java.util.List;
>
> import org.apache.commons.lang.StringUtils;
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> import org.apache.struts2.convention.annotation.Namespace;
> import org.apache.struts2.convention.annotation.Result;
> import org.apache.struts2.convention.annotation.Results;
> import org.springframework.security.web.authentication.WebAuthenticationDetails;
>
> import com.softlagos.common.Message;
> import com.softlagos.common.Response;
> import com.softlagos.common.validator.PasswordValidator;
> import com.softlagos.domain.account.AccountResponse;
> import com.softlagos.domain.account.PrivilegeType;
> import com.softlagos.domain.account.RoleNameType;
> import com.softlagos.domain.account.UserAccount;
> import com.softlagos.domain.address.Email;
> import com.softlagos.web.cookie.CookieManager;
> import com.softlagos.web.cookie.CookieManagerFactory;
> import com.softlagos.web.struts2.action.common.BaseAction;
>
>
> /**
>  * Handles the registration form submit to register a user account on the
>  * system.
>  *
>  * @author Rubens Gomes
>  * @version $Id: RegisterAction.java 3657 2011-01-27 17:38:40Z rgomes $
>  */
> @Namespace("/ssl/account")
> @Results({
>    @Result(name="cancel", location="/", type="redirect"),
>    @Result(name="error", location="/WEB-INF/content/${browser}/account/register.jsp", type="dispatcher"),
>    @Result(name="input", location="/WEB-INF/content/${browser}/account/register.jsp", type="dispatcher"),
>    @Result(name="success", location="/secure/addressbook/address-book.do", type="redirect")
> })
> public final class RegisterAction extends BaseAction
> {
>    private static final long serialVersionUID = 1;
>    private static final Log logger = LogFactory.getLog(RegisterAction.class.getName());
>    static final Log newAccountLogger = LogFactory.getLog("NewAccountLogger");
>    private String email;
>    private String password;
>    private String confirmPassword;
>    private String termsAgreed;
>    private boolean cancel = false;
>
>    public RegisterAction()
>    {
>        super();
>    }
>
>    @Override
>    public void validate()
>    {
>        if (this.isCancel())
>        {
>            return;
>        }
>
>        if (StringUtils.isBlank(this.termsAgreed))
>        {
>            this.addFieldError("termsAgreed", this.getText("error.account.termsNotAccepted"));
>        }
>
>        if (StringUtils.isEmpty(this.email))
>        {
>            this.addFieldError("email", this.getText("error.account.emailRequired"));
>        }
>        else if (!Email.isEmailValid(email))
>        {
>            this.addFieldError("email", this.getText("error.account.emailInvalid"));
>        }
>
>        // password
>        if (StringUtils.isBlank(this.password))
>        {
>            this.addFieldError("password", this.getText("error.authentication.passwordRequired"));
>        }
>        else if (!UserAccount.isPasswordValid(this.password))
>        {
>            List<String> args = new ArrayList<String>();
>            args.add("" + PasswordValidator.MIN_PASSWORD_LENGTH);
>            args.add("" + PasswordValidator.MAX_PASSWORD_LENGTH);
>            this.addFieldError("password",
>                this.getText("error.authentication.passwordInvalid", args.toArray(new String[0])));
>        }
>
>        // confirm password
>        if (StringUtils.isBlank(this.confirmPassword))
>        {
>            this.addFieldError("confirmPassword", this.getText("error.authentication.passwordRequired"));
>        }
>        else if (!UserAccount.isPasswordValid(this.confirmPassword))
>        {
>            List<String> args = new ArrayList<String>();
>            args.add("" + PasswordValidator.MIN_PASSWORD_LENGTH);
>            args.add("" + PasswordValidator.MAX_PASSWORD_LENGTH);
>            this.addFieldError("confirmPassword",
>                this.getText("error.authentication.passwordInvalid", args.toArray(new String[0])));
>        }
>        else if (!this.confirmPassword.equals(this.password))
>        {
>            this.addFieldError("confirmPassword", this.getText("error.account.passwordsDifferent"));
>        }
>    }
>
>    @Override
>    public String execute()
>    {
>        if (this.isCancel())
>        {
>            return "cancel";
>        }
>
>        AccountResponse response = BaseAction.accountService.createUserAccount(this.email, this.password,
>                this.getClientIpAddr(), RoleNameType.ROLE_USER, PrivilegeType.READ_WRITE, this.email,
>                this.getLocale());
>
>        Message error = response.getErrorMessage();
>        if (error != null)
>        {
>            String errorMsg = this.getErrorTextMessage(error);
>            if (logger.isInfoEnabled())
>            {
>                logger.info("error occurred creating account: " + errorMsg);
>            }
>
>            this.addActionError(errorMsg);
>            return ERROR;
>        }
>
>        UserAccount account = response.getUserAccount();
>        Response notificationResponse = BaseAction.notificationService.newAccountConfirmation(account.getUserProfile().getPrimaryEmail(),
>                this.getConfirmationUrl("/account/confirm-new-account.do"));
>        error = notificationResponse.getErrorMessage();
>        if (error != null)
>        {
>            String errorMsg = this.getErrorTextMessage(error);
>            if (logger.isInfoEnabled())
>            {
>                logger.info("error occurred submitting new account notification: " + errorMsg);
>            }
>
>            this.addActionError(errorMsg);
>            return ERROR;
>        }
>
>        WebAuthenticationDetails details = new WebAuthenticationDetails(this.getRequest());
>        Response securityResponse = BaseAction.securityService.establishSecurityAuthentication(details,
>                account.getId());
>        error = securityResponse.getErrorMessage();
>        if (error != null)
>        {
>            String errorMsg = this.getErrorTextMessage(error);
>            if (logger.isInfoEnabled())
>            {
>                logger.info("error occurred creating account: " + errorMsg);
>            }
>
>            this.addActionError(errorMsg);
>            return ERROR;
>        }
>
>        // at this point an authentication has been placed on the security context,
>        // and we can safely redirect the user to the contacts list page.
>
>        // store prefered language on the cookie to remember user's prefered language.
>        CookieManager cookieManager = CookieManagerFactory.getInstance(this.getRequest(), this.getResponse());
>        cookieManager.setLanguageCookie(this.getLocale().getLanguage());
>
>        // store the account Id on the session
>        this.getUserSession().setAccountId(account.getId());
>
>        if (newAccountLogger.isInfoEnabled())
>        {
>            newAccountLogger.info("-------------------------------------------------------------------");
>            newAccountLogger.info("Account created [" + account.getUsername() + "]");
>            newAccountLogger.info("Client IP address [" + account.getRegisteredClientIpAddress() + "]");
>        }
>
>        return SUCCESS;
>    }
>
>    /**
>     * @param password the password to set
>     */
>    public void setPassword(String password)
>    {
>        this.password = password;
>    }
>
>    /**
>     * @return the password
>     */
>    public String getPassword()
>    {
>        return this.password;
>    }
>
>    /**
>     * @return the confirmPassword
>     */
>    public String getConfirmPassword()
>    {
>        return confirmPassword;
>    }
>
>    /**
>     * @param confirmPassword the confirmPassword to set
>     */
>    public void setConfirmPassword(String confirmPassword)
>    {
>        this.confirmPassword = confirmPassword;
>    }
>
>    /**
>     * @return the user primary email
>     */
>    public String getEmail()
>    {
>        return this.email;
>    }
>
>    /**
>     * @param primaryEmail the user primary email to set
>     */
>    public void setEmail(String primaryEmail)
>    {
>        this.email = (primaryEmail != null) ? primaryEmail.trim() : null;
>    }
>
>    /**
>     * @return the terms
>     */
>    public final String getTermsAgreed()
>    {
>        return this.termsAgreed;
>    }
>
>    /**
>     * @param terms the terms to set
>     */
>    public final void setTermsAgreed(String terms)
>    {
>        this.termsAgreed = terms;
>    }
>
>    /**
>     * @return the cancel
>     */
>    public boolean isCancel()
>    {
>        return cancel;
>    }
>
>    /**
>     * notice that if the corresponding button is pressed the cancel should be set to true.
>     *
>     * @param cancel the cancel to set
>     */
>    public void setCancel(boolean dummy)
>    {
>        this.cancel = true;
>    }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


RE: S2 Action Setter Not Called

Posted by Rubens Gomes <Ru...@appia.com>.
I am still having issues with the action setters not being called.  I have already spent several hours on this problem.  Here is additional information:

Struts 2 + Struts 2 struts2-convention-plugin version: 2.2.1.1

Absolutely *none* of my actions setters are called.  This problem is happening across board with all my actions.  I have re-factored all my actions recently to make use of Struts 2 annotations. I have also done some refactoring on the JSPs and Spring security filters.  All actions were working fine before.  And I *did* see the parameters passed from the browser to the struts 2 ParameterInterceptor (see previous logs).

Below is my struts.xml and an action class with the setters that are *not* being called.

Am I doing something wrong on my configurations and java code?

<?xml version="1.0" encoding="UTF-8" ?>
<!--
  * @(#)  $$Id: struts.xml 3763 2011-02-03 06:56:24Z rgomes $$
-->
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
    "http://struts.apache.org/dtds/struts-2.1.7.dtd">

<struts>
  <constant name="struts.devMode" value="false" />

  <constant name="struts.action.extension" value="do" />
  <constant name="struts.convention.default.parent.package" value="defaultPackage" />
  <constant name="struts.convention.package.locators" value="action" />
  <constant name="struts.custom.i18n.resources" value="struts/resources" />
  <constant name="struts.date.format" value="dd/MM/yyyy hh:mm" />
  <constant name="struts.freemarker.templatesCache" value="true" />
  <constant name="struts.i18n.encoding" value="UTF-8"/>
  <constant name="struts.serve.static" value="true" />
  <constant name="struts.ui.theme" value="simple" />

  <include file="struts-default.xml" />

  <package name="ajaxPackage" extends="json-default">
    <interceptors>
      <interceptor name="secureInterceptor" class="com.softlagos.web.struts2.interceptor.SecureInterceptor" />

      <interceptor-stack name="ajaxStack">
        <interceptor-ref name="params" />
      </interceptor-stack>

      <interceptor-stack name="secureAjaxStack">
        <interceptor-ref name="ajaxStack" />
        <interceptor-ref name="secureInterceptor" />
      </interceptor-stack>
    </interceptors>
  </package>


  <package name="defaultPackage" extends="struts-default">
    <interceptors>
      <interceptor name="fontSizeInterceptor" class="com.softlagos.web.struts2.interceptor.FontSizeInterceptor" />
      <interceptor name="valueStackInterceptor" class="com.softlagos.web.struts2.interceptor.ValueStackInterceptor" />
      <interceptor name="localeInterceptor" class="com.softlagos.web.struts2.interceptor.LocaleInterceptor" />
      <interceptor name="secureInterceptor" class="com.softlagos.web.struts2.interceptor.SecureInterceptor" />

      <interceptor-stack name="myDefaultStack">
        <interceptor-ref name="fontSizeInterceptor" />
        <interceptor-ref name="valueStackInterceptor" />
        <interceptor-ref name="defaultStack">
          <param name="exception.logEnabled">true</param>
          <param name="exception.logLevel">ERROR</param>
        </interceptor-ref>
        <interceptor-ref name="localeInterceptor" />
      </interceptor-stack>

      <interceptor-stack name="secureStack">
        <interceptor-ref name="myDefaultStack" />
        <interceptor-ref name="secureInterceptor" />
      </interceptor-stack>
    </interceptors>

    <default-interceptor-ref name="myDefaultStack" />

    <default-action-ref name="default-action" />

    <global-results>
      <result name="exception">/WEB-INF/content/${browser}/error.jsp</result>
    </global-results>

    <global-exception-mappings>
      <exception-mapping exception="java.lang.Exception" result="exception" />
    </global-exception-mappings>

    <action name="default-action" class="com.softlagos.web.struts2.action.DefaultAction">
      <result>/WEB-INF/content/${browser}/error.jsp</result>
    </action>
  </package>

  <package name="home" extends="defaultPackage" namespace="/">
    <action name="about">
      <result>/WEB-INF/content/${browser}/about.jsp</result>
    </action>
    <action name="error">
      <result>/WEB-INF/content/${browser}/error.jsp</result>
    </action>
    <action name="help">
      <result>/WEB-INF/content/${browser}/help.jsp</result>
    </action>
    <action name="language-help">
      <result>/WEB-INF/content/${browser}/language-help.jsp</result>
    </action>
    <action name="pending-email-help">
      <result>/WEB-INF/content/${browser}/pending-email-help.jsp</result>
    </action>
    <action name="privacy">
      <result>/WEB-INF/content/${browser}/privacy.jsp</result>
    </action>
    <action name="remember-help">
      <result>/WEB-INF/content/${browser}/remember-help.jsp</result>
    </action>
    <action name="terms">
      <result>/WEB-INF/content/${browser}/terms.jsp</result>
    </action>
    <action name="terms-service">
      <result>/WEB-INF/content/${browser}/terms-service.jsp</result>
    </action>
  </package>

  <package name="secure-tools" extends="defaultPackage" namespace="/secure/tools">
    <default-interceptor-ref name="secureStack" />
    <action name="view-google-contacts-import">
      <result>/WEB-INF/content/${browser}/tools/google-contacts-import.jsp</result>
    </action>
    <action name="view-export-tools">
      <result>/WEB-INF/content/${browser}/tools/export.jsp</result>
    </action>
    <action name="view-tools">
      <result>/WEB-INF/content/${browser}/tools/tools.jsp</result>
    </action>
  </package>

  <package name="account" extends="defaultPackage" namespace="/account">
    <action name="request-pwd-confirmation">
      <result>/WEB-INF/content/${browser}/account/request-pwd-confirmation.jsp</result>
    </action>
    <action name="reset-pwd-confirmation">
      <result>/WEB-INF/content/${browser}/account/reset-pwd-confirmation.jsp</result>
    </action>
  </package>

  <package name="secure-account" extends="defaultPackage" namespace="/secure/account">
    <default-interceptor-ref name="secureStack" />
    <action name="confirm-email">
      <result>/WEB-INF/content/${browser}/account/confirm-email.jsp</result>
    </action>
    <action name="view-change-user-language">
      <result>/WEB-INF/content/${browser}/account/change-user-language.jsp</result>
    </action>
  </package>

  <package name="secure-ssl-account" extends="defaultPackage" namespace="/secure/ssl/account">
    <default-interceptor-ref name="secureStack" />
    <action name="change-login">
      <result>/WEB-INF/content/${browser}/account/change-login.jsp</result>
    </action>
    <action name="view-change-email">
      <result>/WEB-INF/content/${browser}/account/change-email.jsp</result>
    </action>
    <action name="view-change-password">
      <result>/WEB-INF/content/${browser}/account/change-password.jsp</result>
    </action>
  </package>

</struts>


package com.softlagos.web.struts2.action.account;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.security.web.authentication.WebAuthenticationDetails;

import com.softlagos.common.Message;
import com.softlagos.common.Response;
import com.softlagos.common.validator.PasswordValidator;
import com.softlagos.domain.account.AccountResponse;
import com.softlagos.domain.account.PrivilegeType;
import com.softlagos.domain.account.RoleNameType;
import com.softlagos.domain.account.UserAccount;
import com.softlagos.domain.address.Email;
import com.softlagos.web.cookie.CookieManager;
import com.softlagos.web.cookie.CookieManagerFactory;
import com.softlagos.web.struts2.action.common.BaseAction;


/**
 * Handles the registration form submit to register a user account on the
 * system.
 *
 * @author Rubens Gomes
 * @version $Id: RegisterAction.java 3657 2011-01-27 17:38:40Z rgomes $
 */
@Namespace("/ssl/account")
@Results({
    @Result(name="cancel", location="/", type="redirect"),
    @Result(name="error", location="/WEB-INF/content/${browser}/account/register.jsp", type="dispatcher"),
    @Result(name="input", location="/WEB-INF/content/${browser}/account/register.jsp", type="dispatcher"),
    @Result(name="success", location="/secure/addressbook/address-book.do", type="redirect")
})
public final class RegisterAction extends BaseAction
{
    private static final long serialVersionUID = 1;
    private static final Log logger = LogFactory.getLog(RegisterAction.class.getName());
    static final Log newAccountLogger = LogFactory.getLog("NewAccountLogger");
    private String email;
    private String password;
    private String confirmPassword;
    private String termsAgreed;
    private boolean cancel = false;

    public RegisterAction()
    {
        super();
    }

    @Override
    public void validate()
    {
        if (this.isCancel())
        {
            return;
        }

        if (StringUtils.isBlank(this.termsAgreed))
        {
            this.addFieldError("termsAgreed", this.getText("error.account.termsNotAccepted"));
        }

        if (StringUtils.isEmpty(this.email))
        {
            this.addFieldError("email", this.getText("error.account.emailRequired"));
        }
        else if (!Email.isEmailValid(email))
        {
            this.addFieldError("email", this.getText("error.account.emailInvalid"));
        }

        // password
        if (StringUtils.isBlank(this.password))
        {
            this.addFieldError("password", this.getText("error.authentication.passwordRequired"));
        }
        else if (!UserAccount.isPasswordValid(this.password))
        {
            List<String> args = new ArrayList<String>();
            args.add("" + PasswordValidator.MIN_PASSWORD_LENGTH);
            args.add("" + PasswordValidator.MAX_PASSWORD_LENGTH);
            this.addFieldError("password",
                this.getText("error.authentication.passwordInvalid", args.toArray(new String[0])));
        }

        // confirm password
        if (StringUtils.isBlank(this.confirmPassword))
        {
            this.addFieldError("confirmPassword", this.getText("error.authentication.passwordRequired"));
        }
        else if (!UserAccount.isPasswordValid(this.confirmPassword))
        {
            List<String> args = new ArrayList<String>();
            args.add("" + PasswordValidator.MIN_PASSWORD_LENGTH);
            args.add("" + PasswordValidator.MAX_PASSWORD_LENGTH);
            this.addFieldError("confirmPassword",
                this.getText("error.authentication.passwordInvalid", args.toArray(new String[0])));
        }
        else if (!this.confirmPassword.equals(this.password))
        {
            this.addFieldError("confirmPassword", this.getText("error.account.passwordsDifferent"));
        }
    }

    @Override
    public String execute()
    {
        if (this.isCancel())
        {
            return "cancel";
        }

        AccountResponse response = BaseAction.accountService.createUserAccount(this.email, this.password,
                this.getClientIpAddr(), RoleNameType.ROLE_USER, PrivilegeType.READ_WRITE, this.email,
                this.getLocale());

        Message error = response.getErrorMessage();
        if (error != null)
        {
            String errorMsg = this.getErrorTextMessage(error);
            if (logger.isInfoEnabled())
            {
                logger.info("error occurred creating account: " + errorMsg);
            }

            this.addActionError(errorMsg);
            return ERROR;
        }

        UserAccount account = response.getUserAccount();
        Response notificationResponse = BaseAction.notificationService.newAccountConfirmation(account.getUserProfile().getPrimaryEmail(),
                this.getConfirmationUrl("/account/confirm-new-account.do"));
        error = notificationResponse.getErrorMessage();
        if (error != null)
        {
            String errorMsg = this.getErrorTextMessage(error);
            if (logger.isInfoEnabled())
            {
                logger.info("error occurred submitting new account notification: " + errorMsg);
            }

            this.addActionError(errorMsg);
            return ERROR;
        }

        WebAuthenticationDetails details = new WebAuthenticationDetails(this.getRequest());
        Response securityResponse = BaseAction.securityService.establishSecurityAuthentication(details,
                account.getId());
        error = securityResponse.getErrorMessage();
        if (error != null)
        {
            String errorMsg = this.getErrorTextMessage(error);
            if (logger.isInfoEnabled())
            {
                logger.info("error occurred creating account: " + errorMsg);
            }

            this.addActionError(errorMsg);
            return ERROR;
        }

        // at this point an authentication has been placed on the security context,
        // and we can safely redirect the user to the contacts list page.

        // store prefered language on the cookie to remember user's prefered language.
        CookieManager cookieManager = CookieManagerFactory.getInstance(this.getRequest(), this.getResponse());
        cookieManager.setLanguageCookie(this.getLocale().getLanguage());

        // store the account Id on the session
        this.getUserSession().setAccountId(account.getId());

        if (newAccountLogger.isInfoEnabled())
        {
            newAccountLogger.info("-------------------------------------------------------------------");
            newAccountLogger.info("Account created [" + account.getUsername() + "]");
            newAccountLogger.info("Client IP address [" + account.getRegisteredClientIpAddress() + "]");
        }

        return SUCCESS;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password)
    {
        this.password = password;
    }

    /**
     * @return the password
     */
    public String getPassword()
    {
        return this.password;
    }

    /**
     * @return the confirmPassword
     */
    public String getConfirmPassword()
    {
        return confirmPassword;
    }

    /**
     * @param confirmPassword the confirmPassword to set
     */
    public void setConfirmPassword(String confirmPassword)
    {
        this.confirmPassword = confirmPassword;
    }

    /**
     * @return the user primary email
     */
    public String getEmail()
    {
        return this.email;
    }

    /**
     * @param primaryEmail the user primary email to set
     */
    public void setEmail(String primaryEmail)
    {
        this.email = (primaryEmail != null) ? primaryEmail.trim() : null;
    }

    /**
     * @return the terms
     */
    public final String getTermsAgreed()
    {
        return this.termsAgreed;
    }

    /**
     * @param terms the terms to set
     */
    public final void setTermsAgreed(String terms)
    {
        this.termsAgreed = terms;
    }

    /**
     * @return the cancel
     */
    public boolean isCancel()
    {
        return cancel;
    }

    /**
     * notice that if the corresponding button is pressed the cancel should be set to true.
     *
     * @param cancel the cancel to set
     */
    public void setCancel(boolean dummy)
    {
        this.cancel = true;
    }
}

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


Re: S2 Action Setter Not Called

Posted by Dave Newton <da...@gmail.com>.
We'll need more info. Looks like a validation error so far.

Dave

On Thu, Feb 3, 2011 at 1:31 AM, Rubens Gomes <Ru...@appia.com> wrote:
> Hello,
>
> I am running Struts 2 (version 2.2.1.1) and the struts2-convention-plugin to annotate all Actions.
>
> My action parameter setters are not being called by the ParametersInterceptor.  The form does submit the email
> parameter to my action.  And the logs show that parameter on the ParametersInterceptor DEBUG log.  However, the corresponding action  email setter is not called.  I did verify that the of the parameter matches both setter / getter.
>
> Any ideas?
>
> 02/03/11 12:42:50 AM [com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler] DEBUG: Entering nullPropertyValue [target=[com.opensymphony.xwork2.DefaultTextProvider@101bc44], property=struts]
> 02/03/11 12:42:50 AM [com.opensymphony.xwork2.config.ConfigurationManager] DEBUG: Checking ConfigurationProviders for reload.
> 02/03/11 12:42:50 AM [com.opensymphony.xwork2.DefaultActionProxy] DEBUG: Creating an DefaultActionProxy for namespace /account and action name request-pwd
> 02/03/11 12:42:50 AM [com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler] DEBUG: Entering nullPropertyValue [target=[com.softlagos.web.struts2.action.account.RequestPwdAction@4ba679, com.opensymphony.xwork2.DefaultTextProvider@101bc44], property=fontSize]
> 02/03/11 12:42:50 AM [com.opensymphony.xwork2.interceptor.I18nInterceptor] DEBUG: intercept '/account/request-pwd' {
> 02/03/11 12:42:50 AM [com.opensymphony.xwork2.interceptor.I18nInterceptor] DEBUG: applied invocation context locale=pt_BR
> 02/03/11 12:42:50 AM [com.opensymphony.xwork2.interceptor.I18nInterceptor] DEBUG: before Locale=pt_BR
> 02/03/11 12:42:50 AM [com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler] DEBUG: Entering nullPropertyValue [target=[{browser=mobile}, com.softlagos.web.struts2.action.account.RequestPwdAction@4ba679, com.opensymphony.xwork2.DefaultTextProvider@101bc44], property=struts]
> 02/03/11 12:42:51 AM [org.apache.struts2.interceptor.FileUploadInterceptor] DEBUG: Ignorando /account/ request-pwd
> 02/03/11 12:42:51 AM [com.opensymphony.xwork2.interceptor.StaticParametersInterceptor] DEBUG: Setting static parameters {}
> 02/03/11 12:42:51 AM [com.opensymphony.xwork2.interceptor.ParametersInterceptor] DEBUG: Setting params NONE
> 02/03/11 12:42:51 AM [com.opensymphony.xwork2.interceptor.ParametersInterceptor] DEBUG: Setting params email => [ rgomes@ezlista.com ] mobile => [ true ] recoverPwdButton => [ Submit ]
> 02/03/11 12:42:51 AM [org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor] DEBUG: Validating /account/request-pwd with method execute.
> 02/03/11 12:42:51 AM [com.opensymphony.xwork2.validator.ValidationInterceptor] DEBUG: Invoking validate() on action com.softlagos.web.struts2.action.account.RequestPwdAction@4ba679
> 02/03/11 12:42:51 AM [com.opensymphony.xwork2.interceptor.PrefixMethodInvocationUtil] DEBUG: cannot find method [validateExecute] in action [com.softlagos.web.struts2.action.account.RequestPwdAction@4ba679]
> 02/03/11 12:42:51 AM [com.opensymphony.xwork2.interceptor.PrefixMethodInvocationUtil] DEBUG: cannot find method [validateDoExecute] in action [com.softlagos.web.struts2.action.account.RequestPwdAction@4ba679]
> 02/03/11 12:43:03 AM [com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler] DEBUG: Entering nullPropertyValue [target=[{email=[Ljava.lang.String;@1adf96a, browser=mobile, recoverPwdButton=[Ljava.lang.String;@d1d45a, mobile=[Ljava.lang.String;@1cc6f7e}, com.softlagos.web.struts2.action.account.RequestPwdAction@4ba679, com.opensymphony.xwork2.DefaultTextProvider@101bc44], property=error]
> 02/03/11 12:43:03 AM [com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler] DEBUG: Entering nullPropertyValue [target=[{email=[Ljava.lang.String;@1adf96a, browser=mobile, recoverPwdButton=[Ljava.lang.String;@d1d45a, mobile=[Ljava.lang.String;@1cc6f7e}, com.softlagos.web.struts2.action.account.RequestPwdAction@4ba679, com.opensymphony.xwork2.DefaultTextProvider@101bc44], property=error]
> 02/03/11 12:43:03 AM [com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor] DEBUG: Errors on action com.softlagos.web.struts2.action.account.RequestPwdAction@4ba679, returning result name 'input'
> 02/03/11 12:43:03 AM [com.opensymphony.xwork2.ognl.accessor.XWorkMapPropertyAccessor] DEBUG: Entering getProperty (ognl.OgnlContext@fa455359,{email=[Ljava.lang.String;@1adf96a, browser=mobile, recoverPwdButton=[Ljava.lang.String;@d1d45a, mobile=[Ljava.lang.String;@1cc6f7e},browser)
> 02/03/11 12:43:03 AM [org.apache.struts2.dispatcher.ServletDispatcherResult] DEBUG: Forwarding to location /WEB-INF/content/mobile/account/request-pwd.jsp
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


RE: S2 Action Setter Not Called

Posted by Martin Gainty <mg...@hotmail.com>.
  /**
     * Set a override map containing <code>key -> values</code> that takes precedent when doing find operations on the ValueStack.
     * <p/>
     * See the unit test for ValueStackTest for examples.
     * @param overrides  overrides map.
     */
//best not to use Map <String,Object> when you want to push a browser object into the map
//use Map<Object,Object> instead as seen here
    Map<Object, Object> overrides=new HashMap<Object, Object>();

//push any object you want into the overrides map
    overrides.put("browser", userSession.getBrowser());
            ActionContext.getContext().getValueStack().setExprOverrides(overrides);

//now when you use ValueStack.findValue(String expr) you will find the object (including browser) from the overrides map

Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> Date: Fri, 4 Feb 2011 18:27:53 +0900
> From: li.wei.linfeng@gmail.com
> To: user@struts.apache.org
> CC: Rubens.Gomes@appia.com
> Subject: Re: S2 Action Setter Not Called
> 
> the problem is that you pushed a HashMap on the ValueStack's root.
> 
> if you do that, all the values will be populated to the HashMap, not 
> your action class
> 
> you can try this code to fix it.
> 
>   ActionContext.getContext().put("browser", userSession.getBrowser());
> 
> 
> 
> (2011/02/04 17:12), Rubens Gomes wrote:
> > Okay.  I found what is causing the setters not to be called.   I have an interceptor called ValueStackInterceptor (which is called prior to ParametersInterceptors) that is placing a String variable "browser" on the stack (please, see code below). If I comment out the line that places this variable on the stack (see below) everything works fine.  I am showing the Interceptor and the line of code that is causing a problem.
> >
> > Can someone please help me understand what is the problem with this code?
> >
> >
> > -----------------------------------------
> >
> > package com.softlagos.web.struts2.interceptor;
> >
> > import java.util.HashMap;
> > import java.util.Map;
> >
> > import javax.servlet.http.HttpServletRequest;
> >
> > import org.apache.commons.lang.xwork.StringUtils;
> > import org.apache.commons.logging.Log;
> > import org.apache.commons.logging.LogFactory;
> > import org.apache.struts2.ServletActionContext;
> >
> > import com.opensymphony.xwork2.ActionContext;
> > import com.opensymphony.xwork2.ActionInvocation;
> > import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
> > import com.softlagos.web.common.UserSession;
> > import com.softlagos.web.common.WebAppUtils;
> >
> >
> > /**
> >   * Interceptor object used to initialize the Struts 2 Value Stack with some state information (like the
> >   * browser variable) that is needed in the results.
> >   *
> >   * @author  Rubens Gomes
> >   * @version $Id: ValueStackInterceptor.java 3754 2011-02-03 00:39:46Z rgomes $
> >   */
> > public final class ValueStackInterceptor extends AbstractInterceptor
> > {
> >      private static final long serialVersionUID = 1;
> >      private static final Log logger = LogFactory.getLog(ValueStackInterceptor.class.getName());
> >
> >      public ValueStackInterceptor()
> >      {
> >          super();
> >      }
> >
> >      @Override
> >      public String intercept(final ActionInvocation invocation)
> >          throws Exception
> >      {
> >          HttpServletRequest request = ServletActionContext.getRequest();
> >          UserSession userSession = WebAppUtils.getUserSession(request);
> >
> >          /*
> >           * The DetectUserAgentFilter code should be run prior to Struts 2 filter because that filter
> >           * is responsible for setting the browser on the HTTP userSession session object.
> >           */
> >          if(userSession==null)
> >              throw new IllegalStateException("The userSession was not set.");
> >
> >          if(StringUtils.isBlank(userSession.getBrowser()))
> >          {
> >              String msg = "The userSession browser is null, which means that the user agent detection failed.  Code cannot proceed at this point.";
> >              IllegalStateException ex = new IllegalStateException(msg);
> >              logger.error(msg, ex);
> >              throw ex;
> >          }
> >          if(logger.isInfoEnabled())
> >              logger.info("Setting Struts2 value stack browser [" + userSession.getBrowser() + "].");
> >
> >          Map<String, Object>  context = new HashMap<String, Object>();
> >          // browser is used on Result objects to render either a desktop or mobile JSP page.
> >
> >          context.put("browser", userSession.getBrowser());
> >
> > /*  ---->>>   THE FOLLOWING LINE IS IMPACTING ON ACTION SETTER NOT TO BE CALLED<<<  ---- */
> >          ActionContext.getContext().getValueStack().push(context);
> >
> >
> >          /* --- Reverse Path --- */
> >          return invocation.invoke();
> >      }
> > }
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> 
 		 	   		  

Re: S2 Action Setter Not Called

Posted by li wei <li...@gmail.com>.
the problem is that you pushed a HashMap on the ValueStack's root.

if you do that, all the values will be populated to the HashMap, not 
your action class

you can try this code to fix it.

  ActionContext.getContext().put("browser", userSession.getBrowser());



(2011/02/04 17:12), Rubens Gomes wrote:
> Okay.  I found what is causing the setters not to be called.   I have an interceptor called ValueStackInterceptor (which is called prior to ParametersInterceptors) that is placing a String variable "browser" on the stack (please, see code below). If I comment out the line that places this variable on the stack (see below) everything works fine.  I am showing the Interceptor and the line of code that is causing a problem.
>
> Can someone please help me understand what is the problem with this code?
>
>
> -----------------------------------------
>
> package com.softlagos.web.struts2.interceptor;
>
> import java.util.HashMap;
> import java.util.Map;
>
> import javax.servlet.http.HttpServletRequest;
>
> import org.apache.commons.lang.xwork.StringUtils;
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> import org.apache.struts2.ServletActionContext;
>
> import com.opensymphony.xwork2.ActionContext;
> import com.opensymphony.xwork2.ActionInvocation;
> import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
> import com.softlagos.web.common.UserSession;
> import com.softlagos.web.common.WebAppUtils;
>
>
> /**
>   * Interceptor object used to initialize the Struts 2 Value Stack with some state information (like the
>   * browser variable) that is needed in the results.
>   *
>   * @author  Rubens Gomes
>   * @version $Id: ValueStackInterceptor.java 3754 2011-02-03 00:39:46Z rgomes $
>   */
> public final class ValueStackInterceptor extends AbstractInterceptor
> {
>      private static final long serialVersionUID = 1;
>      private static final Log logger = LogFactory.getLog(ValueStackInterceptor.class.getName());
>
>      public ValueStackInterceptor()
>      {
>          super();
>      }
>
>      @Override
>      public String intercept(final ActionInvocation invocation)
>          throws Exception
>      {
>          HttpServletRequest request = ServletActionContext.getRequest();
>          UserSession userSession = WebAppUtils.getUserSession(request);
>
>          /*
>           * The DetectUserAgentFilter code should be run prior to Struts 2 filter because that filter
>           * is responsible for setting the browser on the HTTP userSession session object.
>           */
>          if(userSession==null)
>              throw new IllegalStateException("The userSession was not set.");
>
>          if(StringUtils.isBlank(userSession.getBrowser()))
>          {
>              String msg = "The userSession browser is null, which means that the user agent detection failed.  Code cannot proceed at this point.";
>              IllegalStateException ex = new IllegalStateException(msg);
>              logger.error(msg, ex);
>              throw ex;
>          }
>          if(logger.isInfoEnabled())
>              logger.info("Setting Struts2 value stack browser [" + userSession.getBrowser() + "].");
>
>          Map<String, Object>  context = new HashMap<String, Object>();
>          // browser is used on Result objects to render either a desktop or mobile JSP page.
>
>          context.put("browser", userSession.getBrowser());
>
> /*  ---->>>   THE FOLLOWING LINE IS IMPACTING ON ACTION SETTER NOT TO BE CALLED<<<  ---- */
>          ActionContext.getContext().getValueStack().push(context);
>
>
>          /* --- Reverse Path --- */
>          return invocation.invoke();
>      }
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


RE: S2 Action Setter Not Called

Posted by Rubens Gomes <Ru...@appia.com>.
Okay.  I found what is causing the setters not to be called.   I have an interceptor called ValueStackInterceptor (which is called prior to ParametersInterceptors) that is placing a String variable "browser" on the stack (please, see code below). If I comment out the line that places this variable on the stack (see below) everything works fine.  I am showing the Interceptor and the line of code that is causing a problem.

Can someone please help me understand what is the problem with this code?


-----------------------------------------

package com.softlagos.web.struts2.interceptor;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.xwork.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.softlagos.web.common.UserSession;
import com.softlagos.web.common.WebAppUtils;


/**
 * Interceptor object used to initialize the Struts 2 Value Stack with some state information (like the
 * browser variable) that is needed in the results.
 *
 * @author  Rubens Gomes
 * @version $Id: ValueStackInterceptor.java 3754 2011-02-03 00:39:46Z rgomes $
 */
public final class ValueStackInterceptor extends AbstractInterceptor
{
    private static final long serialVersionUID = 1;
    private static final Log logger = LogFactory.getLog(ValueStackInterceptor.class.getName());

    public ValueStackInterceptor()
    {
        super();
    }

    @Override
    public String intercept(final ActionInvocation invocation)
        throws Exception
    {
        HttpServletRequest request = ServletActionContext.getRequest();
        UserSession userSession = WebAppUtils.getUserSession(request);

        /*
         * The DetectUserAgentFilter code should be run prior to Struts 2 filter because that filter
         * is responsible for setting the browser on the HTTP userSession session object.
         */
        if(userSession==null)
            throw new IllegalStateException("The userSession was not set.");

        if(StringUtils.isBlank(userSession.getBrowser()))
        {
            String msg = "The userSession browser is null, which means that the user agent detection failed.  Code cannot proceed at this point.";
            IllegalStateException ex = new IllegalStateException(msg);
            logger.error(msg, ex);
            throw ex;
        }
        if(logger.isInfoEnabled())
            logger.info("Setting Struts2 value stack browser [" + userSession.getBrowser() + "].");

        Map<String, Object> context = new HashMap<String, Object>();
        // browser is used on Result objects to render either a desktop or mobile JSP page.

        context.put("browser", userSession.getBrowser());

/*  ---- >>>  THE FOLLOWING LINE IS IMPACTING ON ACTION SETTER NOT TO BE CALLED <<< ---- */
        ActionContext.getContext().getValueStack().push(context);


        /* --- Reverse Path --- */
        return invocation.invoke();
    }
}


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