简体   繁体   中英

JSF2: commandLink without javascript

Is it possible to get the behaviour of a h:commandLink without using javascript? I'm using JSF2

If I want to use a lightbox component, I will need to have the full generated URL beforehand. If my URLs are action-based, I can only use h:commandLink , which generates javascript binded to the mouse click action.

I would like to have the JSF navigation features (eg: use action="#{bean.action}" to generate links) and have a way to get the full generated URL.

Use <h:outputLink> or <h:link> instead. This generates a plain HTML <a> element without the need for a <h:form> . To invoke actions, you have to move the logic from the bean action method to the constructor or @PostConstruct of the managed bean which is associated with the opened view.

If you need to pass parameters, use <f:param> to append them as a query string. You can use <managed-property> in faces-config.xml (or @ManagedProperty when you're already on JSF 2.0) to set those parameters in the bean. You can access them in @PostConstruct method.

In your action you can use

try {
    FacesUtils.redirect("yourUrl.jsf");
} 
catch (IOException e) {
    Log.get().error(e);
}

To redirect requests.

Of course you can generate your url as you wish

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM