سؤال

لدي مشروع JSF 2.0 بسيط للغاية.

لدي ملف index.xhtml لأظهر لي صورة لجبل رشمور. في هذه الصفحة ، يمكنني النقر على الصورة وأريد أن تذهب إلى "President.xhtml" - لا مشكلة في ذلك. عمل بسيط = "" ...

مشكلتي هي أن ملف حزمة الرسائل الخاص بي (الرسائل.

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

وفي ملف "President.xhtml" الخاص بي ، أريد أن يعرض هذه العناوين اعتمادًا على ما نقرت عليه.

<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>

السطر الثاني في الكود أعلاه هو مشكلتي-لا أعرف كيفية الرجوع إلى Get-Method في Java-Code. الكود هنا:

@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;
 }
}

إنها طريقة GetPresident التي أحاول الوصول إليها في ملف President.xhtml ...

أي مساعدة سيكون محل تقدير كبير :)

هل كانت مفيدة؟

المحلول

يستخدم 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>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top