"other" option in dropdown menu and setting values - java

I have a combobox with an option "other". user can select an entry from the list or select option "other". if they select "other" a text box will disply below to enter a new account number. see the code below:
<td>1. Account Number<span class="bodyCopy"><font color="#ff0000"> * </font></span>:
<html:select name="reDataForm" property="Member.accountNumber" styleClass="formContent"
style="width:80px" onchange="showfield(this.options[this.selectedIndex].value)">
<html:options collection="<%= WorkConstants.NewDropdowns.PACCT %>" property="value" labelProperty="label" styleClass="formContent"/>
</html:select>
<div id="div1"></div>
It works fine. But when the page refreshes, the text box disappears as no code to keep it there.
1)how do I keep the text box if the use was selected "Other" and entered a new account number in the text box ? OR if we can add the text box value into the dropdown list, that will also work.
2) Also how to set the text box value into the same variable Member.accountNumber ?
please help me !!!!

Use a little bit of javascript on an onLoad event to check if other is selected, and display the text box
You can't submit the value as the same name as the select box. instead, submit as a second name and process accordingly in your ActionForm on the serverside.

Related

How to Fetch data by clicking image

I have the following code in edit.jsp
<%
while (rs.next())
{
%>
<tr>
<TD><%=rs.getString(1)%></TD> //for text box name
<TD><%=rs.getString(2)%></TD> //for text box address
<TD><%=rs.getString(3)%></TD> //for text box origin
<td> <img src="images/editdetail.png"></td>
</tr>
while clicking the image/editdetail.png i am redirecting the page to create.jsp, where i have three text boxes("name", "address" and "origin").
how to get the getString value also getting displayed in the text box when i click the png image, so that i can edit the details.
You could pass this as params as TJ mentioned. But if you think its kinda insecure, because the details are present in the URL, you could save the details as an object in the session. using session.setAttribute().
In the create.jsp, read the object against the key and populate the text boxes accordingly.
A usecase similar to your's is illustrated in this example : http://www.jsptut.com/sessions.jsp
I believe, the create.jsp will submit the detials to another JSP. say... submit_details.jsp
in submit_details.jsp, after processing the details, do remember to remove the attribute from the session.

How to reset a select dropdown using springform:options and save null value

I have the following dropdown box created for the user to select a specific year:
<springform:select id="firstYear" path="member.attributes[firstYear].value" value=" " tabindex="3">
<option disabled="disabled" value=" " selected="selected">Select year:</option>
<springform:options id="years" items="${years}"/>
</springform:select>
However, I want to set so that if a user checks a particular checkbox, this dropdown is cleared and a blank value is saved to the DB. Currently it is saving the first value in the array that is ${years} which is not desirable. Here is the javascript I have tried using to clear it:
$("#firstYear option:selected").prop("selected", false);
$("#firstYear").selectedIndex=-1;
I have also tried setting the value of firstYear to " " but this didn't work either.
Any help would be very much appreciated!
You can set the value to the dropdown, so when a time to save it to database it will take that value.
$("#firstYear").val("");
It will set an empty value to the dropdown. Also note, that empty values are treated some databases as NULL. Blank values contains at least one blank symbol and it's not empty string.

How to keep selected dropdown box value in next page dropdown

My html page is divided in two and contains sidebar and content, in sidebar I have two dropdown boxes, one for school year and another for student name in respective school year selected in 1st dropdown and next is submit button. When I click on submit button it will redirect to next page and next page also looks same but in content page it shows selected student profile, in side bar the same two dropdowns will be there. The problem I am facing here is, first I will select school year and name. Its fine, when it goes to next page the dropdowns will be at initial stage but I want the selected year and name to be displayed on dropdown box, how can I do this?
Some one suggested me to keep the values selected in session after it goes to next page set the value of the dropdown.
Here is my code for dropdown,
<select style='width: 200px;'
id="combo_zone11" name="alfa1">
<c:forEach var="grade" items="${gradeInfo}">
<option id='syear' value="" selected="selected">
<option value=${grade.getDropDownId()}>${grade.getDropDownName()}</option>
</c:forEach>
</select>
How can I keep selected value in next page dropdown. please help me in this.
You could do this in many ways.
Since you're working in java, you can set the selected values to a hidden field, and while redirecting to next page you can set the values to request object.
Or if the target browsers support HTML5 localStorage, you can make use of it - on dropdown change, save the selected option to local storage using javascript. in the second pages load event, get the values from local storage and set the drop downs respectively.
Something like -
//Script in page1
window.onload = function(){
var dd = document.getElementById('combo_zone11');
dd.addEventListener('change',function(){
localStorage.setItem('ddValue', this.value)
});
}
//Script in page2
window.onload = function(){
var ddValue= localStorage.getItem('ddValue');
var dd= document.getElementById('combo_zone11');
for(var i = 0;i < dd.options.length;i++){
if(dd.options[i].value == ddValue ){
dd.options[i].selected = true;
break;
}
}
}
You can also make use of cookies, sessionStorage, queryStrings etc each method has it's own advantages and disadvantages...
Use select=selected by passing the id
like
<option value="${GroupLi.partyClassificationTypeId if_exists}" selected="selected"> ${GroupLi.description?if_exists}</option>
GroupLi is the list name used to iterate
as:
<#list Group as GroupLi>

jsf primefaces, show itemLabel not itemvalue on update

I have 2 items:
radiobuttons
outputtext
What I'm trying to do is: When the user checks a radiobutton -> get the itemLabel of the checked radiobutton in my outputtext. (not itemValue)
I have following code which shows the itemValue in the output text:
<h:form>
<p:selectOneRadio layout="pageDirection" id="test" name="testy" value="#{myBean.testValue}">
<p:ajax update="testOutput"/>
<p:selectItems value="#{myBean.getAllTestItems()}" var="selecter" itemLabel="#{selecter.label}" itemValue="#{selecter.val}"/>
</p:selectOneRadio>
<h:outputText id="testOutput" value="#{myBean.testValue}"/>
</h:form>
When i select one of the radiobuttons, I get the itemValue in the outputText. However I would like to get the itemLabel of the selected item in the outputText.
How do I get the label instead of the value of the radiobutton?
Several ways.
Get it based on the collection behind #{myBean.getAllTestItems()} which already contains the items with both the label and the value. Find the item matching the selected value in there and then get the label.
Submit #{selecter} instead of #{selecter.val} as radio button item value. This way you can display the label by #{myBean.testValue.label}. You only need to provide a Converter to convert between String (in HTML and HTTP request parameter) and Selecter (in Java model).
See also:
Our selectOneMenu wiki page
How to create Primefaces radioButtons from List? (for the case you'd like to use Selecter as value)

Display the Hindi encoded values in my select box

I am working on struts framework in java and I have a jsp which has a select box. Onchange of this select box I am displaying some values in a second select box. The first select box is displaying the Hindi characters properly. I select some value and the onchange function is called and it goes to ajax and gets the values in second select box. THe second select box is displaying question marks.The follwing is the jsp code
District(ज़िला)
Municipality(नगर)
<html:select property="municipalitycode" bundle="utf-8"
styleId="mun_List" style="width:180px;"
onchange="getzones('myajax.do?action=getzones',this);getsections('myajax.do?action=getsections',this);">
<html:option value="">Select</html:option>
<html:optionsCollection property="municipalities" />
</html:select>
</tr>
Onchange of district, I get muncipalities.
Please help?
Character encoding can be quite tricky, make sure you haven't missed out on anything.
Refer the link below:
http://balusc.blogspot.com/2009/05/unicode-how-to-get-characters-right.html

Categories

Resources