Passing JSF properties from backup bean A to backup bean B

I am currently getting deeper into JSF 2.0 and not sufficiently versed in the "transport" of managed bean properties from one view to another. I searched a little, but did not find a really good example, so if someone could point me to a textbook or explain it a bit, I would be very grateful.

So here is my scenario:

I am developing a small calendar application for playgrounds. The first view select.xhtmlcontains a calendar selector where the user can select a specific date:

<html>
  ...
  <h:form>

    <!-- Calendar selector from primefaces -->
    <p:calendar value="#{calendarSelect.date}" mode="inline" navigator="true" />

    <p:commandButton value="Show entries for date" action="day" />
    ...

My relevant bean support looks like this:

@ManagedBean(name="calendarSelect")
@RequestScoped
public class CalendarSelectComponent {

  private Date date = null;

  ... // Getters and setters

Now when I submit the form from select.xhtml, I am redirected today.xhtml

<html>
  ...
  <h:form>

    The current day ist:
    <h:outputText value="#{calendarEdit.date}">
      <f:convertDateTime pattern="dd.MM.yyyy" />
    </h:outputText>

Bean support now looks like this:

@ManagedBean(name="calendarEdit")
@ViewScoped
public class CalendarEditComponent implements Serializable {

  private Date date = null;
  private CalendarEntryBean currentEntry = null;
  private List<CalendarEntryBean> allEntries = null;

  ....

: date ?

, :

<p:commandButton value="Show entries for date" action="day" />
  <f:setPropertyActionListener target="#{calendarEdit.date}" value="#{calendarSelect.date}" />
</p:commandButton>

, , date calendarEdit calendarSelect, day.xhtml - , CalendarEditComponent bean , select.

, SessionScoped bean, . , , , , , "" . , , - , , , , , ..

, , , , JSF , .

, , - , - !; -)

+3
1

<f:setPropertyActionListener> submit. , . bean - , . , . <f:param>.

<p:commandButton value="Show entries for date" action="day" />
  <f:param name="date" value="#{calendarSelect.dateAsString}" />
</p:commandButton>

( , , - HTTP). JSF , bean , @ManagedProperty. ExternalContext.

String dateAsString = externalContext.getRequestParameterMap().get("date");

, . bean / rendered. / GET, ?;)
+2

Source: https://habr.com/ru/post/1793022/


All Articles