For example, I've this string in GSP:
<td>${cafeeInfo.cafeeName}</td>
How can I send value to the controller via parameter? I know how to do it with form, but to my mind in this case better method is possible.
<g:link action="???" controller="???" params="[param1: value1]">Whatever</g:link>
Here is some Documentation
Related
I have a hidden field in the layout page
#Html.Hidden("idmember", "123456");
I want to access this value in my controller's action
public ActionResult Index(string idmember){
//value for test parameter is null
}
When I do viewsouce on the page - the value is there.
What is the right way to access the value from layout page? Thanks,
UPDATED. based on the help from others, I released in order to pass value to the action I need to do a form post (and it works) but I have an actionlink
example:
#Html.ActionLink("View Member", "index", "member",new{idmember="12345"}, null)
This does work and my URL is /member/index?idmember=12345 But I wanted to make the link cleaner instead of passing the value in the querystring I wanted to somehow pass the value as hidden field? or another way to the action? Is it possible?
Regarding your edit: you shouldn't want to. You pass parameters either in the URL or as request body variables (e.g. POST body).
You can circumvent this for example by using the session to store the ID, but this is going to cause unexpected behavior and will break your web application. Session timeouts, users using multiple tabs and users wanting to share links are going to cause problems.
In short: use the URL for what it's meant to do; don't care about arbitrary "cleanliness".
I have a controller method like that:
public async Task<IEnumerable<MyModel>> GetLinks(IList<string> links)
{
}
Is there anyway I can pass the params to that controller method form url like so:
<endpoint>/getginks?links=http://link1&?links=http://link2 etc?
but for some reason I cant even pass a single param <endpoint>/getginks?links=http://link1
In that case controller getting hit but links = null, I checked on debug.
is there anything I can do?
You need to add the array specification to the URL params, similar to if you were producing POST params from a view.
Try:
/getginks?links[0]=http://link1&links[1]=http://link2&links[2]=http://link3
You need to encode your string and then pass it to your controller.
you can use ajax call, before submitting just encode it
$.htmlEncode(links)
with the use of jquery.html.encode.decode.js
I want to pass ID from query string to my action class, and want to use that id in my action class. I tried as:
<li>
Next
</li>
but I am getting exception. I have aaded list to sessionMap and want to retrive that value from sessionMap as queryString parameter.
Can anybody provide me solution for this problem
Thanks.
If you kept in session there is no need to send as request parameter again.You can directly access that session variable in Action class.
Generally speaking, in Struts2 request parameters are automatically available in the action if:
You have a getter and setter in your action for a variable with the same name (eg int getRecordID() setRecordID(int id) in your case)
You have the ParametersInterceptor in the action's interceptor stack. [1]
[1] See http://struts.apache.org/release/2.2.x/docs/interceptors.html
Try the code below
<li>
<a href="NextPageData.action?recordID="+<s:property value="%{sessionMap.get(recordID[0])}/> >Next</a>
</li>
Hope this helps
Well, I'm not a Struts expert, but I tried the following my Struts 2 Live project and its working fine.
String paramValue = ServletActionContext.getRequest().getParameter("paramName");
Simply put this code on action class.
String paramValue = ServletActionContext.getRequest().getParameter("recordID");
I have a action, say default which will be called from different gsp page.
This default have different set of operation, After completing this operation it need to redirect to the same page from where it is called. Is there any way to achieve this
For example :
A.gsp -> <g:link controller="myController" action="default">
Then default should redirect to A.gsp
B.gsp -> <g:link controller="myController" action="default">
Then default should redirect to B.gsp
I know to implement by sending some params value or other to identify the caller.
But I'm checking is there any way to redirect to caller directly without passing anything from caller explicitly...
You could write a taglib that will use g.link and actionName variable.
Assuming Tools is my Controller, I specify '/Tools' in the ServicePath, and the action name 'GetToolsList' in the ServiceMethod. Can I fire an AutoCompleteExtender this way? How would I be able to pass the prefixText to the Action here? Or is it not possible?
Did it. Created an action that returned void, and JSON-serialized the output and wrote it into the response object so that it's read and shown in an AutoCompleteExtender.