resultMap in mybatis , I need to pass a List of Strings as return type. How to do this in the mapper file - mybatis

<select id="getXXX" parameterType="java.util.List" resultMap="?">
</select>
In the above select query in my mapper file I need to get the resultMap as a List of Strings. How to implement as default Collection cannot be given directly.
I tried using a plain POJO class with a String variable or a List of String variable but it didnt work out.

If you need to get collection of Integers use the following for example:
<select id="getXXX" resultType="java.lang.Integer">
</select>
If you need to get collection of entities:
<select id="getXXX" resultType="com.domain.YourEntity">
</select>

Related

How do I use a select element's onchange event to pass an object instead of a string in AngularDart?

Here's what I'm trying to accomplish.
<select (ngModelChange)="addChild($event)">
<option>Add</option>
<option [value]="null">New Item</option>
<option *ngFor="let child of menuItem.children" [value]="child">
{{child.title}}
</option>
</select>
While it compiles, the addChild method is not called. VSCode is reporting that "The bound output ngModelChange does not exist on any directive or on the element" - so what directive do I need to add?
Try changing your first line to:
<select (change)="addChild($event)">
That should do the job.
You may also find convenient to print strings instead of full objects where it is expected:
<option *ngFor="let child of menuItem.children" [value]="child.id">
and maybe (or maybe not):
<select (ngModelChange)="addChild(child.id)">
if it works better for you and you have a suitable property, of course. YMMV.
AngularDart's SelectElement only supports Strings for values. If you want to pass arbitrary objects, you will need to use a different component - one that supports such functionality.

JSP Dropdown from postgresql

I'm very very new to jsp and postgresql and I want to add a dropdown menu to my jsp file.
There is table with Names and Numbers and all I want is getting the names displayed in the drop down
This is what I got so far. An empty dropdown with the right numbers of rows (4 as I have only for rows in my table) is displayed but no names!
<sql:query
dataSource="${db}"
var="result">
select name from customer
</sql:query>
<select>
<c:forEach
var="result"
items="${result.rows}">
<option value=${param.name}>${param.name}
</option>
</c:forEach>
</select>
Thanks for any help in advance!
PS: i tried to find an answer but all the answers were about mysql but we are using psql :/
Your option list has the right number or options but they're empty because the variable param doesn't exist.
You have:
<c:forEach var="result" items="${result.rows}">
<option value=${param.name}>${param.name}</option>
</c:forEach>
var is the variable to be created from items, so you don't want it named the same as the items list. This is where you should be creating the variable param. It should be:
<c:forEach var="param" items="${result.rows}">
<option value='<c:out value="${param.name}"/>'><c:out value="${param.name}"/></option>
</c:forEach>
You should probably also do it like <option value='${param.name}'> since the field name is probably text rather than numeric.

preselect select field with freemarker

In my struts2 action that prepares the ftl page i have
private static List<Product> listOfProducts;
with getter and setters. This list is filled with products. First product in the list has type B.
In ftl page I am iterating over the list of products
<#list listOfProducts as product>
<select name = product[0].type>
<option value="A">fistType</option>
<option value="B">secondType</option>
<option value="C">thirdType</option>
</select>
</#list>
Problem is that firstType is preselected each time even if in the list i have a product with type B.
Can you tell me what am i missing here? Why option B was not selected when the ftl is loaded?
Thanks
See http://www.w3schools.com/tags/tag_select.asp on the correct syntax for a select
The attribute "name" sets the name of the control - it does not influence the selection
See How can I set the default value for an HTML <select> element?
on how to do that
Use Struts select tag.
<#s.select theme="simple" name="selectedProduct" list="listOfProducts" listKey="productId" listValue="productName" value="defaultProduct"/>
Please go through the example in below link for more understanding.
http://www.mkyong.com/struts2/struts-2-sselect-drop-down-box-example/

Spring MVC 3 - custom labels in <form:select>

I'm creating a form in which user will be able to choose (among the others) the factory of a product.
Each factory is identified by and ID and has specific address.
I want to use custom label in following code:
<form:select items="${factories}" path="factory" itemValue="id" itemLabel="..."/>
At first i tried using Spring Formatter functionality (org.springframework.format.Formatter interface), but when I did this, and when I removed "itemLabel" attribute to have it displayed automatically via Formatter):
<form:select items="${factories}" path="factory" itemValue="id"/>
But then It wasn't selecting proper value if it was set (in case of editing).
Then I tried to:
<form:select path="factory" itemValue="id">
<c:forEach ...>
<form:option value="${factory.id}" label="${factory.address.city} ${factory.address.street}"
</c:foreach>
</form:select>
But as in earlier solution spring was not selecting proper value that was set in model.
My question is:
Is it possible to format entity in a way, that form:select works properly, when a value of select field is not the same as its label.
I had the same problem, the trouble is the form:option value and label maps directly to a property rather than having the flexibility to specify jstl.
So you have to hand crank the html, to something like:
<select name="factory">
<c:forEach var="factory" items="${factories}" >
<option value="${factory.id}" label="${factory.address.city} ${factory.address.street}"/>
</c:forEach>
</select>
Spring will pick up the 'path' based on the name attribute('factory' in this case), as it will try and map to the model object you are using automatically.
Another way is to add another field to the model to concatenate and format label as you wish. And if its an #Entity object then make the field #Transient.
You can also override toString() method in Factory class
#Override
public String toString() {
return "desired string";
}
Then in your jsp
<form:select items="${factories}" itemValue="id" path="factory"/>

ASP.NET MVC 2: What Model property datatype will autobind an html select (DDL) with multiple selections?

The customer has a Model property that requires a comma separated list of selected options. We present their select list (DDL) as a multi-choice drop down.
What would the property datatype look like that would autobind multi-selections in the client side HTML select (DDL)?
The select posts data like this:
myOptions=Volvo&myOptions=Mercedes&myOptions=Audi
And we want to automagically bind it back to some property:
IList<string> CarChoices {get;set;}
So the POST action method parameter would be (Carform myForm)
which would have myForm.CarChoices which includes a List of the three selected cars?
I might be misunderstanding what you're trying to accomplish but I think this post from Phil Haack describes how to do what you're attempting to do in a clean way: http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx
Sometimes it is just easier to get your hands dirty and work with the HTML. I suggest doing something like this:
<select multiple>
<% foreach(var item in Model){ %>
<option value="<%= item.ID %>"><%= item.Description %></option>
<% } %>
</select>
obviously your model is your collection. You can also use the ViewData["Whatever"] object to pass data as well, your choice.