JSF 2.0 - PostConstructs werden sinnlos aufgerufen

N

NeuerUser

Hallo zusammen,

ich bin langsam am Verzweifeln, weil ich einfach den Sinn der Aktion nicht verstehe...

Mein Problem:

Es werden Managedbean Methoden aufgerufen (hauptsächlich @PostConstruct), die mit der aktuellen .xhtml seite absolut nichts zu tun haben.

Beispiel:

AddUrl.xhtml
Code:
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:body>
        <div class="categories">
            <div class="c-corner-left">
                <div class="c-corner-right">
                    <div class="indent">
                        <h:form id="urlForm">
                            <div class="posturlbox">
                                <h:inputText value="#{addUrlBean.userUrl}" styleClass="posturlinput" id="url" onclick="this.value = ''" />
                            </div>
                            <p:commandButton styleClass="button" action="#{addUrlBean.addVideo}" value="#{msg.send}" style="float: left;" update="urlForm" />
                            <div class="addUrlMessage">
                                <p:message for="url" showSummary="true" showDetail="false" />
                            </div>
                        </h:form>
                    </div>
                </div>
            </div>
        </div>
    </h:body>
</html>

AddUrlManagedBean.java
Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedBeans;

import entities.UserEntity;
import infoBeans.VideoValidationInfo;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import sessionBeans.VideoSessionBean;

/**
 *
 * @author MasterM
 */
@ManagedBean(name = "addUrlBean")
@ViewScoped
public class AddUrlManagedBean extends GeneralManagedBean {

    @EJB
    VideoSessionBean videoSessionBean;
    private String userUrl = "YouTube URL";
    @ManagedProperty("#{loginBean}")
    LoginManagedBean loginMB;

    /** Creates a new instance of AddUrlManagedBean */
    public AddUrlManagedBean() {
    }

    public void addVideo() {
        UserEntity sessionUser = loginMB.getSessionUser();

        if (sessionUser == null) {
            informUser(FacesMessage.SEVERITY_WARN,
                    "log_in_or_crate_new_account",
                    "log_in_or_crate_new_account_detail", "urlForm:url");
        } else {
            int validationId = videoSessionBean.validateVideo(userUrl);

            if (validationId == VideoValidationInfo.VIDEO_IS_OK) {
                videoSessionBean.addVideo(sessionUser, userUrl);
                informUser(FacesMessage.SEVERITY_INFO,
                        "video_create_success",
                        "video_create_success_detail", "urlForm:url");
            } else if (validationId == VideoValidationInfo.URL_IS_EMPTY) {
                informUser(FacesMessage.SEVERITY_ERROR,
                        "url_is_empty",
                        "url_is_empty_detail", "urlForm:url");
            } else if (validationId == VideoValidationInfo.URL_SYNTAX_WRONG) {
                informUser(FacesMessage.SEVERITY_ERROR,
                        "url_syntax_wrong",
                        "url_syntax_wrong_detail", "urlForm:url");
            } else if (validationId == VideoValidationInfo.VIDEO_NOT_EXIST) {
                informUser(FacesMessage.SEVERITY_ERROR,
                        "video_not_exist",
                        "video_not_exist_detail", "urlForm:url");
            } else if (validationId == VideoValidationInfo.VIDEO_ALREADY_EXIST) {
                informUser(FacesMessage.SEVERITY_ERROR,
                        "video_already_exist",
                        "video_already_exist_detail", "urlForm:url");
            } else if (validationId == VideoValidationInfo.VIDEO_ID_LENGTH_WRONG) {
                informUser(FacesMessage.SEVERITY_ERROR,
                        "video_id_length_wrong",
                        "video_id_length_wrongdetail", "urlForm:url");
            }
        }
        userUrl = "";
    }

    public String getUserUrl() {
        return userUrl;
    }

    public void setUserUrl(String userUrl) {
        this.userUrl = userUrl;
    }

    public LoginManagedBean getLoginMB() {
        return loginMB;
    }

    public void setLoginMB(LoginManagedBean loginMB) {
        this.loginMB = loginMB;
    }
}

Das komische...
Wenn ich nun in mein CommandButton ausführe, funktioniert zwar alles, jedoch ruft es ebenfalls noch einen @PostConstruct von einer ganz anderen ManagedBean auf und zwar:

UserProfileVideoManagedBean.java
Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedBeans;

import entities.VideoEntity;
import enums.VideoStateEnum;
import infoBeans.PagingInfo;
import java.util.List;
import javax.annotation.PostConstruct;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import sessionBeans.VideoSessionBean;
import javax.faces.bean.ManagedProperty;

/**
 *
 * @author Turk
 */
@ManagedBean(name = "userProfileVideoBean")
@RequestScoped
public class UserProfileVideoManagedBean extends GeneralManagedBean {

    @EJB
    VideoSessionBean videoSessionBean;
    private List<VideoEntity> uncheckedUserVideos;
    private List<VideoEntity> checkedUserVideos;
    private List<VideoEntity> closedUserVideos;
    private boolean existUncheckedUserVideos;
    private boolean existCheckedUserVideos;
    private boolean existClosedUserVideos;
    private String sortBy;
    @ManagedProperty("#{loginBean}")
    LoginManagedBean loginMB;

    /** Creates a new instance of UserProfileVideoManagedBean */
    public UserProfileVideoManagedBean() {
        this.existCheckedUserVideos = true;
        this.existClosedUserVideos = true;
        this.existUncheckedUserVideos = true;
    }

    @PostConstruct
    public void initProfilVideoState() {
        System.out.println("PostConstruct: UserProfileVideoMB - RequestScoped");
        try {

            Long userId = this.loginMB.getSessionUser().getId();
            uncheckedUserVideos = videoSessionBean.getVideosByStateAndUser(VideoStateEnum.UNCHECKED, userId, PagingInfo.VIDEOS_START_PAGE);
            if (this.uncheckedUserVideos.isEmpty()) {
                this.existUncheckedUserVideos = false;
            }
            checkedUserVideos = videoSessionBean.getVideosByStateAndUser(VideoStateEnum.OK, userId, PagingInfo.VIDEOS_START_PAGE);
            if (this.checkedUserVideos.isEmpty()) {
                this.existCheckedUserVideos = false;
            }
            closedUserVideos = videoSessionBean.getVideosByStateAndUser(VideoStateEnum.NOT_OK, userId, PagingInfo.VIDEOS_START_PAGE);
            if (this.closedUserVideos.isEmpty()) {
                this.existClosedUserVideos = false;
            }
        } catch (Exception e) {
        }
        return;
    }

.... und die dazugehörigen Getter-Setter

}

Wie kann das nur sein? Was mich zusätzlich wundert ist, dass wenn ich per navigation-rule auf eine andere Seite wechsel, er noch einmal der PostConstruct der alten ManagedBean aufruft.

Es macht einfach keinen Sinn

----------------------------------------------
Primfaces 2.1
Glassfish v3
jsf 2.0
Ejb 3.1
JPA - Toplink
Netbeans
 

Neue Beiträge

Zurück