I want to create a restful link for each user, who registered on my page. For Example: User "testuser" registered on my page and his profile should be accessible through www.mypage.com/users/testuser.
How can i realize something in wicket?
in WebApplication implementation add to init():
mountPage("/users/${id}", UserPage.class);
and in UserPage.class :
public UserPage(PageParameters parameters) {
String id = parameters.get("id").toString();
...
}
Is it possible to introduce a additional url path element? Something like "http://server/users/userid/testuser"? If you have mount your page to the url "users" then the page will be initialized by wicket using the constructor with the PageParameters parameter:
public class UserPage extends WebPage {
public UserPage(PageParameters pars) {
String userId = pars.getParameterValue("userid");
...
}
}
Have a look at mounting pages in wicket 1.5. It describes the methods to 'mount', aka make available, a page on a certain url. Parameters to that page (in your case, the user name) can either be via name or via index (position).
You will be interested in the positioning parameters.
Related
Can I able to access method as action in Struts 2 with Codebehind plugin? Since there is no struts.xml file and its works as action!method in the URL.
Just I'm wondering to access a method
How to use Struts tag on class?
"#Action(name="action"), <s:url action="action" method="method" />
Class :
#Action(name = "JSONexample")
#Result(name="success",type=JSONResult.class,value="",params={"root","List"})
public class PartAction extends ActionSupport {
public String JSONexample{
-----
return SUCCESS;
}
public String readxml { }
}
if I access below method on submit button click , will I get the JSON data?
$.getJSON('ajax/sayHi.action', formInput,function(data)
So i can access action in URL as
localhost:7001/Sample/JSONmethod.action
to get the JSON data ?
As far as Codebehind Plugin doesn't support actions on methods you need to use Convention Plugin then use convention annotation #Action on method you want to be your action then you don't need ! explicit mapping.
If you continue to use the Codebehind Plugin, then you have to use Dynamic Action Invocation (DMI) to call the method other than mapped to your action.
Another time had to reread you question, it seems you want to access the action that has not mapping to the method other that execute:
It isn't supported by the codebehind plugin;
You have not mapped it via struts.xml. In this case the answer would be - no, you can't. But you can always use execute method!
If you continue with using of DMI better use s:url tag to construct the URL and use the method attribute.
I'm currently developing a Struts 2 web application that allow anonymous usage. I want that with anonymous user, the URL will be like:
http://localhost:8080/myapp
But after user logged in, the URL will be personalized base on user name, for example:
http://localhost:8080/myapp/Cuong-Doan
Please suggest me a plugin/technique that can help me to achieve it.
You can try to do it with Tuckey's UrlRewriteFilter. After loging add session attribute, for example loggedUsername=Cuong-Doan. Then analyze this attribute in UrlRewriteFilter rule using session-attribute parameter of condition element. If it is present -> do redirect, add it to the URL using backreferences.
Personalized could be done via setting the parameter specifying the persona. Looking at the URLs in the question I decided to give you imagination about technique used to reproduce SEO optimized URLs. This technique is called "Parameters after action names". For example to map your persona with the action you can use
#Action(value = "/*", params = {"person", "{1}"})
so, after that action is mapped you will get the information about person via the person parameter that could be used in the action.
I believe it has something to do with Struts2 ValueStack, but if you guys could give me a hand with that would be great.
I have the following setup: Spring 3 + Struts 2.
My struts actions are pretty much like this:
#ParentPackage("struts-default")
public class StepOneAction extends ActionSupport {
...
}
Such Action has a method that is my forward:
#Action(value = "/bla", results = { #Result(name = "ble", location = "/bli.jsp") })
public String populate() {
...
return BLE;
}
Finally such Action is #Autowired.
What's puzzling me is that if I open, say Firefox, navigate to the first page - it's a 3 step wizard - fill the form and submit THEN open another browser, say Opera, and navigate to the first page, Opera has the data populated from Firefox.
How's that possible? What am I missing?
The ValueStack is per-request, so I don't see how it could possibly be a factor here.
It sounds like Spring is treating StepOneAction as a singleton, which would account for the behavior you are seeing. Actions need to be instantiated per-request.
Check that you haven't defined a member on the JSP page or Servlet that keep the same value among multiple sessions
1) i have added an element in request object given below, i need to get/read this in my webpage, how can i do it?
<input type="hidden"> wicket:id="submitted" value="false" />
eg: in servlet, use request.getParameter("submitted") from hidden session.
2) in my controller class i want to set the value in session or hidden field, so that i can identify the user if he already processed the request or enetered my block of code.
1) use HiddenField
2) use a custom WebSession object:
public class MySession extends WebSession{
public Mysession(Request request){super(request);}
private boolean completedRegistration;
public boolean hasCompletedRegistration() {
return completedRegistration;
}
public void setCompletedRegistration(boolean completedRegistration) {
this.completedRegistration = completedRegistration;
}
}
I am not sure I have fully understood your questions.
But to make it short, if you want to get the value stored in your request object, you'll need to make the model of your input map to this value (by using HiddenField wicket internal class).
If you want to track your user, the best thing to do is looking around for a cookie set on the client side that'll allow you to manage its visits.
Please refine your question if you want a more precise answer...
I'm trying to build a way for my application to have a URL pattern/scheme like that of applications like Twitter. For example myapplication.com/username where the username is an actual username treated as a parameter. This parameter will be used to display the user related page. My application also has this URL scheme where the username is a prefix for other resources e.g. myapplication.com/username/accountsettings or myapplication.com/username/profile. The username acts some sort of sub-context path.
As the title suggests, I'm using Stripes for it. What I'm doing now is create a custom ActionResolver where I take out the first non-empty string from the URL binding (the username in this case) since my ActionBeans do not take into account the username prepended to the URL. So for example, the action bean that handles myapplication.com/username/accountsettings is only bound to /accountsettings.
When I tried to use the custom ActionResolver as ActionResolver.Class init param for the Stripes filter, it doesn't seem to be working. It seems like it's still using the default ActionResolver. How do I alter this?
Also, is there an easier/more intuitive way to do this? I'm not very familiar with Stripes and URL bindings so is there a facility in Stripes that would allow me to do this without extending/altering the framework components?
Thanks.
I agree with lucas, URL mappings should be done by UrlBinding annotation. There is no need to start messing around with URL remapping filters, that will only break the Stripes system in generating correct URL’s for you.
This is how it should look like:
#UrlBinding("{username}/profile/")
public class MyProfileAction implements ActionBean {
private ActionBeanContext context;
private String username;
public ActionBeanContext getContext() {
return context;
}
public void setContext(ActionBeanContext context) {
this.context = context;
}
public void setUsername(String username) {
this.name = name;
}
public String getUsername() {
return username;
}
#DefaultHandler
public Resolution view() {
return new ForwardResolution(“/WEB-INF/MyProfile.jsp”);
}
}
I stumbled upon URL Rewrite Filter and it seems to fit the needs of my application so far.
Stripes does have this built in. It's called the #URLBinding annotation, and it was included in Stripes 1.5. There is some documentation here, and there was more in the Stripes book IIRC.
#UrlBinding("/foo/{bar}/{baz}") maps
the action to "/foo" and indicates
that the "bar" and "baz" parameters
may be embedded in the URL. In this
case, the URL /foo/abc/123 would
invoke the action with bar set to
"abc" and baz set to "123".