Instancia the bean

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Instancia the bean

José Antonio Delgado Trujillo
If you have a form linked to a bean using key attribute, then when you submitted, must you instantiate the bean before the call action populate the properties? Or Strust2 instantiate automatically after you call the action.

<form action=“a”>
        <s:textField key=“bean.t”/>
<submit/>

//The method execute of the A class action

public class A extends AcctionSupport{
    private Object bean;

    public String void execute(){
        //Call business logic method
        control(bean);
        return SUCCESS;
    }
}

This throws a NullpointerException???



Un saludo,
José A.

Reply | Threaded
Open this post in threaded view
|

Re: Instancia the bean

José Antonio Delgado Trujillo
I think Strus2 don’t instantiate the bean so you must instantiate perhaps in the prepare method or in the definition of the property class.

> On 2 Jan 2018, at 21:38, José Antonio Delgado Trujillo <[hidden email]> wrote:
>
> If you have a form linked to a bean using key attribute, then when you submitted, must you instantiate the bean before the call action populate the properties? Or Strust2 instantiate automatically after you call the action.
>
> <form action=“a”>
> <s:textField key=“bean.t”/>
> <submit/>
>
> //The method execute of the A class action
>
> public class A extends AcctionSupport{
>     private Object bean;
>
>     public String void execute(){
>         //Call business logic method
>         control(bean);
> return SUCCESS;
>     }
> }
>
> This throws a NullpointerException???
>
>
>
> Un saludo,
> José A.
>

Reply | Threaded
Open this post in threaded view
|

Re: Instancia the bean

Lukasz Lenart
In reply to this post by José Antonio Delgado Trujillo
2018-01-02 22:38 GMT+01:00 José Antonio Delgado Trujillo <[hidden email]>:

> If you have a form linked to a bean using key attribute, then when you submitted, must you instantiate the bean before the call action populate the properties? Or Strust2 instantiate automatically after you call the action.
>
> <form action=“a”>
>         <s:textField key=“bean.t”/>
> <submit/>
>
> //The method execute of the A class action
>
> public class A extends AcctionSupport{
>     private Object bean;
>
>     public String void execute(){
>         //Call business logic method
>         control(bean);
>         return SUCCESS;
>     }
> }
>
> This throws a NullpointerException???

Do you have a setter and getter setBean/getBean ?
Does the bean have a default contructor?
And I assume the type is not Object as Object doesn't have a property "t"


Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Instancia the bean

Yasser Zamani-2
In reply to this post by José Antonio Delgado Trujillo


On 1/3/2018 1:08 AM, José Antonio Delgado Trujillo wrote:
> If you have a form linked to a bean using key attribute, then when you submitted, must you instantiate the bean before the call action populate the properties? Or Strust2 instantiate automatically after you call the action.

You must instantiate bean like below ....

>
> <form action=“a”>
> <s:textField key=“bean.t”/>
> <submit/>
>
> //The method execute of the A class action
>
> public class A extends AcctionSupport{
>      private Object bean;

private Object bean = new ...; //because for "bean.t" Struts calls
getBean().getT() on get and getBean().setT() on post.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Instancia the bean

Lukasz Lenart
2018-01-03 7:23 GMT+01:00 Yasser Zamani <[hidden email]>:
> On 1/3/2018 1:08 AM, José Antonio Delgado Trujillo wrote:
>> If you have a form linked to a bean using key attribute, then when you submitted, must you instantiate the bean before the call action populate the properties? Or Strust2 instantiate automatically after you call the action.
>
> You must instantiate bean like below ....

Nope, you do not have to, Struts/OGNL will do it for you

https://struts.apache.org/core-developers/type-conversion.html#null-property-handling


Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Instancia the bean

José Antonio Delgado Trujillo
OK thanks Lukasz,
i hadn’t put the default constructor in the model class. Now it works!



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]