1

I search for someone who can help me out with this "small" problem, I searched for hours. The code below is "broken down", so the real application is huge, I can't move technology at the moment.

So I have primefaces 5.0.10 and MyFaces 2.0.3 and I have to deal with that.

Here's an XHTML:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="../index.xhtml">
<ui:define name="title">Keyboard Bean Test</ui:define>

<ui:define name="content">
    <h1>Keyboard Bean Test</h1>

    <h:form id="myform">
        <p:panel header="KeyboardBean">
            <p:keyboard value="#{keyboardBean.value}"></p:keyboard>
        </p:panel>

        <h:outputText id="myOutput" value="#{keyboardBean.value}"></h:outputText> <br /><br />

        <p:commandButton value="Setzen" update="myOutput"></p:commandButton>
    </h:form>
</ui:define>

And here's my KeyboardBean.java

package de.lippoliv.test.primefaces.beans;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import javax.inject.Named;

@Named("keyboardBean")
@ManagedBean
@SessionScoped
public class KeyboardBean {

    private String value;

    public String getValue () {
        System.out.println("KeyboardBean::reading value: " + value);

        return value;
    }

    public void setValue (String newValue) {
        System.out.println("KeyboardBean::write value: " + newValue);

        value = newValue;
    }

}

What I would like to to: Update the outputText on pressing the commandButton. QUIET SO SIMPLE!

In the real application the use-case is different, but for start figuring out why it doesn't work in real application, I decided to break it down to this simple think and then make it (step by step) more like the real application.

Whatever: This doesn't work. The outputText just refresh after page-load. I tryed a lot till now, nothing worked. Just switching from MyFaces to original JSF, but that is (as I wrote) not possible for me at the moment.

Hopefully someone can help me out here.

update 1

Here's the Ouput of console:

26.02.2016 11:58:58 org.apache.myfaces.config.annotation.Tomcat7AnnotationLifecycleProvider newInstance
INFO: Creating instance of de.rac.oliverlippert.test.primefaces.beans.MenuBean
26.02.2016 11:58:58 org.apache.myfaces.config.annotation.Tomcat7AnnotationLifecycleProvider newInstance
INFO: Creating instance of de.rac.oliverlippert.test.primefaces.beans.KeyboardBean
KeyboardBean::reading value: null
KeyboardBean::reading value: null
KeyboardBean::reading value: null
KeyboardBean::reading value: null
26.02.2016 11:59:01 org.apache.myfaces.config.annotation.Tomcat7AnnotationLifecycleProvider newInstance
INFO: Creating instance of de.rac.oliverlippert.test.primefaces.beans.KeyboardBean
26.02.2016 11:59:01 javax.faces.validator._ExternalSpecifications isUnifiedELAvailable
INFO: MyFaces Unified EL support enabled
KeyboardBean::reading value: null
KeyboardBean::write value: sdf

Very interessting: After pressing the commandButton once, the Beans will not be called again...

Also I modifyed my bean, it now starts with

@ManagedBean
@SessionScoped
public class KeyboardBean {
    ...
}

AND also I modifyed my "update" to use the whole id:

<p:commandButton value="Setzen" update=":myform:myOutput"></p:commandButton>

All that doesn't change a thing :/

FireFox throws one JS error on pressing the button:

TypeError: f is null (javax.faces.resource/primefaces.js.xhtml?ln=primfaces&v=5.0 row 2 col 6868)

Thanks for any reply

update 2 OK breaking it down to this XHTML, it work:

<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:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
>

<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>Primefaces Test</title>
</h:head>

<h:body>
    <h1>Keyboard Bean Test</h1>

    <h:form id="myform">
        <h:panelGrid id="grid" cellpadding="5" columns="2" style="margin-bottom:10px">
            <p:panel header="KeyboardBean">
                <p:keyboard value="#{keyboardBean.value}"></p:keyboard>
            </p:panel>
            <h:outputText id="myOutput" styleClass="update" value="#{keyboardBean.value}"></h:outputText>

            <h:outputText id="myOutput2" styleClass="update" value="#{keyboardBean.value}"></h:outputText>
            <h:outputText id="myOutput3" styleClass="update" value="#{keyboardBean.value}"></h:outputText>
        </h:panelGrid>

        <p:commandButton value="Setzen" update="@(.update)"></p:commandButton>
    </h:form>
</h:body>

Now I can move forward step by step. Thanks for all :)

lippoliv
  • 679
  • 2
  • 9
  • 26
  • 2
    Possible duplicate of [Backing beans (@ManagedBean) or CDI Beans (@Named)?](http://stackoverflow.com/questions/4347374/backing-beans-managedbean-or-cdi-beans-named) – Kukeltje Feb 26 '16 at 10:30
  • Your title is very wrong. It suggests it works with PrimeFaces 5.1 or with Mojarra or even myfaces 2.1. And very remarkable that a question like this has 2 upvotes and 2 **favorites even** in 2 hours. Very suspicious – Kukeltje Feb 26 '16 at 10:31
  • Hey Kukeltje, I specifyed Version-Numbers because I have to use those Numbers. I haven't tryed newer Versions because I can't migrate. One fav is from me, the other I don't know. – lippoliv Feb 26 '16 at 11:01
  • Put them in your question, not title – Kukeltje Feb 26 '16 at 11:03
  • Please take a step back from development... You annotations are wrong... create an [mcve] (e.g. dropping the template) – Kukeltje Feb 26 '16 at 11:22
  • @Kukeltje OK will give a try to get less code. MyFaces (Maven Dependency org.apache.myfaces.core) indeed should stay in title, because using original (Maven Dependency com.sun.faces) will work... – lippoliv Feb 26 '16 at 11:35

2 Answers2

1

Have you tried to remove @ManagedBean annotation and import javax.enterprise.context.SessionScoped instead of javax.faces.bean.SessionScoped?

It seems to me that at this moment you are mixing CDI beans with Backing beans. Details and differences are provided at this link

Community
  • 1
  • 1
Nikola
  • 430
  • 4
  • 15
  • Please mark the question as a duplicate of the link you posted. – Kukeltje Feb 26 '16 at 10:29
  • @user1072089 thanks for your answer. I read this post. I understand that mixing CDI beans with Backing beans is not good. I modifyed my bean just using "Named" "SessionScoped", but it still does not change anything. – lippoliv Feb 26 '16 at 11:29
  • @user1072089 I simplifyed my XHTML as described in "update 2" and then backported to my original bean, it doesn't work. Then I did what described in your link and now it works. Also JAVA stops generating new beans each refresh and use the old one. Thanks for your answer :) – lippoliv Feb 26 '16 at 13:54
0

I tried to reproduce your Problem:

Bean

@ManagedBean
@ViewScoped
public class TestBean {

    private String testValue = "a";

    public void setTestValue(final String testValue) {
        this.testValue = testValue;
    }

    public String getTestValue() {
        return testValue;
    }

    public void testAction() {
        setTestValue("b");
    }
}

View

<h:outputText id="testId" value="#{roleEditController.testValue}" />
<p:commandButton update="testId" action="#{roleEditController.testAction}" />

But in my case it is working :/

  • Don't you get any javascript or java errors?
  • Did you try to use the absolute id to update the component?

You can find the absolute id if you inspect the page with your Browser:

<span id="form:testId">a</span>

In this case the absolute id would be :form:testId

71m024
  • 86
  • 6