How to use struts2 grid with form submission
Hello,
I've already searched on Stackoverflow with no luck;
I want to make one filter form in which user enters data and according to that data, I want to show results in Struts2 jQGrid.
By default when page loads, Struts2 jQGrid already have action url having all data.
I tried setting target of form and , but it didnt work.
See code:
> <s:url id="filterUrl"
> action="ListItemFilter" />
> <s:form id="filterForm" action="%{filterUrl}">
> <table style="width:100%">
> <tr>
> <td colspan="4">
> <s:textfield
> key="global.item.list.name"
> name="nameContains" />
> </td>
> </tr>
> <tr>
> <td colspan="2"> <s:textfield
> key="global.item.list.pricefrom"
> name="priceFrom" /> </td>
> <td colspan="2"> <s:textfield
> key="global.item.list.priceto"
> name="priceTo" /> </td>
> </tr>
> <tr>
> <td colspan="4">
> <s:select
> cssStyle="width: 100%"
>
> id="SelectCategoryList"
> multiple="true"
> list = "categoryList"
> listKey = "categoryId"
> listValue = "categoryType"
> headerKey="-1"
> headerValue="Select Type"
> key = "global.add.item.type"
> loadingText="Item Types Loading..."
> />
> </td>
> </tr>
> <tr>
> <td colspan="4">
> <div id="fields"></div>
> </td>
> </tr>
> <tr>
> <td colspan="4"> <sj:a
> targets="filterGrid"
> button="true"
> key="global.item.list.form.submit"
> formIds="filterForm"
> onSuccessTopics="reloadGrid"
> />
> </tr>
> </table>
> </s:form>
>
> <s:url id="itemsUrl"
> action="ListItems" />
> <div class="gridSection">
> <sjg:grid gridModel="items"
> href="%{itemsUrl}"
> caption="Items"
> id="filterGrid"
> dataType="json"
> rownumbers="true"
> pager="true"
> navigator="false"
> rowList="10, 15, 20"
> rowNum="10"
> viewrecords="true"
>
> >
> <sjg:gridColumn name="item.itemname" title="Item
> Name"></sjg:gridColumn>
> <sjg:gridColumn name="shelves.shelfname" title="Shelf
> Name"></sjg:gridColumn>
> <sjg:gridColumn name="quantity" title="Available
> Qauntity"></sjg:gridColumn>
> <sjg:gridColumn name="item.itemprice" title="Item
> Price"></sjg:gridColumn>
> </sjg:grid>
> </div>
struts.xml
<action name="ListItems" class="com.acty.libsys.actions.ListItemsAction">
<result name="success" type="json"></result>
</action>
<action name="ListItemFilter" class="com.acty.libsys.actions.ListItemsAction" method="filter">
<result name="success" type="json"></result>
</action>
action:
public class ListItemsAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private List<ItemCategory> categoryList;
public List<ItemCategory> getCategoryList() {
return categoryList;
}
public void setCategoryList(List<ItemCategory> categoryList) {
this.categoryList = categoryList;
}
public String execute() {
serviceProvider.openConnection();
/*This will be available to select box of ListItem.jsp*/
categoryList = serviceProvider.getItemCategoryMapper().selectByExample(null);
items = serviceProvider.getShelfItemsMapper().selectItemsFromShelf();System.out.println("fidddds "+items);
serviceProvider.closeConnection();
return SUCCESS;
}
public String filter() {
ShelfItemsExample example = new ShelfItemsExample();
if(!("".equals(nameContains)))
example.createCriteria().andItemnameIsLike(nameContains);
if(priceFrom != null && priceTo != null)
example.createCriteria().andItemPriceBetween(priceFrom, priceTo);
System.out.println("nameContains "+nameContains + " priceFrom " + priceFrom);
if(itemCategoryFields != null && !(itemCategoryFields.isEmpty())) {
List<String> fieldIds = new ArrayList<String>();
List<String> fieldValues = new ArrayList<String>();
for(Map.Entry<String, String> entry: itemCategoryFields.entrySet()){
fieldIds.add(entry.getKey());
fieldValues.add(entry.getValue());
}
example.createCriteria().andFieldIdIn(fieldIds);
example.setCondition(fieldValues);
}
serviceProvider.openConnection();
items = serviceProvider.getShelfItemsMapper().selectFiltered(example);
System.out.println("fids "+items);
serviceProvider.closeConnection();
return SUCCESS;
}
public void setItems(List<ShelfItems> items) {
this.items = items;
}
/* Used when filter button clicked*/
private String nameContains;
private BigDecimal priceFrom;
private BigDecimal priceTo;
private Map<String, String> itemCategoryFields;
public String getNameContains() {
return nameContains;
}
public void setNameContains(String nameContains) {
this.nameContains = nameContains;
}
public BigDecimal getPriceFrom() {
return priceFrom;
}
public void setPriceFrom(BigDecimal priceFrom) {
this.priceFrom = priceFrom;
}
public BigDecimal getPriceTo() {
return priceTo;
}
public void setPriceTo(BigDecimal priceTo) {
this.priceTo = priceTo;
}
public Map<String, String> getItemCategoryFields() {
return itemCategoryFields;
}
public void setItemCategoryFields(Map<String, String> itemCategoryFields) {
this.itemCategoryFields = itemCategoryFields;
}
/* used when first the form loads*/
private List<ShelfItems> items;
public List<ShelfItems> getItems() {
return items;
}
private DataServiceProviderInterface serviceProvider;
public DataServiceProviderInterface getServiceProvider() {
return serviceProvider;
}
public void setServiceProvider(DataServiceProviderInterface serviceProvider) {
this.serviceProvider = serviceProvider;
}
}
Now form submitted successfully, action also executed successfully, but the grid becomes empty after execution of action.
I didnt get what is happening.
Provide me another way, if this way is not suitable.
In short i ve to implement filter functionality by providing form, and when user click on form submit button, i want to show filtered data in grid. (Please also careful that i dont want to use grid's own filter functionality).
Thank you.
View Answers
Related Tutorials/Questions & Answers:
How to use struts2 grid with form submissionHow to
use struts2 grid with
form submission Hello,
I've already searched on Stackoverflow with no luck;
I want to make one filter
form... to show filtered data in
grid. (Please also careful that i dont want to
use grid's form submissionform submission I have two pairs of textboxes...( so in total 4...("Enter text4 value!");
return false;
}
return true;
}
</script>
<
form name="
form" method="post" onsubmit="return validate();">
<input type="text
Advertisements
javascript form submissionjavascript
form submission
how can apply validation when doing
submission like following
<html>
<script type="text/javascript...();
}
</script>
<
form id="myform" action="submit-form.php
struts2struts2 sir.... i am doing one
struts2 application and i have to make pagination in
struts2....
how can i do
How to export grid into excelHow to export
grid into excel Hi, i created a
grid panel i have to export it to the excel. please help me by some sample code. thanks in advance. cool day dude
struts2struts2 how to read properties file in jsp of
struts2
Hi,
You can
use the Properties class of Java in your action class.ADS_TO_REPLACE_1
Properties pro = new Properties();
FileInputStream in = new FileInputStream(f
Struts2 exception while submitting the update
form in
struts2
I am using tomcat6.0 ...
its...
Struts2 java.lang.NullPointerException
org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69
Struts2 and HibernateStruts2 and Hibernate Sir/ madam,
Can we
use iterator tag in struts for fetch the database value and shown on
form. if yes then
how how to operate on select box using ajax in struts2?how to operate on select box using ajax in
struts2? I am doing a project on
struts2 in which i have a jsp page which has two select boxes like
<s:
form action="">
<s:select id="d" name="dist" onchange="block
Struts2Struts2 Hi,
I need a solution for displaying success message in same page in
struts2.
how to redirect same page in struts2.Please help me.
hi friend,
To know
how redirect action can be done in struts 2 you can go
How to add struts2 dependency in Maven?How to add
struts2 dependency in Maven? What is the dependency code for adding to pom.xml file to include the
struts2 library?
Thanks
You should add the following in the pom.xml file for enabling the Struts 2
STRUTS2STRUTS2 sir but my question is using ApplicationResources.properties in STRUTS 2.i cant get the values into my application.but in the exmple given at roseindia,u cant
use the properties file.i
use actionclass-validation.xml
Login form in Struts2 version 2.3.16How to create Login
Form in
Struts2?
In this video tutorial I am explaining you about the source code of the
program to create the Login
form in
Struts2... at roseindia.net
how to make a login
form in
Struts2.
Check more Struts 2
struts2struts2 dear deepak sir plz give the struts 2 examples using applicationresources.properties file
how to operate on select box using ajax in struts2?how to operate on select box using ajax in
struts2? I am doing a project on
struts2 in which i have a jsp page which has two select boxes like
Now i want to
use ajax so that when i select a district value
struts2struts2 hi all
i am going to run struts2.x program i got this error when server started
java.lang.RuntimeException...:
Struts2 Tutorials
Struts2Struts2 i want select multiple items from select list in struts2.when i did like that the two selected values must saved into databse in two diffirent rows.pls provide any one code for this i am new to
Struts2 struts2 struts2 Sir
when i have run my struts 2 web application,every time i get error " request resources is not available",,,what is this,,,plz help me
Struts2Struts2 Hi
I am using struts 2,In
struts2 architecture ,I couldn't understand the purpose of ActionMapper and ActionProxy.My Question is,when the request comes into the picture,the filterdispatcher consult the ActionMapper
How to reset a form in jQuery?How to reset a
form in jQuery? Hi,
I have a
form where I am using jQuery. I want to reset the
form.
How I can reset the
form grammatically?
Hi,
You can
use following code:
$("#MyFomrName").reset();
Thanks
How to make login form in Struts 2?How to make login
form in Struts 2? Hi,
How to make login
form in Struts 2?
Thanks
Hi,
If you want to learn to make Login
form in Struts then check following tutorial:
How to create Login
Form in
Struts2?
Thanks
how to get time picker value in javascript of struts2how to get time picker value in javascript of
struts2 I am not able to get value of time picker in java script .
my code is
jsp
java script
var totime=dojo.widget.byId("totime").getValue();
how to get value please help me
How to create form in SwingsHow to create
form in Swings
How to create registration, login and question
form in Java Swing?
Creating different forms in Java Swing - Examples
how to create registration
form in swing
swing login
form example
How to create pdf file in struts2.How to create pdf file in
struts2.
In this example, you will see the
how to create PDF in struts, and
how
to write message in generated PDF file in
struts2...
<s:
form
action="generatepdf.action">
how to deploy struts2 app in Intellij ideahow to deploy
struts2 app in Intellij idea I have choosed idea as my ide, but till now i have used ant to make a build file.
Manually i deployed it in server, then start the server.
But As we know that, ide provide there own
how to deploy struts2 app in Intellij ideahow to deploy
struts2 app in Intellij idea I have choosed idea as my ide, but till now i have used ant to make a build file.
Manually i deployed it in server, then start the server.
But As we know that, ide provide there own
how to deploy struts2 app in Intellij ideahow to deploy
struts2 app in Intellij idea I have choosed idea as my ide, but till now i have used ant to make a build file.
Manually i deployed it in server, then start the server.
But As we know that, ide provide there own
how to deploy struts2 app in Intellij ideahow to deploy
struts2 app in Intellij idea I have choosed idea as my ide, but till now i have used ant to make a build file.
Manually i deployed it in server, then start the server.
But As we know that, ide provide there own
how to deploy struts2 app in Intellij ideahow to deploy
struts2 app in Intellij idea I have choosed idea as my ide, but till now i have used ant to make a build file.
Manually i deployed it in server, then start the server.
But As we know that, ide provide there own
how to deploy struts2 app in Intellij ideahow to deploy
struts2 app in Intellij idea I have choosed idea as my ide, but till now i have used ant to make a build file.
Manually i deployed it in server, then start the server.
But As we know that, ide provide there own