struts2 passing parameters - struts2

New to Struts2.
I have a search criteria form(search1) ,where I have dropdown lists to submit to get a result page (consolidatedreports.jsp).
In my result page, I am showing the data from the search criteria, but I also have a form at the top of the results page with search2 criteria to submit again.
I am chaining my actions because the heading for the results page needs a value from the search1 criteria to determine a heading value.
This works
Question
Now I want the heading to change when I use the search2 form in the results page.
How can I use the values from the search criteria in the search1 and override search2 values in the results page when a user chooses new criteria to run a new report on the results page?
I am modifying someone's code so it has to be done like this.
Can someone suggest a link so I get some information?

please clarify your question...
Using the search criteria and the value which you have entered in your first search page go to your action class.
There you have to check what are your search criteria.
Based on the criteria your codes for selecting values will be get differentiated.
That is you have to use if else if or some switch for each case according to your criteria.
Then in each case you have to bind your values into a list(if it is a server side coding.) and return the control to forwarding 2nd search page.
If it is a client side coding, you just need to return to 2nd page.
In the second page at top you can put your search boxes as in 1st page. then you can get the values from the list and print them, if its server side coding.
If its client side coding, get the selection value for criteria from action page , find the results using your calculations. print it..
the same action class can be used for your second page's search field also..
while submitting the form, keep a hidden field which will specify the name of your page, so that we can identify which search criteria is printing result, using that value you will be able to change your header values also.

Related

RAILS - Submit form to the same page and display query results

I need to display dynamical charts based on user's choises.
I want to let the user choose options from several select menus filled by data coming from db tables.
When the user submit the page, I want to fire a query in order to get the data to build my charts with.
I'm new to Rails and I cannot figure out how to do this.
I've made a new model, setting it to "Abstract" (as I don't need to write anything to the db, just display query results) but I don't know which action I have to use (index, new etc.).
I hope I had correctly explained the problem.
Thank you
Looking at your problem in your views you can use form_tag with remote: true option and url set to your index action. Add your business logic to return chart data in index action. remote: true option will fire request asynchronously. In your views use returned data to display chart.

How do I get Grails g:select with multiple-selection with all selections when returning from the controller

I have a page that is a report from a database and I'm working on modifying how the filtering works. The intention is to allow the user to select possible values form a list that will be used to filter the resulting report. There are too many values to do this with checkboxes. I'm defining a multiple selection list box with this:
<g:select name="country" from="${countryDataList.KOUNTRY}" value="${params.country}" multiple="true" />
countryDataList is a List<> of objects with a name and a value which I create in the controller. I'm able to get the selected counties and process them without an issue.
But when the page returns from the controller with the filtered report, only the first selection in the list is selected. It doesn't re-select all of the items that the user selected. I am passing the params.country object back from the controller as
country:params.country
I saw some posts about this not working, but they are all from several years ago. Am I missing a vital step?
Ahh sorry, I was reading it on the phone initially and missed the point.
So what you want is a way of sending a multiple select box to a confirmation page. If I understand correctly?
Anyways how many objects in the select are we talking massive or a dozen couple of dozen or so ?
What I did was use check boxes and did a confirmation which shows the selection ticked in check boxes.. So this is the confirmation page that loads in https://github.com/vahidhedayati/mailinglist/blob/master/grails-app/views/mailingListEmail/confirmcontact.gsp
this page which is where multiple attachments selected from the schedule re-appear...
https://github.com/vahidhedayati/mailinglist/blob/master/grails-app/views/mailingListAttachments/_mailerAttachmentsDisplay.gsp.
Please note advice below is all conceptual stuff and there may be easier ways than this
Other than that You could create a taglib call on the confirmation page https://github.com/vahidhedayati/ajaxdependancyselection/blob/master/grails-app/taglib/ajaxdependancyselection/AutoCompleteTagLib.groovy#L55 which takes in your arrayList you could probably convert it to JSON pass it into the javascript that you load in within the taglib (on mine further down it loads this page in)
https://github.com/vahidhedayati/ajaxdependancyselection/blob/master/grails-app/views/autoComplete/_selectJs1.gsp#L23
and look to reselect them using javascript... as I say I haven't tested the last bit, the first bit i.e. checkbox works it is/has been in use.
Years later from you I just had the same problem. What I figured out is: it happens when params.country is an array instead of a Collection (i.e. an ArrayList).
A workaround for this if you want to stick to the array type is at the value attribute of the tag doing this: params.country?.findAll().

rails best way to handle optional parameter

I want to display a list of stocks when the user logs in (default parameters). This smells like an index action. However, I will also make a form for the user to select the market capitalization of the stocks (that is to refine the universe). The submission of the form will send parameters to some action (I am not sure if I should use the same index action) and then do an ajax update of the list. This ajax doesn't do anything to the database, it just updates the parameters for the database query.
The first time the user visits the site, they will see the default parameters for the query, but I also want them to be able to change the parameters later and renew the list according to their parameter through ajax.
Yep, a list of stocks sure sounds like an index action. Do you mean that you want to filter the list depending on some form input?
You can make the form send to the index action with a get method, and in your controller, just read the params, and query your #stocks however you want your filter to work.
This is the non-Ajax solution, so users without Javascript will be happy. When you get this working, you can easily AJAXify it.

Orbeon Forms - Find current Document_id

I want to have a text box have the current document_id displayed. Is there an XPath expression to get that?
The following XPath returns the current document id, the same that you see on the URL on the edit page you get by clicking on a form instance in the summary page.
xxforms:instance('fr-parameters-instance')/document
Note however that if you use this in a calculated expression, for new forms, the value won't show until a change was done in the form (e.g. users entered a value in a field).

How do you handle parameters for sorting, paging and filtering?

This is the usual thing: you have a list of items with several attributes. You can :
sort the list according to each of the attributes, in both ascending and descending order
filter (search) the items, again on all attributes
navigate between different pages of results
All of this gives you differents parameters for a given page:
sorting attribute and sorting order
pairs of attribute name and values for the filtering
page number
How do you handle the propagation of all these paramters between your pages ? Let's say you can edit one item, and when you go back, you'd like to get on the same page you where.
Do you simply put all parameters in the url (and pass them as "return parameters" to the edit page) ? Do you put some in the session (maybe sort and filter parameters) ?
I like to make them part of the URL so that if someone bookmarks the page or emails a link to the page, it will render the page exactly the same way. You can't do that if you depend on session state.

Resources