You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Nitin Mandolkar <Ni...@servista.com> on 2005/05/20 13:37:52 UTC

set-property?

In this action mapping. What is mean by set-property. What it will do.
How we can use this one. 

In which condition this is useful.

 

    <action path="/myapp/logininfo"

            name="LoginForm"

            type="com.myapp.LoginAction"

            scope="session">

        <set-property property="secure"           value="false" />

        <set-property property="authenticated"    value="true" />

        <forward name="init"        path="/customer/login.jsp" />

        <forward name="init_fail"   path="/error.jsp" />

        <forward name="success"     path="/product.do />

        <forward name="failure"     path=""/customer/login.jsp" />

   </action>

 

 


Re: set-property?

Posted by Hubert Rabago <hr...@gmail.com>.
The <set-property> element is used to set properties when using custom
configuration objects.  For your particular example, check the custom
ActionMapping configuration object declared in the <action-mapping>
tag.

The /WEB-INF/struts-config.xml that comes with struts-examples.war
illustrates this:

  <action-mappings 
      type="org.apache.struts.webapp.examples.CustomActionMapping"> 

    <action path="/welcome" forward="/welcome.jsp" >
        <set-property property="example" value="EXAMPLE" />
    </action>

  </action-mappings>

If you look at the CustomActionMapping source code, you'll see it has
an "example" property with accessors.  You can access this value in
your action via the ActionMapping parameter provided to the execute()
method:

    public ActionForward execute(
            ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response)
            throws Exception {

        CustomActionMapping cam = (CustomActionMapping) mapping;
        String example = cam.getExample();
        ...

    }

The struts-examples.war app comes with the Struts binary distribution.
 (The war itself includes its source.)  It shows other config elements
(form-bean, forward) using arbitrary properties as well.


Note that starting with Struts 1.3, you can provide arbitrary
properties to configuration elements without requiring a custom
object.  This is done by using the key attribute:

    <set-property key="example" value="EXAMPLE" />

Then in the action:

    String example = mapping.getProperty("example");


Hubert


On 5/20/05, Nitin Mandolkar <Ni...@servista.com> wrote:
> In this action mapping. What is mean by set-property. What it will do.
> How we can use this one.
> 
> In which condition this is useful.
> 
>     <action path="/myapp/logininfo"
>             name="LoginForm"
>             type="com.myapp.LoginAction"
>             scope="session">
> 
>         <set-property property="secure"           value="false" />
>         <set-property property="authenticated"    value="true" />
> 
>         <forward name="init"        path="/customer/login.jsp" />
>         <forward name="init_fail"   path="/error.jsp" />
>         <forward name="success"     path="/product.do />
>         <forward name="failure"     path=""/customer/login.jsp" />
>    </action>
>

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