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



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

Have Programming Question? Ask it here!
 
 
 


Jaydeep
How to use struts2 grid with form submission
0 Answer(s)      a year and 5 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
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 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
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
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
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 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  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
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
Ajax grid
Ajax grid  Hi, How I can create ajax grid in my program? 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
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
struts2
struts2  dear deepak sir plz give the struts 2 examples using applicationresources.properties file
how to implement ajax in struts2 to operate on selectbox in jsp
how to implement ajax in struts2 to operate on selectbox in jsp  I am doing a project on struts2 in which i have a jsp page which has 2 select boxes like </s:form>` ` now i want that when i select a district
How to Assign struts2 property to jsp variable
How to Assign struts2 property to jsp variable  In Struts2 <s:property value='count'/> I wants to assign <% int count = %><s:property value='count'/><% ; %> But its not working.   Please
struts2
struts2  hi all i am going to run struts2.x program i got this error when server started java.lang.RuntimeException...: Struts2 Tutorials
Struts2
Struts2  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
how to get time picker value in javascript of struts2
how 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
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
How to Assign struts2 property to jsp variable
How to Assign struts2 property to jsp variable  In Struts2 <s:property value='count'/> I wants to assign <% int count = %><s:property value='count'/><% ; %> But its not working.   Please
job submission in cloud computing
job submission in cloud computing  job submission in cloud computing
Struts2
Struts2  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 can i create a data grid - Java Beginners
how can i create a data grid  Nice to ur respose...thnks all of u plz help me i want make a datagrid but i have no idea about this how can i create datagrid. and how can i connect to the database plz help me give
Swing Problem on submission of button
Swing Problem on submission of button  How to close current frame (Frame1) and open a new frame (Frame2) already created and pass the data to frame2 from frame1 on the clicking of button in swing
Setting Grid Line in JTable
programming tutorial, you will learn how to set the colored grid line in JTable.... You can use the grid line according to the user's requirement.  Description of program: In this program, you will learn how to set the grid line in JTable
How to make a horizontally Scrollable grid in jsp using div, table, css, javascript?
How to make a horizontally Scrollable grid in jsp using div, table, css... saving data would be viewed in grid in the same page. Now problem is that, I need to display a record of 30 columns.Since the grid is made of table it becomes
How to create form in Swings
How 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...;h1>Generate_PDF_in_Struts</h1><hr> <s:form
Struts2 Tiles Example
Struts2 Tiles Example The Following are the steps for Stuts tiles plugin 1. Map the Tiles Listener class deployment descriptor(web.xml) file <listener> <listener-class>org.apache.struts2.tiles.StrutsTilesListener<
how to deploy struts2 app in Intellij idea
how 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 idea
how 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 idea
how 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
Advertisements
 

 

 

DMCA.com