When I click on the "delete row" button, it calls my jquery function, but it does not delete my row. (please see my below code). I think I am unable to get the row_id with my custom button. That is why I am unable to delete. I do not know what is the solution for this.
main code:
<script type="text/javascript">
$.subscribe('rowdelete', function(event,data) {
alert("function is calling on the delte button click");
$("#gridtable").jqGrid('delGridRow',"row_id_s", {height:200,reloadAfterSubmit:true});
});
</script>
<br/>
<sj:submit id="grid_edit_addbutton" value="Add Row" onClickTopics="rowadd" button="true"/>
<sj:submit id="del_gridtable" value="delete Row" onClickTopics="rowdelete" button="true"/>
Full code:
<sjg:grid
id="gridtable"
caption="List of Subject Details"
dataType="json"
href="%{remoteurl}"
pager="true"
gridModel="gridModel"
onClickGroupTopics="rowadd,rowdelete">
<sjg:gridColumn name="id" index="subjectId" title="ID" formatter="integer" sortable="true" key="true" search="false" editable="true" hidden="true" />
<sjg:gridColumn name="subjectName" index="subjectName" title="Subject Name" sortable="true" search="true" editable="true" edittype="text" />
</sjg:grid>
<script type="text/javascript">
$.subscribe('rowdelete', function(event,data) {
alert("function is calling on the delte button click");
$("#gridtable").jqGrid('delGridRow',"row_id_s",{height:200,reloadAfterSubmit:true});
});
</script>
<br/>
<sj:submit id="grid_edit_addbutton" value="Add Row" onClickTopics="rowadd" button="true"/>
<sj:submit id="del_gridtable" value="delete Row" onClickTopics="rowdelete" button="true"/>
You can put the id in a PROPERTY tag and when you click at the button refresh the datagrid ( by execution the action for ex or refreshing the div that contains it )
Related
I have a code that adds or removes fields when clicked, but when i bound it in a c:foreach tag, it shows unexpected behaviour, as instead of showing a remove field it shows an add field with textfield when i load the data from backend?
<script>
$(document).ready(function() {
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 1; //initlal text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++; //text box increment
$(wrapper).append('<div><input type="text" name="parameter_value" size="50" style="width: 50%;; margin-left: 3%;" class="headers " value="${workflow.parameter_value}" /> Remove</div>'); //add input box
}
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); x--;
});
});
</script>
<table>
<tr>
<td class="tbody_color">
<div class="input_fields_wrap">
<c:if test="${not empty workflow.workflowParametersList}">
<c:forEach var="paramValue" items="${workflow.workflowParametersList}">
<input type="text" name="parameter_value" size="50" style="width: 50%;; margin-left: 13%;" class="headers" value="${paramValue.param_value}"></input>
<button class="add_field_button bttn">Add Parameters</button>
</c:forEach>
</c:if>
<c:if test="${empty workflow.workflowParametersList}">
<input type="text" name="parameter_value" size="50" style="width: 50%;; margin-left: 13%;" class="headers" value=""></input>
<button class="add_field_button bttn">Add Parameters</button>
</c:if>
</div>
</td>
</tr>
</table>
You have Add Parameters button insted of Remove in your c:forEach tag which displays backend data.
Change this to:
<c:if test="${not empty workflow.workflowParametersList}">
<c:forEach var="paramValue" items="${not empty workflow.workflowParametersList}">
<div>
<input type="text" name="parameter_value" size="50" style="width: 50%;; margin-left: 13%;" class="headers" value="${paramValue}"></input>
Remove
</div>
</c:forEach>
</c:if>
I'm working in a Java EE aplication thats uses JSF2 and Richfaces 4. We decided that some interactions would be made using modal windows, and we chose Jquery UI Dialog with h:form, because we were already using Jquery UI in this project.
The Dialog is opened correctly, and submits the form, the submit is made using a h:commandButton and a4j:ajax. The h:commandButton stays hidden, and it is triggered by a dialog button.
Everything looks like perfect, but the dialog/forms just works once. If I close and open the dialog without refreshing the page I receive the message when submit the form:
javax.faces.application.ViewExpiredException:
viewId:/frontend/inicial.xhtml - /frontend/inicial.xhtml could not be restored
The JSF/HTML of dialog:
<h:panelGroup id="dialog-nova-intercorrencia" styleClass="ui-dialog-content ui-widget-content">
<h:form id="frm-dialog-nova-intercor" prependId="false">
<table>
<tr>
<td>Paciente</td>
<td>
<h:selectOneMenu id="sel-intern-intercor" value="#{intercorrenciaController.novaIntercorrencia.internacao.internacaoID}" styleClass="ui-widget-content ui-corner-all">
<f:selectItems value="#{internacaoController.listInternacoesSelectItem}" />
</h:selectOneMenu>
</td>
</tr>
<tr>
<td>Impacto</td>
<td>
<h:selectOneMenu id="sel-impacto" value="#{intercorrenciaController.novaIntercorrencia.impacto.impactoID}" styleClass="ui-widget-content ui-corner-all">
<f:selectItems value="#{intercorrenciaController.listaImpactosSelectItem}" />
</h:selectOneMenu>
</td>
</tr>
<tr>
<td>
Data e Hora
</td>
<td>
<h:inputText value="#{intercorrenciaController.dataIntercorrencia}" styleClass="ui-widget-content ui-corner-all" style="width: 130px" />
<h:inputText value="#{intercorrenciaController.horaIntercorrencia}" styleClass="ui-widget-content ui-corner-all" style="width: 70px" />
</td>
</tr>
<tr>
<td>Resumo</td>
<td><h:inputText value="#{intercorrenciaController.novaIntercorrencia.resumo}" size="25" styleClass="ui-widget-content ui-corner-all" /></td>
</tr>
<tr>
<td colspan="2">
Comentarios
<br />
<h:inputTextarea cols="30" rows="3" value="#{intercorrenciaController.novaIntercorrencia.descricao}" />
</td>
</tr>
</table>
<h:commandButton id="btt-add-nova-intercor" action="#{intercorrenciaController.cadastrarIntercorrencia}" style="display:none">
<a4j:ajax execute="#form" render="#form frm-dialog-nova-intercor panel-lista-intercorrencias" />
</h:commandButton>
</h:form>
</h:panelGroup>
The JS to create jQuery UI Dialog:
$("#dialog-nova-intercorrencia").dialog({
position: {
my: "top top",
at: "top top",
of: window
},
autoOpen: false,
height: 350,
width: 400,
draggable: false,
resizable: false,
modal: true,
buttons: {
"Cadastrar": function() {
$("#btt-add-nova-intercor").trigger("click");
},
"Cancelar": function() {
$( this ).dialog( "close" );
$(this).find("input").val("");
$(this).find("textarea").val("");
$(this).find("select").val(0);
}
},
close: function() {
$(this).find("input").val("");
$(this).find("textarea").val("");
$(this).find("select").val(0);
}
});
Does anyone knows the reason I can execute the form in dialong only once and in the second time I get the message "view could not be restored" ?
The problem was the JS that I was using to clear the fields before close the dialog:
$(this).find("input").val("");
It was setting the input hidden javax.faces.ViewState in the form with null.
<input type="hidden" name="javax.faces.ViewState" value="" />
I've run into and issue with IE not allowing me to hit the enter key to submit a form. I found a partial solution (http://www.thefutureoftheweb.com/blog/submit-a-form-in-ie-with-enter) but my dialog window closes. My validations are run and the error messages are displayed. How would I keep my dialog open?
<p:dialog id="sgupdlg" header="#{bundle['signUp.HEADER']}" widgetVar="signUpDlg"
modal="true" styleClass="dialog dialog1" draggable="false"
resizable="false" showEffect="fade" hideEffect="fade" position="top">
<h:form id="signUpFrm" binding="#{signUpDetail.signUpFrm}">
<p:growl id="growl" showDetail="true" showSummary="false" life="3000" errorIcon="/images/Validation-Error.png" infoIcon="/images/Validation-Success.png"/>
<p:inputText value="#{signUpDetailBean.firstName}" name="nameInput" required="true" requiredMessage="First Name is Required"/>
<p:inputText value="#{signUpDetailBean.lastName}" required="true" requiredMessage="Last Name is Required"/>
<p:commandButton styleClass="form-btn2"
value="#{bundle['signUp.button.LABEL']}" actionListener="#{signUpDetail.signUp}" onclick="trackingSignUpOverlaySave()"
oncomplete="handleSignUpRequest(xhr, status, args)" update="growl"/>
<p:commandButton type="reset" styleClass="close" />
</h:form>
</p:dialog>
<script type="text/javascript">
$ = jQuery
$(function(){
$('input').keydown(function(e){
if (e.keyCode == 13) {
$('#signUpFrm').submit();
return false;
}
});
});
</script>
function closeWhenValidationSuccesful(dialog, xhr, status, args) {
if (!args.validationFailed) {
dialog.hide();
}
}
<p:commandButton value="Save" action="doSomething" update=":formName:panelContainingValidatedElements"
oncomplete="closeWhenValidationSuccesful(dialogWidgetVar, xhr, status, args)" />
I use the following to keep a dialog open and display validation errors. You will need to move your inputs into a panelGrid so that it can be target by the update attribute.
A simple tag would solve it.
oncomplete="if (args.validationFailed){} else {Professor.show(),Student.hide();}"
you suppose to apply this on Professor widget var
My Struts2 application needs the pagination functionality applied to some records, but what I need to customize is the "Last 1 - 2 - 3 Next" appearance and also have the ability to use a combo box for the selection of how many records should be visible(10 - 20 - 30 - 40 -50).
I have tried two way to accomplish this goal:
1) use display tag library, but I'm not able to customize the appearance, because is auto-generated by the library, and I don't how implement the combo box for select how many records should be visible
2) create my own code for accomplish this functionality but is a job too long and not enough time due to the expiry.
My question is: exists some Struts2 library for realize this functionality? Or, is possible to customize the display tag library for the page scroll bar and the records combo box?
I can give insight from struts2 code base there is no functionality as described by you provided by struts2 in itself..
Regarding the Display tag i have not used them much but since they are the part of oprn source i am sure we can customize that one more thing regarding the customization of display tag ask question under display tag you will get better answer at at quick pace
I wrote a custom tld just for the purpose as below and then just use it like this:
Usage:
paginate.tag
1}">
<c:set var="showingPage"
value="${param.pageNumber == null ? 1 : param.pageNumber}" />
<c:url value="${postUrl}" var="previousUrl">
<c:param name="pageNumber" value="${showingPage - 1}" />
<c:param name="perPage" value="${perPage}" />
</c:url>
<c:url value="${postUrl}" var="nextUrl">
<c:param name="pageNumber" value="${showingPage +1}" />
<c:param name="perPage" value="${perPage}" />
</c:url>
<div class="pagination" />
<c:if test="${showingPage > 1}">
<< Previous
</c:if>
<fmt:formatNumber var="endCounter" pattern="0">
<%= totalCount % perPage > 0 ? Math.ceil(totalCount/perPage) + 1 : totalCount/perPage %>
</fmt:formatNumber>
<c:forEach begin="1" end="${endCounter}" var="index">
<c:url value="${postUrl}" var="url">
<c:param name="pageNumber" value="${index}" />
<c:param name="perPage" value="${perPage}" />
</c:url>
${index}
</c:forEach>
<c:if test="${endCounter != showingPage}">
Next >>
</c:if>
</div>
</c:if>
hi you can try struts2 jquery grid here is the code
<%# page contentType="text/html; charset=UTF-8"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<%# taglib prefix="sjg" uri="/struts-jquery-grid-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<sj:div id="resultsDiv">
<body>
<div id="mainframe">
<s:form>
<div id="sucessMsg">
<s:property value="msg" />
</div>
<s:url id="editurl" action="editUser" />
<s:url id="deleteurl" action="deleteUser" />
<script type="text/javascript">
function editLinkFormatter(cellval, options, rowObject, icon, link_class, link_action) {
//alert(rowObject.username);
return "<a href='#' onClick='javascript:openEditDialog(""+cellval+"",""+rowObject.username+"")'><font class='hyperlink'><u>" + rowObject.username + "</u></font></a>";
}
function deleteLinkFormatter(cellval, options, rowObject, icon, link_class, link_action) {
return "<a href='deleteUser?userid="+cellval+"' onClick='javascript: return delete_user()'><font class='hyperlink'><u>Delete</u></font></a>";
//return "Delete";
}
colModal: [
{name: 'userid', formatter: function (cellvalue, options, rowObject) {
return editLinkFormatter(cellvalue, options, rowObject,
'ui-icon-pencil', 'edit-link-class', 'Edit');
}},
{name: 'userid', formatter: function (cellvalue, options, rowObject) {
return deleteLinkFormatter(cellvalue, options, rowObject, icon, link_class, link_action);
}}
];
function openEditDialog(userid,username) {
$("#resultsDiv").load("<s:property value="editurl"/>?userid="+userid+"&username="+username);
}
function delete_user() {
var agree=confirm("Are you sure you want to Delete?");
if (agree){
return true;
}
else{
return false;
}
// $("#edit_Users").dialog('open');
}
function unlockerFormatter(cellval, options, rowObject, icon, link_class, link_action) {
if(rowObject.loginStatus=='Locked'){
return "<a href='unlockuser?userid=" + rowObject.userid + "')'><font class='hyperlink'><u>Locked</u></font></a>";
}
else{
return "UnLocked";
}
/* return "<a href='deleteUser?userid="+cellval+"' onClick='javascript: return deleteUser("+cellval+")'><u>Delete</u></a>"; */
//return "Delete";
}
</script>
<sj:dialog id="edit_Users" title="Edit User" autoOpen="false"
modal="true" width="800" />
<sj:div id="draggable" draggable="true">
<s:url id="remoteurl" action="viewUserstemp" />
<sjg:grid id="gridtable" caption="Users" dataType="json"
href="%{remoteurl}" pager="true" gridModel="gridModel"
rowList="10,15,20,50,100" rowNum="10" rownumbers="true" viewrecords="true"
width="800" navigator="true" navigatorView="false" navigatorDelete="false" navigatorAdd="false" navigatorEdit="false" navigatorSearch="false">
<sjg:gridColumn name="userid" index="userid" title="User Id"
sortable="false" />
<sjg:gridColumn name="userid" index="username" title="User Name"
sortable="true" formatter="editLinkFormatter" />
<sjg:gridColumn name="emailid" index="emailid" title="Email Id"
sortable="true" />
<sjg:gridColumn name="userCreatedDate" index="userCreatedDate"
title="Created Date" sortable="true" />
<sjg:gridColumn name="userModifiedDate" index="userModifiedDate"
title="Modified Date" sortable="true" />
<sjg:gridColumn name="accstatus" index="accstatus"
title="Account Status" sortable="true" />
<sjg:gridColumn name="userid" index="username" title="Delete User"
sortable="true" formatter="deleteLinkFormatter" />
<sjg:gridColumn name="loginStatus" index="loginStatus" title="Unlock User"
sortable="true" formatter="unlockerFormatter" />
</sjg:grid>
<br></br>
<s:submit action="loadUserValues" cssClass="ui-button ui-widget ui-state-default ui-corner-all ui-state-hover" name="button"
id="button" value="New User" />
<br />
</sj:div>
</s:form>
<%--
<td height="25" align="left" valign="middle">
<s:url id="url" action="unlockuser">
<s:param name="userid">
<s:property value="userid" />
</s:param>
</s:url>
<s:set name="type" value="%{loginStatus}" />
<s:if test="%{#type=='Locked'}">
<s:a href="%{url}" title="Click here to Unlock" ><s:property value="loginStatus"/></s:a>
</s:if>
<s:else>
Unlocked
</s:else> --%>
</td>
</div>
</body>
</sj:div>
</html>
I have a button like this
<input type="button" id="btnEdit" value="Edit Selected" class="emrBTN" style="top:5;right:95;width:100; visibility:hidden" />
I want to change the visibility to visible using jquery onclick ob a button event. How can I do that.
Thanks
jQuery('#btnEdit').css('visibility', 'visible');
It is very near the top of the CSS section of the documentation.
Solution here: http://jsfiddle.net/hY3eg/
HTML:
<input type="button" value="Make Visible" id="makeVisible"/>
<input type="button" id="btnEdit" value="Edit Selected" class="emrBTN" style="top:5;right:95;width:100; visibility:hidden" />
JS:
$(function() {
$("#makeVisible").click(function() {
$("#btnEdit").css("visibility", "visible");
});
});