I am trying to do a form that has one model and 2 values that are always the same but there is one value that changes.
My html form is:
#helper.form(action = routes.TeacherController.putQuestionToAssignment(), 'class -> "form-horizontal") {
<input type="hidden" name="size" value="#{size}">
<input type="hidden" name="assignment_id" value="#{assignment_id}">
#for(question <- questions){
<input type="checkbox" name="question_id" value="#{question.question_id}">
}
<button type="submit" class="btn btn-primary" value="submit">create</button>
}
my model:
#Entity
public class Verkefnaspurningar extends Model {
#Id
public int verkefnaspurningar_id;
#Constraints.Required
public int assignment_id;
#Constraints.Required
public int question_id;
#Constraints.Required
public Double size;
and in the controller i am going to try to create a model for each question that is checked in the checkbox in the form, but i have no idea how to do that, can i maybe set an id on the question_id field in the form and loop through that?
public static Result putQuestionToAssignment(){
Form<Verkefnaspurningar> verkefnaspurningarForm = form(Verkefnaspurningar.class).bindFromRequest();
int question_id= verkefnaspurningarForm.get().question_id;
Double size= verkefnaspurningarForm.get().size;
int assignmentId= verkefnaspurningarForm.get().assignment_id;
Verkefnaspurningar verkefnaspurningar = Verkefnaspurningar.create(assignmentId, question_id, size);
return redirect(routes.TeacherController.createAssignment());
}
Hoping that this post is not to dumb, my first one, with kind regards Björn.
Here is my idea to the solution for your problem. But, I test this solution using Play!Framework 2.1.0.
In your controller, you can get the checked question_id value submitted by user like this :
public static Result putQuestionToAssignment() {
// get all HTTP request value from submitted form
Map<String, String[]> map = request().body().asFormUrlEncoded();
String[] allCheckedData = map.get("question_id"); // get all checked question
... // bind the rest of request parameter to variable if needed
Verkefnaspurningar verkefnaspurningar;
// Loop for each checked question
for (String t : allCheckedData) {
Logger.info("Checked data is " + t);
verkefnaspurningar = new Verkefnaspurningar(); // create each data
... // put the rest of code for saving the model
}
return TODO; // still dummy. Should be redirect!
}
Please note that I'm not use Form in this solution. I get all the request parameter from submitted form using request().body().asFormUrlEncoded(). Check documentation for RequestBody here.
I would use a DynamicForm for this. It would be something like:
public static Result putQuestionToAssignment(){
DynamicForm form = form().bindFromRequest();
Set<Long> ids = new HashSet<Long>();
for (Entry<String, String> entry : form.data().entrySet()) {
ids.add(Long.valueOf(entry.getValue()));
}
Verkefnaspurningar verkefnaspurningar;
for (Long id : ids) {
verkefnaspurningar = Verkefnaspurningar.create(assignmentId, id, ids.size());
}
return redirect(routes.TeacherController.createAssignment());
}
To get the assignmentId, you may have to add a condition when looping over form.data().entrySet(): if entry.getKey() if the one of your assignment, then store id, else add value to Set.
Related
I would like someone to help me on how to update row with entity manager. Here is a table ex, in angular where data is sent to rest service:
app.html
<tr *ngFor="let myCar of cars$ | paginate: { itemsPerPage: count, currentPage: p }; let i = index">
<td>{{ (p - 1) * count + i + 1 }}</td>
<td>{{myCar.name}}</td>
<td>{{myCar.price}}</td>
<td><button type="submit" class="btn btn-secondary" (click)="fillForm(myCar)">
<i class="glyphicon glyphicon-edit"></i>Edit
</button></td>
</tr>
carsDTO.java
#Id
#Column(name = "name")
private String name;
#Column(name = "price")
private String price;
service.java
public carsDTO updateCar(carDTO cars){
TypedQuery<myquerycalss> query = entitymanager.createNamedQuery("sqlName",
myquerycalss.class);
// I need help to complete this update method
// Maybe no need to first find by id, the row gets update based on #id
// on the name
}
resource.java
#PUT
#Path("/updatecars")
public Response updateCar(){
// no preblem here
}
Note: You can see that in the app.html I have ID generated but my jave class just name and price variables.
What is the best approach to update a chosen entity, that is, fields of database record, in my service.java? My resouces url is without parameter, that is URL: .../updatecars
Your resource needs to receive the car selected and changed in the frontend.
You can change it to receive inside the request body, using this:
#RequestMapping(method = RequestMethod.PUT, value = "/updatecars")
public Response updateCar(#RequestBody() carDTO car){
// here you call the service, passing the car as parameter
service.updateCar(car);
}
Inside your angular component, you have to put the car selected in the http request. Something like this:
saveCar(car: carDTO){
return this.httpBase.put(this.url, car, this.options)
.map(dados => dados.json()); // handle the return here....
}
Inside your service:
public carsDTO updateCar(carDTO cars) {
TypedQuery<myquerycalss> query = entitymanager.createNamedQuery("sqlName", myquerycalss.class);
query.setParameter("name", cars.getName());
query.setParameter("price", cars.getPrice());
query.executeUpdate();
...
}
I'm assuming that your named query SQL is like this:
UPDATE cars SET price = :price WHERE name = :name
I need choose values from one array and assign it to other array. Using Spring Thymeleaf. No idea how retrieve these choosed values.
My classes:
#Entity
public class Collaborator {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#NotNull
#Size (min=3, max=32)
private String name;
#NotNull
#ManyToOne (cascade = CascadeType.ALL)
private Role role;
public Collaborator() {}...
#Entity
public class Role {
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
#NotNull
#Size(min = 3, max = 99)
private String name;
public Role() {}....
My controllers:
#RequestMapping("/project_collaborators/{projectId}")
public String projectCollaborators(#PathVariable Long projectId, Model model) {
Project project = mProjectService.findById(projectId);
List<Collaborator> allCollaborators = mCollaboratorService.findAll();
List<Collaborator> assignments = new ArrayList<>();
if (project.getRolesNeeded()!=null) {
for (int i=0;i<project.getRolesNeeded().size();i++) {
assignments.add(new Collaborator("Unassigned", project.getRolesNeeded().get(i)));
assignments.get(i).setId((long) 0);
}
}
model.addAttribute("assignments", assignments);
model.addAttribute("allCollaborators", allCollaborators);
model.addAttribute("project", project);
return "project_collaborators";
}
#RequestMapping(value = "/project_collaborators/{projectId}", method = RequestMethod.POST)
public String projectCollaboratorsPost(#ModelAttribute Project project, #PathVariable Long projectId, Model model) {
Project p = mProjectService.findById(projectId);
//mProjectService.save(project);
return "redirect:/project_detail/{projectId}";
}
And template:
<form th:action="#{'/project_collaborators/' + ${project.id}}" method="post" th:object="${project}">
<label th:text="'Edit Collaborators: ' + ${project.name}">Edit Collaborators: Website Project</label>
<ul class="checkbox-list">
<li th:each="a : ${assignments}">
<span th:text="${a.role.name}" class="primary">Developer</span>
<div class="custom-select">
<span class="dropdown-arrow"></span>
<select th:field="${a.id}">
<option th:each="collaborator : ${allCollaborators}" th:value="${collaborator.id}" th:text="${collaborator.name}">Michael Pemulis</option>
</select>
</div>
</li>
</ul>
<div class="actions">
<input type="submit" value="Save" class="button"/>
Cancel
</div>
</form>
As you can see I want to let user choose for each role (roleNeeded) any collaborator from (allCollaborators) and keep that assigns in List (assignments).
And I get error message:
ava.lang.IllegalStateException: Neither BindingResult nor plain target
object for bean name 'a' available as request attribute
So question is: how to solve it, assign values from one array to another in template and retrieve that values in my controller.
The cause of the exception
The IllegalStateException you are getting is because th:field="${a.id}" in your select element must be related to the form th:object="${project}" element; the th:field attribute must refer to an actual field in the project instance (also you need to write th:field="*{fieldName}"). That should fix the exception you are getting, but will not solve your entire problem as the second part of it is related to how to make the values get into your controller, which I will explain next.
Sending the values to your controller
To get the values into your controller you will need to make a few changes. As I don't really know the code of your Project class, I will change a few things so you will be able to figure it out how to adapt this simple example to your particular case.
First, I understand you want to make a relation like the following in your form:
Role1 => CollaboratorA
Role2 => CollaboratorB
Your controller needs to receive a list and in order to receive this information we need two classes:
The class which will be storing the individual element data, mapping a role id with the collaborator id:
public class RoleCollaborator {
private Long roleId;
private Long collaboratorId;
public Long getRoleId() {
return roleId;
}
public void setRoleId(Long roleId) {
this.roleId = roleId;
}
public Long getCollaboratorId() {
return collaboratorId;
}
public void setCollaboratorId(Long collaboratorId) {
this.collaboratorId = collaboratorId;
}
}
A wrapper class to store a list of individual mappings:
public class RolesCollaborators {
private List<RoleCollaborator> rolesCollaborators;
public List<RoleCollaborator> getRolesCollaborators() {
return rolesCollaborators;
}
public void setRolesCollaborators(List<RoleCollaborator> rolesCollaborators) {
this.rolesCollaborators = rolesCollaborators;
}
}
The next thing to do is change your controllers where you have two methods, one that handles GET requests and another one which handles the POST requests and so, receives your form data.
In the GET one:
public String projectCollaborators(#PathVariable Long projectId, Model model) {
(... your code ...)
model.addAttribute("project", project);
// Add the next line to add the "rolesCollaborators" instance
model.addAttribute("rolesCollaborators", new RolesCollaborators());
return "project_collaborators";
}
As you can see, we added a line that will be used by the thymeleaf template. Right now is a wrapper of an empty list of roles and collaborators, but you can add values if you need to edit existing mappings instead of adding new ones.
In the POST one:
// We changed the #ModelAttribute from Project to RolesCollaborators
public String projectCollaboratorsPost(#ModelAttribute RolesCollaborators rolesCollaborators, #PathVariable Long projectId, Model model) {
(... your code ...)
}
At this point, your controller is prepared to receive the information sent from your form, that we also need to modify.
<form th:action="#{'/project_collaborators/' + ${project.id}}" method="post" th:object="${rolesCollaborators}">
<label th:text="'Edit Collaborators: ' + ${project.name}">Edit Collaborators: Website Project</label>
<ul class="checkbox-list">
<li th:each="a, stat : ${assignments}">
<span th:text="${a.role.name}" class="primary">Developer</span>
<div class="custom-select">
<input type="hidden" th:id="rolesCollaborators[__${stat.index}__].roleId" th:name="rolesCollaborators[__${stat.index}__].roleId" th:value="${a.role.id}" />
<span class="dropdown-arrow"></span>
<select th:field="*{rolesCollaborators[__${stat.index}__].collaboratorId}">
<option th:each="collaborator : ${allCollaborators}" th:value="${collaborator.id}" th:text="${collaborator.name}">Michael Pemulis</option>
</select>
</div>
</li>
</ul>
<div class="actions">
<input type="submit" value="Save" class="button"/>
Cancel
</div>
</form>
Here there are a few changes:
As I pointed out in The cause of the exception you need to change th:object="${project}" to th:object="${rolesCollaborators}", as rolesCollaborator is the instance name from where you will receive the values from your GET controller method and where you will be sending the values to your POST controller method.
I added a hidden input; this input will store the role id that will be send in association to the collaborator id the user picks from the interface using the select element. Take a look at the syntax used.
I changed the th:field value of your select element to refer to a field in the rollesCollaborators object we use in th:object="${rolesCollaborators}" form attribute. This will set the value of the collaborator in the RoleCollaborator element of the RolesCollaborators wrapped list.
With these changes your code will work. Of course, you can improve it with some other modifications, but I tried to not introduce more modifications to focus on your problem.
I have a HashMap which looks pretty much like this..
class MyDTO
{
private Map<Long, StringListWrapper> myMap=new HashMap<>();
private List<Long> keys=new ArrayList<>();
private List<String> values=new ArrayList<>();
// setter and getter methods
}
class StringListWrapper
{
private List<String> st=new ArrayList<>();
// setter and getter methods
}
Now, for the map keys, I have a select which will contain the keys, and a list box which will be used for values.
<select th:field="*{myMap}">
<option th:each="key : *{keys} th:value="${key}" th:text="${key}"></option>
</select>
Here above, keys refer to the keys in MyDTO. I used it to show the keys in the <select>. However, this select must be mapped to the myMap to make sure that the option selected here acts as a key.
<select multiple="multiple">
<option th:each="value : *{values}" th:value="${value}" th:text="${value}"></option>
</select>
Now, also this above multiple select must be mapped to myMap so that the options selected here get into the StringListWrapper.st. Now, how and where to put the th:field attribute for multiple select above?
Thanks in advance. Hope you will reply as soon as possible.
There are a few things unclear about the question, but based on the code, I'm assuming that the myMap property is a Map because you will be providing multiple pairs of these select fields for uses to select the values for some number of keys.
If the assumption above is false, then why have myMap as a Map instead of two different properties/attributes of MyDTO?
Going with my assumption, you'll need the select pairs to be converted into a List or array in MyDTO and have a getter (getMyMap()) that creates a Map based of the list. The entry in the list above would be a simple value object with Long key and List<String> as its properties. Here is an working example of this use case. See how this is transformed by Thymeleaf and you might find a tweaked version that works with your solution.
Also, minor thing: IMHO, I don't believe it's appropriate to have the keys and values properties be within MyDTO, though it might just be simplified for this question only. They should be model attributes instead since they are not user inputs of the form. It technically works but doesn't strictly adhere to separation of concerns.
References/Credits: Dynamic Form Fields - http://www.thymeleaf.org/doc/thymeleafspring.html#dynamic-fields
Spring Controller:
package net.martian111.examples.spring.web;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
#Controller
#RequestMapping("/public/stackoverflow/q26181188")
public class StackoverflowQ26181188Controller {
public static class Entry {
private Long id;
private List<String> values;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public List<String> getValues() {
return values;
}
public void setValues(List<String> values) {
this.values = values;
}
}
public static class FormBackingBean {
List<Entry> entries;
public List<Entry> getEntries() {
return entries;
}
public void setEntries(List<Entry> entries) {
this.entries = entries;
}
public Map<Long, List<String>> getMyMap() {
Map<Long, List<String>> map = new HashMap<>();
for (Entry entry : entries) {
// StringListWrapper constructed from entry.getValues() here...
map.put(entry.getId(), entry.getValues());
}
return map;
}
#Override
public String toString() {
StringBuilder sb = new StringBuilder();
int i = 1;
for (Entry entry : entries) {
sb.append("Pair #" + i + ": ID=" + entry.getId() + ", Values="
+ entry.getValues() + "\n");
++i;
}
return sb.toString();
}
}
// Can be set within the #RequestMapping methods too (mv.addObject())
#ModelAttribute("keys")
public List<Long> getKeys() {
return Arrays.asList(null, 1L, 2L, 3L);
}
#ModelAttribute("values")
public List<String> getValues() {
return Arrays.asList(null, "abc", "def", "ghi");
}
#RequestMapping(method = RequestMethod.GET)
public ModelAndView get() {
ModelAndView mv = new ModelAndView("stackoverflow/q26181188");
// Blank Form Backing Bean
FormBackingBean fbb = new FormBackingBean();
fbb.setEntries(Arrays.asList(new Entry(), new Entry(), new Entry(),
new Entry(), new Entry()));
mv.addObject("fbb", fbb);
return mv;
}
#RequestMapping(method = RequestMethod.POST)
public ModelAndView post(FormBackingBean fbb) {
ModelAndView mv = new ModelAndView("stackoverflow/q26181188");
mv.addObject("fbb", fbb);
// Print Form Backing Bean
System.out.println("FBB: \n" + fbb);
// Redisplay submitted from
return mv;
}
}
Thymeleaf Template:
<div th:each="entry,entryStat : *{entries}">
Pair #<span th:text="${entryStat.count}">1</span>
<select th:field="*{entries[__${entryStat.index}__].id}">
<option th:each="key : ${keys}" th:value="${key}" th:text="${key}"></option>
</select>
<select multiple="multiple" th:field="*{entries[__${entryStat.index}__].values}">
<option th:each="value : ${values}" th:value="${value}" th:text="${value}"></option>
</select>
</div>
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</form>
</body>
</html>
EDIT: Additional details in response to the first comment
Both Map and List properties can be mapped to a collection of HTML form fields. Each Map.Entry or list element is mapped to a single HTML form field, with the name in the form propertyName[index], where index is the integer index of the element for the case of a List, or is the key value of the entry for the case of a Map. The solution above illustrates this for the List case.
To illustrate the Map case, say you want an HTML form to result in a myMap with the following contents:
123L : ["abc", "def"]
234L : ["abc", "ghi"]
Working backwards, the query string (before URL encoding) required for Spring MVC to create the Map above will need to look like: myMap[123]=abc&myMap[123]=def&myMap[234]=abc&myMap[234]=ghi. To get a browser to submit that query string, the HTML form will have to have two multi <select> form elements, one with name="myMap[123]" and the other with name="myMap[234]". However, the name of form elements cannot be set by another form field in standard HTML. In other words, there is no th:field value for the key <select> elements to do this (answering this Stackoverflow question).
With that said, an outside-the-box solution would be client side JavaScript scripting that gathers the necessary data from the form fields and create the required query string to submit the form. It would be a SO different question for a different audience, but I feel that would be an unnecessarily complex and specialized. Also, whereas the solution above works both to generate the HTML view from MyDTO and back to MyDTO from a form submission using the same HTML form, a JavaScript solution will require distinct specialized code for each direction.
I am new to JavaBeans and I need a little help to keep my first little JSF-project going.
I am writing a little web application where a user can search with certain criteria for buildings. So the user enters in the search form 'location', 'property type', 'asking price', 'number of rooms' and 'living space'.
My managed bean accept the requiry with setter/getter and now the data is to be transmitted to a SQL class, where they are processed and matching search results are returned. It sounds simple, but I can not find a solution.
My managed bean looks like this now:
package beans
//import statements
...
#ManagedBean
#RequestScoped
public class PropertySearchBean {
private String _place
private String _propertyType
private double _askingPrice
private int _rooms
private double _livingSpace
public ArrayList<SearchResults> results = new ArrayList<SearchResults>();
// empty constructor
...
// getter and setter for these 5 user inputs
...
public void initializeSearchResults() {
// do the SQL query, recieve search results
// add it as a new object of 'SearchResults'
SQLPropertySearch search = new SQLPropertySearch(_place, _propertyType,
_askingPrice, _rooms, _livingSpace);
ArrayList<Integer> idResults = search.getPropertyIDlist();
SQLProperty property;
if(!idResults.isEmpty()) {
for(int i=0; i<idResults.size(); i++) {
property = new SQLProperty(idResults.get(i));
results.add(new SearchResults(
property.getPropertyID(),
property.getPropertyName(),
// and so on..
));
}
}
}
public static class SearchResults {
int propertyID;
String propertyName;
// and so on..
public SearchResults(int propertyID, String propertyName) {
this.propertyID = propertyID;
this.propertyName = propertyName;
// and so on..
}
// getter and setter
public int getPropertyID() {
return propertyID;
}
public void setPropertyID(int propertyID) {
this.propertyID = propertyID;
}
// and so on..
}
public ArrayList<SearchResults> getResults() {
return results;
}
}
In my XHTML-file I go through each entry of my ArrayList results.
It looks like this:
<ui:repeat var="res" value="#{PropertySearchBean.results}">
<p>#{res.propertyID}</p>
<p>#{res.propertyName}</p>
</ui:repeat>
I don't have an idea how to initialize the ArrayList, because first thing to do is the search itself, with the user input.
I am thankful for any kind of help!
You've removed the getters and setters from your example to improve readability. I'll provide one implementation here to ensure a common understanding (especially regarding the leading underscores).
public String getPlace() {
return _place;
}
public void setPlace(String place) {
this._place = place;
}
The property 'place' will be accessible within your view by using the value binding #{propertySearchBean.place}(see below).
Your code is meant to perform a search. Therefore you'll have to transfer user input from your XHTML file (view) to your managed bean. To do so you need to add a form to your view. Each search query parameter is bound to your bean using a specific value binding. Additionally the form contains a <h:commandButton> tag which finally triggers initialization of the result list.
<h:form>
<h:outputLabel for="place" value="Place:" />
<h:inputText id="place" value="#{propertySearchBean.place}" />
<!-- Additional fields -->
<h:commandButton action="#{propertySearchBean.initializeSearchResults}"
value="Search"/>
</h:form>
Note: You've used the following code in your example
<ui:repeat var="res" value="#{PropertySearchBean.results}">
Make sure that the first letter of your bean name is lower-case (propertySearchBean instead of PropertySearchBean). So this needs to be updated to
<ui:repeat var="res" value="#{propertySearchBean.results}">
I'm sending this parameter to my struts action
cdata[1]=bar
In my action I'm interested in the index and the value.
I defined a getter/setter pair for CDATA as the OGNL documentation suggests:
public void setCdata(int index, String value){
LOG.info("setData; key="+ key +"; value="+ value);
// store index and value;
}
public String getCdata(int index){
return null; // don't really need a setter
}
This is the Exception I get:
2013-04-29 15:38:49,792 [http-apr-8080-exec-3] WARN com.opensymphony.xwork2.util.logging.commons.CommonsLogger.warn(CommonsLogger.java:60) - Error setting expression 'cdata[1]' with value '[Ljava.
lang.String;#4223d2a4'
ognl.OgnlException: target is null for setProperty(null, "1", [Ljava.lang.String;#4223d2a4)
at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2309)
at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.ASTChain.setValueBody(ASTChain.java:227)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.Ognl.setValue(Ognl.java:737)
...
If I define a public member variable String[] cdata = new String[1000] I don't see any exception in my log but my setter is not called either. If the member variable is private I get another exception again.
Use the following setup
List<String> cdata = new ArrayList<String>();
public List<String> getCdata() {
return cdata;
}
public void setCdata(final List<String> cdata) {
if (cdata == null) {
this.cdata = new ArrayList<String>();
} else {
this.cdata = cdata;
}
}
submit the values from JSP like cdata[1]=value etc
only requirement is to have the getters/setters. I've tested this Tomcat7 running on java 1.6. You can submit values like cdata[0], cdata[1] likewise
or else you could use a map
private Map<String, String> data = new HashMap<String, String>();
public Map<String, String> getData() {
return data;
}
public void setData(Map<String, String> data) {
this.data = data;
}
JSP can have
<s:form action="indexProperty">
<h3>Test The Map</h3>
<input type="text" name="data['0']"/>
<input type="text" name="data['1']"/>
<s:iterator value="data.entrySet()" var="aData">
<s:property value="#aData.key" />-<s:property value="#aData.value" />
</s:iterator>
<input type="submit" name="submit" value="submit"/>
</s:form>
Gets populated without a issue
My solution (rather an ugly hack):
I made my action class implement ServletRequestAware and in the action iterate over the parameter map from HttpServletRequest, fetch cdata from it and parse it for index and value
I had to change the sent parameter and encode eg cdata[999]=foobar like cdata_999_=foobar because if it looks like an array field struts requires there's a setter/getter for it in the action class.
According to the docs, OGNL provides support for indexing properties of JavaBeans: OGNL Reference Guide:
JavaBeans supports the concept of Indexed properties. Specifically this means that an object has a set of methods that follow the following pattern:
public PropertyType[] getPropertyName();
public void setPropertyName(PropertyType[] anArray);
public PropertyType getPropertyName(int index);
public void setPropertyName(int index, PropertyType value);
You didn't implement all of these methods. Also if you didn't initialize an array, the values could not be set.
You can read more about indexed properties here.
Indexed Properties
An indexed property is an array instead of a single value. In this case, the bean class provides a method for getting and setting the entire array. Here is an example for an int[] property called testGrades:
public int[] getTestGrades() {
return mTestGrades;
}
public void setTestGrades(int[] tg) {
mTestGrades = tg;
}
For indexed properties, the bean class also provides methods for getting and setting a specific element of the array.
public int getTestGrades(int index) {
return mTestGrades[index];
}
public void setTestGrades(int index, int grade) {
mTestGrades[index] = grade;
}