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");
Related
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
I need to be able to pass an ID to my Kooboo module.
I was hoping to add {id} to the page route and then somehow pass it to the module put I can't seem to find how.
I want the Querystring variable to be passed into the MVC Controller action.
Any Suggestions?
Managed to figure it out
Add a route to a controller in Module.Config
Use
#Url.ModuleUrl().Action("ActionName")
or
#Url.ModuleUrl().Action("ActionName", new { parameterName = 0 })"
To get an url to another action/controller within you module
I want to pass a parameter to the controller and this is what i did :
<c:out value="${activity.nom_etabl}"/>
The controller :
#RequestMapping(value="/getinfoEtab")
public String getInfoEtablissement(#RequestParam("nomEtab") String nometab,ModelMap model){
model.addAttribute("etabliss", actservice.FicheEtabl(nometab));
return "FicheEtablissement";
}
But the controller with this way doesn't get the parameter.
Is ${pageContext.request.contextPath}/getinfoEtab resolving into the url you are trying to reach?
If your context path is the same as in the url for the page that contains your <a href> tag then you don't need ${pageContext.request.contextPath}. You can directly use <a href="getinfoEtab?nomEtab=. But if its taking you to the controller don't even bother changing it.
Do you see a value in your link where you have <c:out value="${activity.nom_etabl}"/>? If you can see the value, then change your code to <a href="${pageContext.request.contextPath}/getinfoEtab?nomEtab=${activity.nom_etabl}">
I am looking out for different alternatives of passing parameter from an action method in JSF Managed bean to next view.
For example, I have an action method in my managed bean.
public String actionMethod01(){
String outcome = "nextPage";
return outcome;
}
If I want to pass a parameter to nextPage, one option which I have is:
outcome += "?param1=value1";
But, its not so convinient if I have multiple parameters to be passed.
Is there a better way for doing it?
Best regards,
Anand.
There's nothing in the JSF API which makes this easier. Just create a helper/utility method yourself which makes it more convenient so that you can end up with something like this:
return "nextPage" + toQueryString("param1", "value1", "param2", "value2");
I'm trying to pass a list of URL's with Id attributes from a controller to a view.
I can pass a <a href=...> link back but I don't think writing a 'localhost' absolute path is a clean way of approaching this. I cant pass an ActionLink back as it returns the full string. Is ther a simple solution to this problem? Thanks in advance.
Using this overload of the UrlHelper.Action() method and Request object you can get a complete URL including the route parameters such as IDs and the actual hostname of the application.
string url = Url.Action("action", "controller",
new System.Web.Routing.RouteValueDictionary(new { id = id }),
"http", Request.Url.Host);
UrlHelper is available in the controller via its Url property.
You can then pass such URL into your view.
It is also possible to use UrlHelper directly inside your view to create URLs for controller actions. Depends if you really need to create them inside the controller.
Edit in response to comments:
Wherever you need to place the URLs, this "URL builder" you are looking for is still the UrlHelper. You just need to pass it (or the generated URLs) where you need it, being it inside the controller, view or custom helper.
To get the links inside the unsorted list HTML structure you mention, you need to put anchors inside the list items like this:
<ul>
<li>Link</li>
...
</ul>
Then again you just need to get the URLs from somewhere and that would be from UrlHelper.
Simple and easy.
text
the route id = the parameter that is going to be inserted into your method.
eg.
function Details(int id) {
//id has the value of my_var_id
}