0

My intention was to show information on filling a text area component. When it gets the focus I show the info, when it loses the focus I clear the info. I do not want to proccess any input value just catch the focus and blur events and call the listener and show/clear the message.

I have read BalusC's comment on conditional rendering so I put my conditional text message to an "always rendered" JSF component.

My "always rendered" f:outPutPanel component is shown in the generated XHTML code but my listener function is never called. As far as I know the method signature of primefaces listener is just void somefunction() not like in jsf ajax listener. I also read BalusC's comment about including @this for the proccess attribute but in my case it seems not to be reasonable as I do not want to catch any input values. I am newbie to JSF and primefaces so any help is appreciated.

My relevant view snippet:

<h:form>
    <h:panelGroup layout="block" id="info">
        <h:outputText rendered="#{ebookController.infoMessage != null}" value="#{ebookController.infoMessage}"/>
    </h:panelGroup>
    ....
    <p:inputTextarea id="description" styleClass="form-control vspace"  required="true" requiredMessage="Kérlek, add meg az e-könyv rövid leírását" value="#{ebookController.newEbook.description}" rows="20" cols="30" counter="display" maxlength="500" counterTemplate="{0} karakter lehet még" autoResize="false" validatorMessage="Az e-könyv leírása maximum 500 karakterből állhat">
       <f:validateLength maximum="500"/>
       <p:ajax event="focus" process="@none" update="info" listener="#{ebookController.setTextAreaInfoMessage()}"/>
       <p:ajax event="blur" process="@none"  update="info" listener="#{ebookController.clearInfoMessage()}"/>
    </p:inputTextarea>
    <h:outputText id="display" />
</h:form>

My relevant java code:

@Named(value = "ebookController")
@SessionScoped
public class EbookController implements Serializable {

private String infoMessage;

public String getInfoMessage() {
    return infoMessage;
}

public void setInfoMessage(String infoMessage) {
    this.infoMessage = infoMessage;
}

public void setTextAreaInfoMessage(){
    setInfoMessage("Tipp: Az e-könyved bemutatása során a fontos részeket emeld ki, és tagold a szöveget bekezdésekkel. Ha egy bekezdés végére értél, csak egy ENTER-t üss!");
}

public void clearInfoMessage(AjaxBehaviorEvent e){
        setInfoMessage("");
}
....
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Roland
  • 327
  • 7
  • 19

1 Answers1

0

Solution 1 : User f:ajax

<f:ajax immediate="true" event="focus" process="@none" render="info"
                listener="#{ebookController.setTextAreaInfoMessage()}" />
<f:ajax immediate="true" event="blur" process="@none" render="info"
                listener="#{ebookController.clearInfoMessage()}" />

Managed Bean

public void setTextAreaInfoMessage() {
        System.out.println("setTextAreaInfoMessage");
        setInfoMessage(
                "Tipp: Az e-könyved bemutatása során a fontos részeket emeld ki, és tagold a szöveget bekezdésekkel. Ha egy bekezdés végére értél, csak egy ENTER-t üss!");
    }

    public void clearInfoMessage() {
        System.out.println("clearInfoMessage");
        setInfoMessage("");
    }

Reference Problem with h:form and p:ajax

Community
  • 1
  • 1
Ravi
  • 391
  • 2
  • 18
  • Thanks your answer. Unfortunately, I still got the following partial response taken from Google dev tools: '
    5250913947076146787:2613487393278789583
    '
    – Roland Apr 26 '16 at 08:59
  • I was able to recreate you case in my sandbox environment. Then found the solution given by BalusC. My Test was done with Mojarra jsf 2.2.4 , primefaces-5.3 on Tomcat 8 – Ravi Apr 26 '16 at 15:29
  • Hi, Ravi. You did not need to change the method signature of 'void setTextAreaInfoMessage()' to 'void setTextAreaInfoMessage(AjaxBehaviorEvent e)'. I use GlassFish 4.1.1 with Mojarra 2.2.12. Really I have run out of ideas. – Roland Apr 27 '16 at 09:49
  • Hi Roland, I did test in a new instance of glassfish-4.1.1 with Mojarra 2.2.12(the jar available within glassfish. ). With lib was primefaces-5.3.jar. – Ravi Apr 27 '16 at 20:53
  • Hi @Ravi. Thanks your time. It is interesting that we are using the same environment and getting different results. During our discussion I realized that pure javascript would be better solution. No client-server communication results faster solution and more robust code. I am a little bit disappointed with the jsf/primefaces approcah as a newbie. I thought that these frameworks are to make the developer's life easier but it turned out that even the easiest task is not trivial to accomplish, at least for me. – Roland Apr 29 '16 at 07:39