Guest User

Untitled

a guest
Jul 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. <h:form>
  2. <h:commandButton
  3. action="#{mainPageBB.goToLink}" value="#{msgs.clickhere}"/>
  4. </h:form>
  5.  
  6. @Named("mainPageBB")
  7. @RequestScoped
  8. public class MainPageBB {
  9.  
  10. @EJB
  11. private ILinkManagerEJB linkManagerEJB;
  12.  
  13.  
  14. public String goToLink() {
  15. String link = linkManagerEJB.retrieveLink();
  16. if(link != null) {
  17. System.out.println(link);
  18. return link.trim() + "?faces-redirect=true";
  19. }
  20. return null;
  21. }
  22.  
  23. public String goToRandomLink() {
  24. String link = linkManagerEJB.retrieveRandomLink();
  25. if(link != null) {
  26. ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
  27. try {
  28. externalContext.redirect(link.trim());
  29. } catch (IOException e) {
  30. e.printStackTrace();
  31. }
  32. }
  33. return null;
  34. }
  35.  
  36. ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
  37. externalContext.redirect(link.trim());
Add Comment
Please, Sign In to add comment