Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Struts How to use struts2 grid with form submission
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Jaydeep
How to use struts2 grid with form submission
0 Answer(s)      a year and 6 months ago
Posted in : Struts


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.


Advertisement
View Answers

Related Tutorials/Questions & Answers:
How to use struts2 grid with form submission
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... to show filtered data in grid. (Please also careful that i dont want to use grid's
form submission
form 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 submission
javascript form submission  how can apply validation when doing submission like following <html> <script type="text/javascript...(); } </script> <form id="myform" action="submit-form.php
How to use Sigma grid built-in capabilities to calculate aggregates where Sortable property set to TRUE
How to use Sigma grid built-in capabilities to calculate aggregates where Sortable property set to TRUE  How to use Sigma grid built-in capabilities... ,totals row will come up and may cause mess in the grid). Sorting must be done
How to export grid into excel
How 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
how to use a image in background in your application form?
how to use a image in background in your application form?  how to use a image in background in your application form
how to insert a summary values in grid
how to insert a summary values in grid  how to insert a summary value in grid
job submission in cloud computing
job submission in cloud computing  job submission in grid computing
How to use enctype="multipart/form-data" in DOJO - JSP-Servlet
How to use enctype="multipart/form-data" in DOJO  Hi All, I am.../mixed stream' Is there any way to use multipart/form-data in dojo... form method = "post" & enctype="multipart/form-data". In same page I am using
struts2 how can we add an radio button to form using a class(doa)
struts2 how can we add an radio button to form using a class(doa)  Hi... button on the registration form how to do plz help me out here is my code model...; plz sugest me how to use the class means how should i refer it here  
struts2 how can we add an radio button to form using a class(doa)
struts2 how can we add an radio button to form using a class(doa)  Hi... button on the registration form how to do plz help me out here is my code model...; plz sugest me how to use the class means how should i refer it here  
how to use one form out of multiple form from one jsp to another jsp
how to use one form out of multiple form from one jsp to another jsp  Hi All. please give me your valuable advise for below requirement.. I have... one form from abc.jsp as it is to another .jsp(say def.jsp).Your advise
job submission in cloud computing
job submission in cloud computing  job submission in grid computing using gui representation
struts2
struts2  sir.... i am doing one struts2 application and i have to make pagination in struts2....how can i do
how to prepopulate data in struts2 - Struts
how to prepopulate data in struts2  I wanted to show the data from database using Struts 2
how to display data in List Or grid or in table in Jsp
how to display data in List Or grid or in table in Jsp   <%@page import="java.util.Calendar"%> <%@ page import="org.apache.lucene.search.IndexSearcher"%> <%@ page import="org.apache.lucene.analysis.Analyzer"%>
struts2 - Struts
Struts2 and Ajax Example  how to use struts2 and ajax
how to show required fields indicate as * in struts2
how to show required fields indicate as * in struts2  how to show required fields indicate as * in struts2
struts2
struts2  how to read properties file in jsp of struts2   Hi, You can use the Properties class of Java in your action class. Properties pro = new Properties(); FileInputStream in = new FileInputStream(f); pro.load
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
job submission in cloud computing using gui representation
job submission in cloud computing using gui representation  job submission in grid computing using gui representation
How to use Token Interceptor - Struts
How to use Token Interceptor  Hi, Iam a beginner in struts. I tried to implement Token Interceptor to prevent double submission, I search internet but didnt find examples to do that in Struts2 I tried below code
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
Struts2 and Hibernate
Struts2 and Hibernate  Sir/ madam, Can we use iterator tag in struts for fetch the database value and shown on form. if yes then how
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
STRUTS2  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
Struts2
Struts2  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
Ajax grid
Ajax grid  Hi, How I can create ajax grid in my program? Thanks
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
Grid Problem - Java Beginners
detail. Steps: 1:- there r one form,this form belong to grid. and two... belong to different table.but in main form,all data going in the grid(with join... user input in form) form also . 6:- user click the next button then grid open
struts2
struts2  dear deepak sir plz give the struts 2 examples using applicationresources.properties file
Advertisements
 

 

 

DMCA.com