struts 2.1.8 not working on xXxxx property

View: New views
5 Messages — Rating Filter:   Alert me  

struts 2.1.8 not working on xXxxx property

by KamHon Eng :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
I just try to upgrade my project from struts 2.1.6 to struts 2.1.8, I
found that some property is not working.
For example, property username in Login.class working while sUsername
is not working.
Lets do a simple test on struts2 blank project in struts2.1.8.zip

1. unzip struts2-blank-2.1.8.war.
2. add the following code at Login.jsp
  <s:textfield key="username"/>
  <s:textfield name="sUsername" label="sUsername"/>
  <s:password key="password" />
3. add the following code at Login-validation.xml.
<validators>
......
<field name="sUsername">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
</field>
.......
</validators>
4. add the following code at Login.java.
  private String sUsername;
  public String getsUsername() {
  return sUsername;
  }
  public void setsUsername(String sUsername) {
    System.out.println("testing only");
this.sUsername = sUsername;
  }
5. running tomcat, type http://localhost:8080/struts2-blank/example/Login.action

Test 1
=======
1. fill in all fields in the form and click submit button.
2. type admin for Username.
3. type admin2 for sUsername.
4. type 123456 for password.
Result
1. unable to login because screen showing message 'This Field is
required' for sUsername.
2. the text input value for sUsername is blank but the text input
value for Username is 'admin'.

Test 2
=======
1. remove the sUsername validation at Login-validation.xml.
2. type http://localhost:8080/struts2-blank/example/Login.action
3. fill in all fields in the form and click submit button.
Result
unable to see 'testing only' at console. (meaning setter for sUsername
not called).

Thanks.
--
Best Regard,

Kam Hon

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


Re: struts 2.1.8 not working on xXxxx property

by Lukasz Lenart :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/10/30 KamHon Eng <kamhon@...>:
>   private String sUsername;
>   public String getsUsername() {
>   return sUsername;
>   }
>   public void setsUsername(String sUsername) {

Setter/getter should be set/getSUsername, try that way


Regards
--
Lukasz
http://www.lenart.org.pl/
http://dailylog.lenart.org.pl/

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


Re: struts 2.1.8 not working on xXxxx property

by KamHon Eng :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm using eclipse code to generate the getters and setters.
private String sUsername;
  public String getsUsername() {
  return sUsername;
  }
  public void setsUsername(String sUsername) {
this.sUsername = sUsername;
  }

My getter / setter is correct.

Besides, changing the getter / setter is not solve the validation
problem. The xml validator unable to 'detect' sUsername as request
parameter.

It work well on struts2.1.6 too.



On Fri, Oct 30, 2009 at 3:40 PM, Lukasz Lenart
<lukasz.lenart@...> wrote:

> 2009/10/30 KamHon Eng <kamhon@...>:
>>   private String sUsername;
>>   public String getsUsername() {
>>   return sUsername;
>>   }
>>   public void setsUsername(String sUsername) {
>
> Setter/getter should be set/getSUsername, try that way
>
>
> Regards
> --
> Lukasz
> http://www.lenart.org.pl/
> http://dailylog.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>



--
Best Regard,

Kam Hon

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


Re: struts 2.1.8 not working on xXxxx property

by phillips1021 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Instead of

  public String getsUsername() ...

  public void setsUsername(String sUsername) ...

try

  public String getSUsername()...  [note the capital S]

  public void setSUsername()...

Struts 2 will look for and then use a set method that follows the JavaBean convention to set the value for the form parameter.  Struts 2 will look for and use a get method that follows the JavaBean convention to get the value of a property.




Hi,
I just try to upgrade my project from struts 2.1.6 to struts 2.1.8, I
found that some property is not working.
For example, property username in Login.class working while sUsername
is not working.
Lets do a simple test on struts2 blank project in struts2.1.8.zip



Re: struts 2.1.8 not working on xXxxx property

by phillips1021 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I did some testing also.  

Using 2.1.8 with with the following:

sUsername (form field name and instance field name in the ActionSupport class)

public String getsUsername

public void setsUsername

doesn't work as the setsUsername method doesn't get called on form submission.

Using 2.1.6 with the above does work, the setsUsername method does get called on form submission.

Using the following on both 2.1.8 and 2.1.6 does work as expected:

sUsername (form field name and instance field name in the ActionSupport class)

public String getSUsername

public void setSUsername

However in 2.1.8 if you add this validation to Login-validation.xml

<field name="sUsername">
<field-validator type="requiredstring">
<message key="requiredstring" />
</field-validator>
</field>

Validation doesn't occur and form submission fails even if you provide a value for the sUsername form field.

___________________________________



Instead of

  public String getsUsername() ...

  public void setsUsername(String sUsername) ...

try

  public String getSUsername()...  [note the capital S]

  public void setSUsername()...

Struts 2 will look for and then use a set method that follows the JavaBean convention to set the value for the form parameter.  Struts 2 will look for and use a get method that follows the JavaBean convention to get the value of a property.



KamHon Eng wrote:
Hi,
I just try to upgrade my project from struts 2.1.6 to struts 2.1.8, I
found that some property is not working.
For example, property username in Login.class working while sUsername
is not working.
Lets do a simple test on struts2 blank project in struts2.1.8.zip