Struts 2 Jquery delete a row - struts

Can anyone help me deleting a row from Struts 2 Jquery grid using an external button.
I have included a button in the jsp as below
<sj:a id="delete" name="delete" onClickTopics="rowselect"
button="true">Delete</sj:a>
and in the script tag I have written
$.subscribe('delete', function(event,data) {
$("#gridedittable").jqGrid(‘delRowData’,row_id);
}
I am not able to get the rowid for the selected row to be deleted.
Can any one help me with this as I am new to struts 2 jquery.

Hi you can get selected row by using the jqGrid api
$.subscribe('delete', function(event,data) {
var rowid = $("#gridedittable").jqGrid(‘getGridParam’,'selrow');
$("#gridedittable").jqGrid(‘delRowData’,row_id);
}
This assumed you set the multiselect param to false.
For multiselect , you have to use the option selarrrow instead.
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options
And the grid setting should be like
<s:url var="remoteurl" action="jsontable"/>
<sjg:grid
id="gridtable"
caption="Customer Examples"
dataType="json"
href="%{remoteurl}"
pager="true"
gridModel="gridModel"
rowList="10,15,20"
rowNum="15"
rownumbers="true"
>
<sjg:gridColumn name="id" index="id" title="ID" key="true" sortable="false"/>
<sjg:gridColumn name="name" index="name" title="Name" sortable="true"/>
<sjg:gridColumn name="country" index="country" title="Country" sortable="false"/>
<sjg:gridColumn name="city" index="city" title="City" sortable="false"/>
<sjg:gridColumn name="creditLimit" index="creditLimit" title="Credit Limit" formatter="currency" sortable="false"/>
</sjg:grid>

Related

How to pass selected value from selectOneRadio tag to fileUpload tag in PrimeFaces

I'm using PrimeFaces 6.0. I used selectOneRadio tag and populates the list from database, and then I would like to use the selected value to identify the type of document selected and pass this to fileUploadListener so that the right document type is attached to file being uploaded. How do I pass that selected value?
<p:selectOneRadio id="docType" value="#{fileUploadBean.docType}" layout="grid" columns="1">
<f:selectItems var="document" value="#{fileUploadBean.docDescriptionList}" itemLabel="#{docType}" itemValue="#{docType}" />
</p:selectOneRadio>
<p:fileUpload id="docFile" value="#{fileUploadBean.file}" mode="advanced" allowTypes="/(\.|\/)(pdf)$/"
fileUploadListener="#{fileUploadBean.uploadFile}" multiple="true" update="messages">
</p:fileUpload>
<p:growl id="messages" showDetail="true" />
You'll need to add variable for allowed types and then update it when radio button is changed:
<p:selectOneRadio id="docType"
value="#{fileUploadBean.docType}"
layout="grid"
columns="1">
<p:ajax listener="#{fileUploadBean.updateAllowTypes}" update="#form" />
<f:selectItems var="document"
value="#{fileUpoadBean.docDescriptionList}"
itemLabel="#{docType}"
itemValue="#{docType}" />
</p:selectOneRadio>
<p:fileUpload id="docFile"
value="#{fileUploadBean.file}"
mode="advanced"
allowTypes="#{fileUploadBean.allowTypes}"
fileUploadListener="#{fileUploadBean.uploadFile}"
multiple="true"
update="messages">
</p:fileUpload>
And in Java bean:
private String allowTypes; //getters and setters
...
public void updateAllowTypes(){
allowTypes = ... //Specify allowed types
}

selection xtype listener unable to access multifield and multifield unable to fire the dialog.form.findfield

I have been working on disabling the content and ignoring data that is populated in a selection field that forms part of multifield that comes with CQ5 dialog
below is the code that is not working
<medicineType
jcr:primaryType="cq:Widget"
fieldLabel="medicine Type : "
name="./medicinetype"
blankText="medicine Type"
type="radio"
xtype="selection">
<options jcr:primaryType="cq:WidgetCollection">
<inactive
jcr:primaryType="nt:unstructured"
text="medicine Lead"
value="medicinelead" />
<active
jcr:primaryType="nt:unstructured"
text="doctor Lead"
value="doctorlead" />
</options>
<listeners jcr:primaryType="nt:unstructured"
selectionchanged="function(box,value){
if(value == 'medicinelead'){
var ans = box.findParentByType('dialog').form.findField('./medicinedoctorset');
ans.setDisabled(true);
ans.getEl().up('.x-form-item').setDisplayed(false);
}
"/>
</medicineType>
<medicinedoctorset
fieldLabel="doctor cards"
jcr:primaryType="cq:Widget"
name="./medicinedoctorset"
xtype="multifield">
<fieldConfig
jcr:primaryType="cq:Widget"
type="select"
options="/apps/doctor-api/components/medicineview/doctorcards.json"
optionsRoot="doctorcards"
optionsTextField="label"
optionsValueField="id"
xtype="selection" />
</medicinedoctorset>
Not sure what exactly you are trying to do in the code, but it seems to me that you are trying to disable a particular field medicinedoctorset. Try adding id to the field you want to disable, get and disable the field as CQ.Ext.getCmp("idOfTheFieldToBeDisabled").setDisabled(true); Hope this helps.

use checkbox Display Tag in Struts

A list is passed to the display:table. In the table i need to have a checkbox column to select/deselect any transactions that are selected. How do i associate the checked item with the transaction. Also i need to pass this checked transaction to a java script.
Thanks
Jsp code:
<display:column title="<input type='checkbox' name='selectall' onClick='selectAll()' />" media="html">
<input type="checkbox" name="selectBox" class="selectableCheckbox" id="selectBox" value="${sample.txniD}"></>
</display:column>
<display:column property="txniD" sortable="true" scope="all" title="Transaction ID %>" />
Try alerting the value of the checkbox, alert(checkboxArray[i].value);, not toString.

struts 2 dojo, can't load partial div tag?

Can anyone help me? I can't load div tag partially!
The flow, I run is like that:
When I click submit btn, it call imporUrl and go to action "import" and then call the importAction in ActionBean.
After that set 'AAA' and 'BBB' to the List.
Finally it is all working , but it reload the whole form, not only div, I want to reload only div partially. Please help thank !
<s:url id="importUrl" action="import">
<s:param name="id" value="%{id}" />
</s:url>
<sx:submit href="%{importUrl}" value="Import" targets="selectedDiv" />
String importAction(){
List.add("AAA");
List.add("BBB");
return SUCCESS;
}
<s:div id="selectedDiv">
<s:iterator value="List">
<s:property/>
</s:iterator>
</s:div>
I think you directly load the div on same page.But you have to do like this.
<sx:submit href="%{importUrl}" value="Import" targets="selectedDiv"
onclick="javascript:show_details();return false;"/>
And put javascript
<script>
function show_details() {
dojo.event.topic.publish("show_detail");
}
</script>
And make ur div tag like :
<sx:div id="details" listenTopics="show_detail" formId="frm_demo" showLoadingText="">
</sx:div>

Multiple Submit button in Struts 1.3

I have this code in my JSP:
<%#taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
..
..
<html:form action="update" >
..
..
<html:submit value="delete" />
<html:submit value="edit" />
<html:sumit value="update" />
</html:form>
And this in the struts-config.xml file:
<action path="/delete" name="currentTimeForm" input="/viewall.jsp" type="com.action.DeleteProduct">
<forward name="success" path="/viewall.jsp" />
<forward name="failure" path="/viewall.jsp" />
</action>
Like the delete action, I have edit and update. It works fine, if I give the name specifically like <html:form action="delete"> but, how to make it dynamically work for update and edit?
You have one form and multiple submit buttons. The problems is that a form can only submit to one action, no matter how many submit buttons you have inside the form.
Three solutions come to mind right now:
1. Have just one action where you submit everything. Once inside the Action class check what button was used to submit the form and perform the appropriate treatment based on that.
<html:form action="modify">
..
..
<html:submit value="delete"/>
<html:submit value="edit" />
<html:sumit value="update" >
</html:form>
In the ModifyAction.execute(...) method have something like:
if (request.getParameter("delete") != null || request.getParameter("delete.x") != null) {
//... delete stuff
} else if (request.getParameter("edit") != null || request.getParameter("edit.x") != null) {
//...edit stuff
} else if (request.getParameter("update") != null || request.getParameter("update.x") != null) {
//... update stuff
}
2. Have the action attribute of the HTML form changed using JavaScript before submitting the form. You first change the submit buttons to plain ones with click handlers attached:
<html:form action="whatever">
..
..
<html:button value="delete" onclick="submitTheForm('delete.do')" />
<html:button value="edit" onclick="submitTheForm('edit.do')" />
<html:button value="update" onclick="submitTheForm('update.do')" />
</html:form>
With the handler:
function submitTheForm(theNewAction) {
var theForm = ... // get your form here, normally: document.forms[0]
theForm.action = theNewAction;
theForm.submit();
}
3. Use a DispatchAction (one Action class similar to point 1) but without the need to test for what button was clicked since that's treated by the DispatchAction.
You just provide three execute methods properly named delete, edit and update. Here is an example that explains how you might do it.
In conclusion: For number 1, I don't really like those ugly tests.... for number 2, I don't really like the fact that you have to play with the action form using JavaScript, so I would personally go for number 3.
There is another simpler way to do this as follows:
In the ActionForm currentTimeForm, add a String property (example: buttonClicked).
In the jsp, in each of the html:submit tags add this property.
Now in the action execute method simply check the value of this property, ie.
if(currentTimeForm.getButtonClicked().equals("delete"){
}
else if((currentTimeForm.getButtonClicked().equals("edit"))
and so on...