Domanda

Ho un progetto molto semplice JSF 2.0.

Ho un file index.xhtml per farmi vedere una foto di Mount Rushmore. In questa pagina, posso cliccare sopra l'immagine e voglio che vada a "president.xhtml" - nessun problema in questo. Un semplice action = "" ...

Il mio problema è che il mio file di bundle di messaggi (messages.properties) è impostato con chiavi statiche e valori, es:.

jeffersonPageTitle=Thomas Jefferson
rooseveltPageTitle=Theodore Roosevelt
lincolnPageTitle=Abraham Lincoln
washingtonPageTitle=George Washington

E nel mio file "president.xhtml", lo voglio mostrare questi titoli a seconda di quello che ho cliccato su.

<h:form>
  <span class="presidentPageTitle">#{msgs['rushmore.president'],PageTitle}</span>
  <br />
  <h:graphicImage library="images" name="jefferson.jpg" styleClass="leftImage" />
  <span class="presidentDiscussion">#{msgs.washingtonDiscussion}</span>
  <br />
  <h:commandLink action="index" styleClass="backLink">${msgs.indexLinkText}</h:commandLink>
</h:form>

Seconda riga nel codice di cui sopra è il mio problema - non so come fare riferimento al metodo get-a mio java-codice. Codice è qui:

@ManagedBean // or @Named
@RequestScoped
public class Rushmore {
 private String outcome = null;
 private Rectangle washingtonRect = new Rectangle(70, 30, 40, 40);
 private Rectangle jeffersonRect = new Rectangle(115, 45, 40, 40);
 private Rectangle rooseveltRect = new Rectangle(135, 65, 40, 40);
 private Rectangle lincolnRect = new Rectangle(175, 62, 40, 40);

 public Rushmore() {}

 public void handleMouseClick(ActionEvent e) {
  FacesContext context = FacesContext.getCurrentInstance();
  String clientId = e.getComponent().getClientId(context);
  Map<String, String> requestParams = context.getExternalContext().getRequestParameterMap();


  int x = new Integer((String) requestParams.get(clientId + ".x")).intValue();
  int y = new Integer((String) requestParams.get(clientId + ".y")).intValue();

  outcome = null;

  if (washingtonRect.contains(new Point(x, y))) {
   outcome = "washington";
  }

  if (jeffersonRect.contains(new Point(x, y))) {
   outcome = "jefferson";
  }

  if (rooseveltRect.contains(new Point(x, y))) {
   outcome = "roosevelt";
  }
  if (lincolnRect.contains(new Point(x, y))) {
   outcome = "lincoln";
  }
  System.out.println(requestParams.keySet());
 }

 public String getPresident() {
  return outcome;
 }

 public String navigate() {
  if(outcome != null) {
   return "president";
  }
  else return null;
 }
}

E 'il metodo getPresident sto cercando di raggiungere nel file president.xhtml ...

Qualsiasi aiuto sarebbe molto apprezzato:)

È stato utile?

Soluzione

c:set .

<html xmlns:c="http://java.sun.com/jsp/jstl" ...>
...
<c:set var="pageTitle" value="#{rushmore.president}PageTitle" />
<span class="presidentPageTitle">#{msgs[pageTitle]}</span>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top