Re: [ask] How to pass multiple radio button in struts2

2018-12-24 Thread M Huzaifah
Hi Yasser,

i tried, it will exception.

 i use this code bellow to get that value, instead for loop:
request.getParameterValues("viewAccess["+i+"]")[0]
this work for me. i’ll update if i got the proper way about this

Thank you


> On 22 Dec 2018, at 15.31, Yasser Zamani  wrote:
> 
> Hi,
> 
> As different values are setting into same viewAccess[0], I guess instead 
> `private String viewAccess[][];` (array of array) would work.
> 
> Regards. 
> 
>> -Original Message-
>> From: M Huzaifah 
>> Sent: Friday, December 21, 2018 11:44 AM
>> To: Struts Users Mailing List 
>> Subject: [ask] How to pass multiple radio button in struts2
>> 
>> Hi Members,
>> 
>> i would like to ask something about radio button in strtus2.
>> 
>> i have radio button in jsp like this:
>> 
>> 
>> 
>>   All
>>   Self
>>   Custom
>> 
>> 
>> 
>>   All
>>   Self
>>   Custom
>> 
>> 
>> and in my JavaAction class i add property " private String viewAccess[]; “ 
>> also with
>> setter and getter.
>> 
>> the problem is, i am not able to get value of radio button in Java Action. i 
>> use
>> struts 2.3.35
>> 
>> someone could help?
>> 
>> Thank you
> 
> 
> -
> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> For additional commands, e-mail: user-h...@struts.apache.org



RE: How to display both selected key and value of s:select

2018-12-24 Thread Yasser Zamani
Hi Albert,

The simplest method can be something like this:

public class RegisterAction {
...
public Country getSelectedCountryObject() {
foreach (c in countryList) if(c.countryId==selectedCountry) return c;
}
...
}



Thanks for using Struts.

Kind Regards.

>-Original Message-
>From: albert kao 
>Sent: Saturday, December 22, 2018 6:39 PM
>To: Struts Users Mailing List 
>Subject: How to display both selected key and value of s:select
>
>I want to display both selected key and value of s:select.
>e.g. for the following codes, after I select key="2", value="Canada"
>and press the submit button.
>Only the key "Country: 2" is displayed in the registerResult.jsp as desired.
>How to make the value "Canada" to display also in the browser?
>
>public class RegisterAction extends ActionSupport { private String country,
>selectedCountry; private ArrayList countryList;
>
>public RegisterAction() {
>countryList = new ArrayList();
>countryList.add(new Country(1, "India")); countryList.add(new Country(2,
>"Canada")); countryList.add(new Country(3, "US")); return; } }
>
>public class Country {
>private int countryId;
>private String countryName;
>public Country(int countryId, String countryName) { this.countryId = countryId;
>this.countryName = countryName; } public int getCountryId() { return 
>countryId; }
>public void setCountryId(int countryId) { this.countryId = countryId; } public 
>String
>getCountryName() { return countryName; } public void setCountryName(String
>countryName) { this.countryName = countryName; } }
>
>register.jsp
>
>
>listValue="countryName"
>value="selectedCountry"
>headerKey="0" headerValue="Country"
>label="Select a country" />
>
>
>
>
>
>registerResult.jsp
>Country:  selectedCountry:
> CountryListAll: value="getCountryList()" /> CountryListAll2: value="countryList" /> CountryList: value="getCountryList().get(country)" /> CountryList.get value="countryList.get(country)" />
>
>
>http://localhost:8080/Struts2Example/register.action
>Country: 2
>selectedCountry: CountryListAll: [com.test.common.Country@32cdbdf6,
>com.test.common.Country@6cbe3d89, com.test.common.Country@7abf043f]
>CountryListAll2: [com.test.common.Country@32cdbdf6,
>com.test.common.Country@6cbe3d89, com.test.common.Country@7abf043f]
>CountryList: com.test.common.Country@7abf043f CountryList.get
>com.test.common.Country@7abf043f