I am using Struts2.
<s:iterator value="empReportFields" var="empReportField"
<s:select name="%{#empReportField.fieldName}" list="%{#empReportField.listName}" listKey="id" listValue="name" cssClass="search" headerValue="All" headerKey="All" />
<s:property value="#empReportField.listName" />
// Here it is displaying proper list name
</s:iterator>
I am fetching out these data from my db. Now I am displaying specific list in select box (<s:select list="<ListName>" />) which is stored in column of my table (Database).
Normally it runs like.
<s:select name="emp" list="locationList"
listKey="id" listValue="name"
headerValue="All" headerKey="All" />
It will work well.
But I find simple select box with no list value in it. So what is the actual problem??
In short I want to call list dynamically.
The s:select tag itslef has a list attribute where you can directly give the name of the list (in action class) you want to fill the dropdown with. You do not need an iterator for packing values into s:select dropdown.
Try this:
<s:select label="Select from here"
headerKey="-1" headerValue="Select"
list="listNameHere"
name="feildNameHere" />
Here 'listNameHere' is the list in action layer and the 'feildNameHere' is a instance variable in action class which recieves the value selected by the user.
According to how I understand the question you want to load <s:select list dynamically according to the iterator value.
If so just use the <s:select list like this <s:select list="#empReportField.listName".
Where <s:iterator value="empReportFields" is a list and inside that list another list or map named listName.
Related
I have a variable that is obtain inside each block in thymeleaf. I want to send that variable to a certain method in my controller. The limitation is that the variable is obtain inside a block which makes it local, not accessible global.Hence I get an error while trying to use it. How can I move inside the scope to get the variable so as I can use it global in thymeleaf.
<form th:action="#{/masomo/somo(date=${dateMpya.date})}" method="POST">
<select id="date" name="date" required="true">
<option value="none" selected disabled hidden >
Select a Date
</option>
<th:block th:each="somoChagua : ${masomoChagua}">
<option th:each="dateMpya: ${somoChagua}" th:value="${dateMpya}" th:text="${dateMpya.date}" ></option>
</th:block>
</select>
<button type="submit"><i class="fa fa-search"></i> </button>
</form>
There can be many different "dateMpya" objects for each "somoChagua".
But there is only one submit button.
So which "dateMpya" should be used for the submit button value?
I think what you are actually trying to do here is get the value of the "dateMpya" which the user selected in the drop-down. Is that right?
If that's the case there is no need to add any attributes to the submit button. You would access that value by using the name of the select element, which is "date".
EDIT: For the same reason you also need to remove the (date=${dateMpya.date}) part of the form action as well. The value selected in the drop-down will automatically be submitted under the name of the select element "date", it does not need to be specified.
I have created a list of lists that contains content that I want to display through a jsp file. when trying to just display the items through one list, the file works and I see it. But when I split the items in different arraylists and try to iterate over that, nothing shows up. My initialization is,
private final List<ArrayList<DisplayableProduct>> listOfThreeProducts = new ArrayList<ArrayList<DisplayableProduct>>();
I have verified that there is content inside each list of it through debugging.
my model.listofThreePorducts is a list of lists. so I want to loop through the list of lists and then loop inside each loop and so stuff. Is it correct to pass the var="listoflists" value to the second for loop as such below? would it be items="${listoflists}" to access everything in that list ?
<c:forEach items="${model.listOfThreeProducts}" var="listoflists">
<div id="hero-featureSwap">
<c:forEach items="${listoflists}" var="product">
<div class="widget-element-brand"
title='<awsmp:formatText text="${product.vendorName}" />'>
<awsmp:formatText text="${product.vendorName}" maxLength="25" />
</div>
</c:forEach>
</div>
</c:forEach>
You need standard getter in model object for property listOfThreeProducts
further detail discussed in question's comment section
My application is shopping website application. In place order case, I need to pass the sum of every item's price as a one parameter. Prices are coming to the iterator correctly. But I failed to get the sum of those prices. shopping cart list is coming from Another action class.
I tried with this:
<s:iterator value="shoppingCarts" var="shoppingCarts">
<s:label name="total" value="%{#total+(item.salesPrice*qty)+item.shippingCost}" label="Total"/>
</s:iterator>
This shows two labels, if shopping cart list has two items. How can I get a total to a one parameter inside the iterator?
Define a context variable total like in this exampe
<s:set var="total" value="0">
<s:iterator value="shoppingCarts">
s:set var="total" value="%{#total+item.salesPrice*qty+item.shippingCost}"/>
</s:iterator>
<s:label name="total" value="%{#total}" label="Total"/>
I have list.add(int,String) in action class. I am getting this list in my jsp page as
<s:iterator value="list" var="emc" status="status">
<s:checkbox name="selectedCoverage" fieldValue="%{#emc.dataId}" />
<s:label value="%{#emc.PersonName}" />
</s:iterator>
Now I have three checkboxes, User did not selected any checkbox and hit submit which should throw validation errors. I have getters and setters for this check box in action class.
When I debug the code and see the value of selectedCoverage it is displaying me ognl.NoConversionPossibe instead of null. What is the issue and where am I going wrong?
I saw a sample code in this website to dynamically populate second dropdown men based on a selection of first dropdown. I have account number dropdown and based on the selection, I need to populate second dropdown with corresponding email-id.
code is here :Populating Child Dropdown (second option using java script).
But can someone let me know how to populate the values inthe second dropdown ?
<script>
var dd2options = ${dd2optionsAsJSObject};
var dd3options = ${dd3optionsAsJSObject};
function dd1change(dd1) {
// Fill dd2 options based on selected dd1 value.
var selected = dd1.options[dd1.selectedIndex].value; ... }
</script>
My code is as below- how to change the code to do this ?
<td>
1. Member Account Number
<span class="bodyCopy">
<font color="#ff0000"> * </font>
</span>:
<html:select
name="DataForm"
property="Member.accountNumber"
styleClass="formContent"
style="width:80px">
<html:options collection="<%= WorkConstants.RENewDropdowns.PACCT %>"
property="value"
labelProperty="label"
styleClass="formContent"/>
</html:select>
</td>
My second dropdown is as below:
<td>
3. Member <br>E-mail Address:<br />
<span class="bodyCopy"></span>
<html:select
name="DataForm"
property="Member.emailAddress.emailAddress"
style = "width:150px"
styleClass="formContent">
<html:options collection="<%= WorkConstants.RENewDropdowns.PEMAIL %>"
property="value"
labelProperty="label"
styleClass="formContent"/>
</html:select>
</td>
Appreciate your help on this as I'm new to java script.
Problem can be solved in following ways
Using onchange event of select element, on first box submit form and populate data in second select box.
Use ajax to fetch data in the same way instead of submitting form
Fetch all the main and related data, store them in arrays. Call them according to key. You can use JSON to solve