Reputation: 845
How to replace HREF value with dynamic value in java
<a href=\"http://www.example.com\"> with <a href=\ outcome \">
where String outcome ="home\login.jsf"
Upvotes: 0
Views: 918
Reputation: 6738
Replace 'a' tag with 'h:commandLink' tag.And bind value and action as you like.
<h:commandLink value="#{..}" action="#{yourBean.yourMethod()}"/>
Upvotes: 0
Reputation: 10055
There are different types of outcomes possible. If you're using plain HTML or components such as h:outputLink and h:link, the EL expressions will be interpreted while rendering the page instead of being 100% dynamic.
<h:link outcome="#{bean.link}" value="I go to a page!"/>
Will result in an <a>
tag with the link specified by #{bean.link}
as its href.
Also, in JSF 2.x you can use conditional navigation in your defiend rules by adding an if clause referencing a bean attribute:
<navigation-rule>
<from-view-id>index.xhtml</from-view-id>
<navigation-case>
<from-outcome>logIn</from-outcome>
<if>#{sessionBean.sessionActive}</if>
<to-view-id>userDashboard.xhtml</to-view-id>
<else if>#{sessionBean.rejectedUser}</else if>
<to-view-id>index.xhtml</to-view-id>
<else>
<to-view-id>register.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
On the other hand, elements like h:commandButton and h:commandLink have an action attribute that references a method with return type String or void. If the method return String then you can return "#" or a navigation rule, either implicit navigation or a configured rule:
<h:commandLink value="Log In" action="#{bean.logIn}"/>
The logIn method will be invoked from your Bean:
public String logIn() {
//Your login logic
if(userIsLoggedIn) {
return "userDashboard"; //Implicit navigation
} else {
return "index"; //Implicit navigation
}
}
Implicit navigation (JSF 2.x) will let you navigate between pages in the same folder by returning the name of the page. For example, returning index
will send the user to index.jsf
.
Upvotes: 1
Reputation: 66657
You need to use either EL (like JSTL) render the string there.
Example JSTL is:
<a href=#{outcome}> with <a href=\ outcome \">
Upvotes: 1