I have a list.gsp that displays list of items which is restful. It displays well but It gives me error when I click next or page no. My mapping is:
"/request/list/$sort?/$order?/$max?/$offset?"(controller:"request"){
action = [GET:"list"]
}
My view pagination is:
<div class="paginationlayer">
<span >
<g:paginate next="Next" prev="Back"
total="${ total }" /></span>
</div>
I tried using name url mapping like this:
name requestURL: "/list/$sort?/$order?/$max?/$offset?"{
controller = 'request'
action = 'list'
}
and out some mapping in the view like this mapping="requestURL", I even added params in the pagination, or hardcoded params like offset, max etc but still the same.
but still it gives me HTTP Status 404 when I click "next" it seems that the url loses its map and becomes something like this : http://localhost:8081/client/request/%5BGET%3Alist%5D?offset=10&max=10&order=desc
as basic as it may sound, the solution was to put action="list" to the pagination. Didn't occur to me coz all my paginations work with out it.
<span class="gadgetNumber">
<g:paginate next="Next" prev="Back"
maxsteps="0" action="list"
total="${ printRequestInstanceTotal }" /></span>
There is no need to list all possible parameters in UrlMappings.groovy: whatever you may need will still be available via the params object or via action method attributes.
Please try rewriting the url mapping as
"/request/list"(controller:"request"){
action = [GET:"list"]
}
This will probably resolve your issue and save us the (possibly considerable) effort of determining why exactly your URL mapping isn't being accepted.
Related
This is something quite simple which worked perfectly with Struts 2.1.x. But we recently upgraded to 2.3.15.2 and it broke. Basically we have a form (actually, many forms) with multiple submits:
<s:form>
<s:submit action="save" />
<s:submit action="resetPassword" />
</s:form>
If I stick the action in the tag all is well. But if instead it is in the tag, I get a 404 error. And it's the same action!
I've been debugging and discovered that when you use the "action" attribute in the tag, the generated html is:
<input type="submit" name="action:save">
<input type="submit" name="action:resetPassword">
Supposedly Struts should take this "action" prefix and say "A-ha! This is an action!" and execute it. And it more or less does this. Or at least tries to. What I've discovered is that at a very low level, the DefaultActionMapper.handleSpecialParameters() method goes through all the parameters and tries to create a ParameterAction for each one, and if it's not null, it is executed. Most of the parameters produce a "null" ParameterAction, but not "action:".
In the docs I found this about ParameterAction:
Defines a parameter action prefix. This is executed when the configured prefix key is
matched in a parameter name, allowing the implementation to manipulate the action mapping
accordingly. For example, if the "action:foo" parameter name was found, and a
ParameterAction implementation was registered to handle the "action" prefix, the execute
method would be called, allowing the implementation to set the "method" value on the
ActionMapping
So what it does is set the mapping's result to a new ServletDispatcherResult with the name of the Action:
mapping.setResult(new ServletDispatcherResult(actionName));
On the other hand, when the action is specified in the s:form tag, the mapping's result is null.
So that when finally we get to Dispatcher.serviceAction():
if (mapping.getResult() != null) {
Result result = mapping.getResult();
result.execute(proxy.getInvocation());
} else {
proxy.execute();
}
So when the action is specified in the tag, proxy.execute() is called, which just calls the Action/method itself. Which is what should happen! But when the action is specified in the tag, since the mapping has a result, the proxy's invocation is passed to result.execute(), which calls ServletDispatcherResult ... and in the end, I get a 404.
This seems like a whole lot of work just to get multiple submit buttons with action attributes working. Is this a known issue for Struts 2.3? Do I need to implement a ParameterAction for the "action" prefix as stated in the docs?
EDIT
Ok, known bug, opened just a few days ago. In the meantime I can either downgrade to 2.3.15.1 or use the "method" attribute rather than the "action" attribute.
Hopefully it will be fixed soon ...
this is b/c in struts2.3.16.
Disables support for action: prefix
by default struts.mapper.action.prefix.enabled = false
set
<constant name="struts.mapper.action.prefix.enabled" value="true"/>
in struts.xml
Internal Changes of struts2-core 2.3.16
The action: and method: prefixes are be by default excluded and changed order to first check excludeParams and then acceptedParams in ParametersInterceptor
This is supposed to be in the process of being fixed for 2.3.15.3.
The specific jira is:
https://issues.apache.org/jira/browse/WW-4204
I have a basic controller, just like this:
class BookingController {
def periodCheck(){
}
def periodInput(){
}
Both booking/periodCheck.gsp and booking/periodInput.gsp have been created, and they work if I access typing the URL directly.
However, I have a form in periodInput.gsp that is supposed to send some data to periodCheck, and every time, when I send the form, I get a 404 error, saying that The requested resource (/hoteledison/booking/periodCheck) is not available. The form is defined like this:
<g:form action="periodCheck">
<!-- here would go the fields -->
<g:actionSubmit class="btn" value="Comprobar" />
</g:form>
What am I doing wrong? I've also tried defining allowedMethods in the controller, but that does not help.
Ok, according to this blog post, there's a difference between using actionSubmit and submitButton. For forms like mine, with just one action, I should have used the later.
Now it's working.
I have a simple search form I want to reuse across multiple pages in my codeigniter application. For example, right now I have a search form in the sidebar and I'm planning on displaying that sidebar on the index, about, and other pages.
I want to have the form validation display errors on the same page the users submits the form from.
For example:
User is on About page.
User submits form with invalid data
User sees error in the sidebar on the About page
and
User is on Index page.
User submits form with invalid data
User sees error in the sidebar on the Index page
But I'd like to reuse that form validation logic. I just want it to display the error on whichever page the user posted from.
Any ideas how to do that? Sorry for the noob question, I'm pretty new to CI.
Here you have to think globally.
Step.1 : Make one view file : display.php
which contains :
<div id = "main">
<div id = "header">
[load header file here]
</div>
<?php
if(validation_errors() != '') {
?>
<div id = "error">
<?=validation_errors()?>
</div>
<?php
}
?>
<div id = "content">
<?=$page?>
</div>
<div id = "footer">
[load footer file here]
</div>
</div>
Step.2 : About us Page.(controlller)
.... Your data ....
at end of controller function
$data['page'] = 'aboutus';
$this->load->view('display',$data);
With regards to your comment on the above question you could use Flash data
With the assumption that you have the session library loaded, here is a helper function.
function last_page($page = null){
$ci = get_instance();
if($page === null)
return $ci->session->flashdata('last_page');
$ci->session->set_flashdata('last_page', $page);
}
then you can call last_page('about'); at the top of the about page, and then when you want to find out what the last page you were on was you can just call last_page(); with no params.
In the User Guide, there's different ways to configure sets/groups of rules. Then you can simply have something like:
if ($this->form_validation->run('signup') == FALSE)
{
$this->load->view('myform');
}
else
{
$this->load->view('formsuccess');
}
Which will run your "signup" group of validations. To me, this is the cleanest way to achieve reusable validation rules.
This is a perfectly valid question.
I'm not a PHP expert, nor a CI expert, but the fact is sometimes you want to post to a controller that didn't create the view from which you're posting. Which means posting back to itself is not going to work.
I came across this post on the Ellislab forum:
http://ellislab.com/forums/viewthread/217176/
On this page, There are 2 methods of going about it. Both of which use flashdata and both of which are totally valid, IMHO.
The first: create a helper function
http://ellislab.com/forums/viewreply/1003010/
The second: extend the CI_Form_Validation Class.
http://ellislab.com/forums/viewreply/1047536/
The second is the way I went as it seems cleanest although some may argue whether the form validation class should know anything about flash data.
I have a struts2 page which uses a shared action using <s:action> with executeResult="true" to add header contents to the page. However, there's some processing need to be done in the header action, which needs to retrieve the url of the actual page(aka the caller page). But if I use <s:url> within the header action's jsp, it only retrieve the url of the header action. So I would like to ask the experts here to enlighten me on how to achieve the result I want.
Thanks in advance.
I'm not sure I follow... so feel free to correct me if I'm not at all answering what you want.
But you should be able to use the <s:set> tag with the appropriate scope (probably request) before you call <s:action> to make the values you need available to the next action. See: http://struts.apache.org/2.2.1.1/docs/set.html
I would consider using the request object for this:
String referrer = request.getHeader("referer"); //referer spelling intentional
Do whatever you need with it via string manipulation.
So below is what I did to do it.
On the main page, use s:url and s:set to obtain the current url as well as parameters and save it in request scope
<s:set name="pageurl" scope="request">
<s:url includeParams="none" encode="true"/>
</s:set>
<s:set name="pageparams" scope="request" value="#parameters"/>
On the header page, you can retrieve them using below
<form action="<s:property value='#attr.pageurl'/>" >
<s:iterator value="#attr.pageparams" var="param">
<s:hidden name="%{#param.key}" value="%{#param.value}" id="_header_%{#param.key}"/>
</s:iterator>
</form>
I am using an application (a blog) written using the CodeIgniter framework and would like to search my blog from my browsers location bar by adding a string to the end of my blogs url like this:
http://mysite.com/blog/index.php/search...
As you can see in the example above I am not really sure how to format the rest of the url after the search part so I am hoping someone here might be able to point me in the right direction.
This is what the form looks like for the search box if that helps at all.
form class="searchform" action="http://mysite.com/blog/index.php/search" method="post">
<input id="searchtext" class="search_input" type="text" value="" name="searchtext">
<input type="submit" value="Search" name="Search">
</form>
Thx,
Mark
Since your form is posting to http://mysite.com/blog/index.php/search, I'm assuming this 'search' controller's default function is the one your are attempting to submit your data to. I think that the easiest way to do this would be to just grab the post data inside of the controller method you're posting to. Example:
function search()
{
$search_params = $this->input->post('search_text');
}
Then you would have whatever the user input stored as $search_params, and you can take actions from there. Am I misunderstanding what you're asking?
It seems like you're kind of discussing two different approaches. If you wanted to make a request to
mysite.com/blog/index.php/search&q=what_I_am_looking_for
This is going to call the search controllers default method (which is index by default). If you wanted to use the URL to pass parameters like that you would go to your function in the search controller and do:
print_r($this->input->get('q'));
This will print out "what_am_I_looking_for".
An easier approach in my opinion would be to:
1. Create a view called "search_view" with the HTML content you pasted above, and have the form "action" http://www.mysite.com/blog/index.php/test/search
Create a controller called "Test" that looks like the following:
class Test extends CI_Controller {
function search()
{
$search = $this->input->post('searchtext');
print_r($search);
}
public function display_search()
{
$this->load->view('search_view');
}
}
Visit http://www.mysite.com/blog/index.php/test/display_search in your browser. This should present you with the form you placed in search_view.php. Once the form is submitted, you should be sent to the search function and print out the variable $search, which will have whatever text you submitted on that form.
If this isn't what you were looking for then I am afraid I do not understand your question.