質問

Ok guys. After something like 3 hours of struggle, I decided to post the question here, since I'm not able to solve this.

Let's get to the point.

I've got a NetBeans web project done with PrimeFaces 3. It works correctly, no problems of any kind.

But I need to make an Enterprise Application, using that Web project as the Web module.

I already have an EE project with the EJB part almost complete, so I started to "merge" the two projects, by copying the web pages into the War part of the Enterprise project and by rewriting the Managed Beans.

But things got messy so I had to make some changes.

I'll write the code of 2 files in different versions (keeping in mind that this code WORKS in the single Web project!):

-- JSF PAGE --

[cut]
<p:dialog id="loginDialog" header="Login" widgetVar="loginDialog" showEffect="fade" hideEffect="fade" position="center" draggable="false" resizable="false" height="220" width="300" modal="true" showHeader="false">
        <h:form id="loginForm">
            <br/>
            Username: <br/><p:inputText id="username" value="#{loginBean.username}" required="true" requiredMessage="random error message"/><br/><br/>                           
            Password: <br/><p:password id="password" value="#{loginBean.password}" required="true" requiredMessage="random error message"/><br/><br/>                                                        
            <p:commandButton value="Login" actionListener="#{loginBean.doLogin}" oncomplete="handleLoginRequest(xhr, status, args)" ajax="true" update=":growl, :loginForm, :userPanel"/> <p:commandButton value="Cancel" type="button" onclick="loginDialog.hide()" />
        </h:form><br/>                    
    </p:dialog>
[cut]

-- MANAGED BEAN --

[cut]
public void doLogin(ActionEvent ae) {
    user = loginUser.doLogin(username, password);
    loggedIn = false;
    FacesMessage msg;
    RequestContext context = RequestContext.getCurrentInstance();
    if (user != null) {
        msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Welcome " + user.getUsername(), user.getUsername());
        loggedIn = true;
    } else {           
        msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Login failed", "Incorrect credentials");
    }
    FacesContext.getCurrentInstance().addMessage(null, msg);
    context.addCallbackParam("loggedIn", loggedIn);
}
[cut]

Even if this code WORKS in my Web project, "moving" it to the full EE application leads me to an error :

The class 'ManagedBeans.LoginBean' does not have the property 'doLogin'.

So, assuming that the problem is caused by doLogin's signature (it takes one parameter, but in JSF page is called without it), and despite the fact that this is the way that the component is used in the PrimeFaces docs, I've simply changed it into :

-- JSF PAGE --

[cut]
<p:dialog id="loginDialog" header="Login" widgetVar="loginDialog" showEffect="fade" hideEffect="fade" position="center" draggable="false" resizable="false" height="220" width="300" modal="true" showHeader="false">
        <h:form id="loginForm">
            <br/>
            Username: <br/><p:inputText id="username" value="#{loginBean.username}" required="true" requiredMessage="random error message"/><br/><br/>                           
            Password: <br/><p:password id="password" value="#{loginBean.password}" required="true" requiredMessage="random error message"/><br/><br/>                                                        
            <p:commandButton value="Login" action="#{loginBean.doLogin()}" oncomplete="handleLoginRequest(xhr, status, args)" ajax="true" update=":growl, :loginForm, :userPanel"/> <p:commandButton value="Cancel" type="button" onclick="loginDialog.hide()" />
        </h:form><br/>                    
    </p:dialog>
[cut]

-- MANAGED BEAN --

[cut]
public void doLogin() {
    user = loginUser.doLogin(username, password);
    loggedIn = false;
    FacesMessage msg;
    RequestContext context = RequestContext.getCurrentInstance();        
[cut]

So I've changed the method signature and the action of the commandButton.

By doing this changes, it seems that the previous error is gone..but..

java.lang.NoClassDefFoundError: org/primefaces/context/RequestContext

Yes, now I've got this one.

Just to set things clear, the library is imported and everything's fine. NetBeans can import correctly from org.primefaces.*, so I assume that the jar file il loaded.

But here comes the strange thing.

After removing PrimeFaces from libraries and importing a new jar (the same one as before, it's just in a different directory) it seems to work.

The page is loaded without problems.

But this lasts just until the next deploy, because a new deploy will lead me to the same NoDefClassFoundError as before.

It's quite a random thing, because it gets solved after some playing with the library paths, but none of them works for more than one deployment.

I don't know what to do, because things are pretty weird.

Sometimes it just load the page with the yellow warning, saying that he can't find the library for http://primefaces.org/ui namespace (or something like this).

I'm sorry for the length of the question, but it's quite hard to explain what I'm seeing.

Is there anyone that can point me out to a solution?

役に立ちましたか?

解決

Both problems have exactly the same cause: PrimeFaces JAR file isn't in the runtime classpath (for simplicity I assume that you're using PrimeFaces 3.x and have not changed the taglib URI).

The class 'ManagedBeans.LoginBean' does not have the property 'doLogin'.

The first exception is admittedly somewhat misleading but in reality the PrimeFaces components are not been resolved by Facelets at all and treated as plain text/html. Any EL expression inlined in PrimeFaces component markup will then be resolved as a value expression. It's like as you're writing EL plain in template text like so <p>#{loginBean.doLogin}</p>. It's then looking for a getDoLogin() method in order to print its result.

java.lang.NoClassDefFoundError: org/primefaces/context/RequestContext

The second exception brings you closer to the real explanation of the problem: the JAR file containing the mentioned class is not in the webapp's runtime classpath.

Make sure that the PrimeFaces JAR file is present in the webapp's /WEB-INF/lib folder of the deploy.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top