I'll try to put an image in my checkboxlist like this
<s:checkbox name="evento.eve_tarjeta_cred1" id="chkAmex" />
<img alt="10" src="./images/tarjetasCredito/amex.png">
<s:checkbox name="evento.eve_tarjeta_cred2" id="chkCmr" />
<img alt="10" src="./images/tarjetasCredito/cmr.png">
But i need to pass a list in one field to save it in my DB like
"true,false".
I'll try in this way
<s:checkboxlist id="chkTarjeta" name="evento.eve_tarjeta_cred"
list="{
'<img alt="10" src="./images/tarjetasCredito/amex.png">',
'<img alt="10" src="./images/tarjetasCredito/cmr.png">'
}"
/>
but it doesn't work. HELP
The error is probably in the <img/> tags declaration: when you open the first double quote, you are closing the list attribute.
Put them in the Action (and read the values with a getter from the list attribute), or try escaping them manually;
<s:checkboxlist id="chkTarjeta" name="evento.eve_tarjeta_cred"
list="{
'<img alt="10" src="./images/tarjetasCredito/amex.png">',
'<img alt="10" src="./images/tarjetasCredito/cmr.png">'
}"
/>
I'm not sure if Struts2 will escape the values or not; if it will, the only chance would be to extend the Tag.
To submit values in one string line use the same names on both checkboxes and your evento.eve_tarjeta_cred variable must be a String.
Use <label> tags to create labels of image for checkboxes.
Note: that unchecked chekboxes (false values) won't be submitted.
<label>
<s:checkbox name="evento.eve_tarjeta_cred" id="chkAmex" />
<img alt="10" src="./images/tarjetasCredito/amex.png" />
</label>
<label>
<s:checkbox name="evento.eve_tarjeta_cred" id="chkCmr" />
<img alt="10" src="./images/tarjetasCredito/cmr.png" />
</label>
I solved it like this, in my JSP i got this
<s:checkbox name="t1" id="chkAmex" />
<img alt="10" src="./images/tarjetasCredito/amex.png">
<s:checkbox name="t2" id="chkCmr" />
<img alt="10" src="./images/tarjetasCredito/cmr.png">
and in my Action i declare a global variable "tarjetas", with get and set, obviously
tarjetas = t1 + "," + t2;
evento.setEve_tarjeta_cred(tarjetas);
eventoservice.RegistraEvento(evento);
and to show it in Update case, just do this
String[] tarjetasArray = evento.getEve_tarjeta_cred().split(",");
for (int i = 0; i < tarjetasArray.length; i++) {
t1 = tarjetasArray[0];
t2 = tarjetasArray[1];
}
Related
I am able to display a table when a user clicks a search button. But now I want to split the table into chunks of 20 rows where the user can click next or previous to go forward and backward through all of the data. I am not allowed to use JavaScript for this assignment. Only JSP, Java, HTML.
The two debugging out.print() calls are not showing up. A different page is being loaded after one of the buttons is clicked, but the two debugging out.print calls are not displaying any HTML. I have checked out How to know which button is clicked on jsp this post but had no luck.
<form method="GET">
<center>
<input type="submit" name="previous_table" value="Previous" />
<input type="submit" name="next_table" value="Next" />
</center>
</form>
</br>
<%
String val1 = request.getParameter("previous_table");
String val2 = request.getParameter("next_table");
try {
if ("Previous".equals(val1)) { // Get previous results
out.println("<h1>HELLO 1</h1>");
buildTable(rs, out, false);
}
else if ("Next".equals(val2)) { // Get next results
out.println("<h1>HELLO 2</h1>");
buildTable(rs, out, true);
}
} catch(Exception e) {
out.print("<center><h1>"+e.toString()+"</h1></center>");
}
%>
I also have a follow up question. If the user clicks next or previous button, will my current table on the page be overwritten by the new one? That is my intent but I don't know if it will work that way.
I WAS ABLE TO FIX IT BY DOING THIS:
<form method="POST">
<center>
<input type="submit" name="previous_table" value="Previous" />
<input type="submit" name="next_table" value="Next" />
</center>
</form>
</br>
<%
String val1 = request.getParameter("previous_table");
String val2 = request.getParameter("next_table");
you should add name with value for button after that you can get by parameter click value.
`<input type="hidden" name="myprevious" value="previous"/>
<input type="hidden" name="mynext" value="next" />
<%
String val1 = request.getParameter("myprevious");
String val2 = request.getParameter("mynext");
try {
if (val1 == "previous") { // Get previous results
out.println("<h1>HELLO 1</h1>");
buildTable(rs, out, false);
}
else if (val2 == "next") { // Go next results
out.println("<h1>HELLO 2</h1>");
buildTable(rs, out, true);
}
} catch(Exception e) {
out.print("<center><h1>"+e.toString()+"</h1></center>");
}
%>
`
I hope it will help you.
Thanks.
Try to use the subList() method of a List<>().
As explained here.
HOW TO IMPLEMENT IT ##
you can put an hidden input in your form to give you the last index for your list like :
<input type="hiden" value="${last_index_of_your_list + 1}" name="index">
Then in your servlet part you put like this :
int index = Interger.ParseInt(request.getParameter("index"));
if(index <= 0){
datalist = datalist(0, 19>datalist.size()? datalist.size() : 19);
}else{
if(clicked_on_next){
datalist = datalist(index, index+19>datalist.size()? datalist.size() : index+19 );
}else{
datalist = datalist(index - 40, index-20>datalist.size()? datalist.size() : index-20 );
}
}
You are using hidden fields but you need to use submit button for next and previous.
<input type="submit" name="myprevious" value="previous"/>
<input type="submit" name="mynext" value="next" />
Make sure both are define in form. when we submit form after that you will get button value in parameter.same my previous answer. because we can not get parameter value without submit form.
Thanks.
Here I am creating dynamic table inside jQuery by using AJAX call. In this table I am creating select box. But I have to provide the dynamic values to that select box, so I am using the id of that select box and appending the data inside it.
But I am not able to solve the issue.
Qualification.js
function switchOption() {
var selectedValue= $("#companyClass").val();
$.ajax({
type: "GET",
url: "getClass",
data:'classId='+selectedValue,
success: function(data){
var tablebody = $('<tbody>');
var tablerow = "";
$(data.qualAttributes).each(function(index){
tablerow = $('<tr>')
.append($('<td>').append($('<input>').attr({type :'checkbox'}).attr('class','checkBoxSize').attr({value : ''+$(this)[0].qualId}).attr('id','attributeList').attr('name','attributeList')))
.append($('<td>').append($(this)[0].qualAttrName+''))
.append($('<td>').append($('<select>').attr('class','form-control').attr('id','operatorList').attr('name','operatorList')))
.append($('<td>').append($('<input>').attr({type :'text'}).attr('class','form-control').attr('id','attributeValue').attr('name','attributeValue')))
.append($('<td>').append($('<input>').attr({type :'hidden'}).attr('class','form-control').attr('id','attributeValueHidden').attr('name','attributeValueHidden').attr('value',$(this)[0].qualId)))
$(tablebody).append(tablerow);
});
$(data.operatorList).each(function(i,value){
$('#operatorList1').append($('<option>',
{
value: value.dropdownId,
text : value.dropdownValue,
}));
});
Portion of Qualification.jsp
<div class="form-group">
<label class="label-bg col-xs-12">Class <span class="red">*</span></label>
<div class="col-xs-12">
<form:select id="companyClass" class="form-control" path="companyClass" onchange="switchOption();">
<form:option value="Select" />
<form:options items="${classList}" itemValue="id" itemLabel="dropdownValue"/>
</form:select>
</div>
</div>
Note: there are no errors in the log. If I print value.dropdownId in console it is giving correct value.
Is it possible that while defining select in jQuery, can I append the values by using like this?
$(data.operatorList).each(function(i,value){
$('#operatorList1').append($('<option>',
{
value: value.dropdownId,
text : value.dropdownValue,
}));
});
In my jsp i have a variable
String str = "Get_Name";
What can i do to have my variable(str) directly accessed in the input type shown below? By this I want to see the form auto filled with the the variable I have instead of me filling it.
<input id="vendorName" name="vendorName" type="text" class="txtsmall2" />
ANSWER ALSO CONTAINS SOLUTION FOR PROBLEM DISCUSSED IN COMMENTS.
Do this.
<%
long val = 2; //can be anything.
if(val > 1) {
%>
<input id="vendorName" name="vendorName" type="text" class="txtsmall2" value="<%=str%>"/>
<%
else {
%>
<input id="vendorName" name="vendorName" type="text" class="txtsmall2" />
<%
}
%>
<%=str%> is called as expression tag.
I have this iterator that loops through an object.
<s:iterator value = "choices" status = "key">
<s:set var = "test" value ="%{#key.index}"/>
<input type = "radio" name="choices[{key.index}].answer" />
<s:textfield name = "choices[%{#key.index}].value" value = "%{choices[%{#key.index}].value}"/>
<br>
</s:iterator>
where answer is a boolean value, that I am trying to set through radio buttons.
but the problem is, upon on the generated html, teh radio buttons. is like this
<input type = "radio" name="choices[%{#key.index}].answer" />
It did not have the indice/index. it only gave me the %{#key.index}
you have to use property tag to get the actual value
<input type = "radio" name="<s:property value='%{choices[#key.index].answer}' />" />
Better use radio tag of struts tag library, like this
<s:radio name="choices[%{#key.index}].answer" / >
My jsp page display a list using logic iterate. every row displayed has a edit link too. when edit linked clicked Name will be changed to textbox so it can be edited.and sent along with commit link. html:text value i need to send with html:link.
part of my jsp is below,where I have
html:text property="newId" value="<%=modId%>"/> I want to pass this property as hashmap with html link as I am sending "/> as param1 Please help. or suggest any other way to do this. Thanks .
####################################################################################
<logic:equal name="mode" value ="1">
<td><bean:write name="display" property="productId"/></td>
<logic:notEqual name="edit" value="1">
<td><bean:write name="display" property="productName" /></td>
</logic:notEqual>
<logic:equal name="edit" value ="1">
<logic:equal name="display" property="productName" value ="<%=modId%>">
<td><html:text property="newId" value="<%=modId%>"/></td>
</logic:equal>
<logic:notEqual name="display" property="productName" value ="<%=modId%>">
<td><bean:write name="display" property="productName" /></td>
</logic:notEqual>
</logic:equal>
<bean:define id="param1" name="display" property="productName"/>
<%
String changedName=request.getParameter("changedName");
System.out.println(" st: " + changedName);
java.util.HashMap params = new java.util.HashMap();
if(param1!=null)
params.put("objectToEdit", param1);
params.put("abc",param1);
pageContext.setAttribute("paramsName", params);
%>
</logic:equal>
#####################################################################################
Same JSP HTML:LINK PArt
#######################################
<html:link action="Manager?edit=1" name="paramsName" onclick="return modify()">
<logic:equal name="edit" value ="1">
<logic:equal name="display" property="productName" value ="<%=modId%>">
<img src="../images/commit.png" border="0" style="background-color:blue" title=" bean:message key="commit.data"/>" >
</logic:equal>
</logic:equal>
</html:link>
Well I did it using java script.
hope my solution help someone
function modify(){
var textBox = document.getElementById('editableTextBox');//text box name
var newName = document.getElementById('editableTextBox').value;
if(textBox!=null){
var table = document.getElementsByTagName("table");
var rows = table[3].rows;
var rowCount=0;
for(i=1;i<rows.length;i++){
rowCount = i;
var cells = rows[i].cells;
if(cells[1].hasChildNodes()){
var nodeName = cells[1].childNodes[0].nodeName;
if(nodeName=="INPUT"){
break;
}
}
}
var reqCell =rows[rowCount].cells[cells.length-2];
var oldLink = reqCell.childNodes[1].getAttribute("href"); //getOld link
reqCell.childNodes[1].setAttribute("href",oldLink+"&newName="+newName) //set href with appending text box value
}
}