0

could you please help me. I made this request scoped managed bean, but when I click on sayHello, in the console of the log it displays only hello even if I put a value in the field "chaine"

public class BackTheme {


private String chaine;

public BackTheme() {

}

public void sayHello(){
    System.out.println("hello "+chaine);
}

public String getChaine() {
    return chaine;
}

public void setChaine(String chaine) {
    this.chaine = chaine;
}
}

HTML Code goes as below:

<div class="gt-form gt-content-box"> 
    <h:inputText  value="#{backTheme.chaine}" />
    <h:form >        
     <a4j:htmlCommandLink actionListener="#{backTheme.sayHello}" value="Download"/>
    </h:form>

RinoTom
  • 2,278
  • 2
  • 26
  • 40
daly
  • 43
  • 1
  • 1
  • 9

2 Answers2

2

When a form is submitted, only the data contained in the form will be submitted. However, your input component is outside the form, so its value would not be taken in the form submit. The input component should go in the same form as the command button/link if you want to send its value to the server as well.

<h:form>        
  <h:inputText value="#{backTheme.chaine}" />
  <a4j:htmlCommandLink actionListener="#{backTheme.sayHello}" value="Download"/>
</h:form>

Unrelated to the concrete problem, I'm not sure what the concrete functional requirement of this all is, but I would only warn that it's not possible to download individual files using ajax. Your command link has namely the label "download" which suggests that you're in your real code attempting to download a file. Perhaps this is just carelessness, but you never know; just sayin'. If that's indeed the case, replace the <a4j:htmlCommandLink> by <h:commandLink> in order to achieve a successful file download. See also How to provide a file download from a JSF backing bean?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
1

your inputText needs to be in the form.

user1598246
  • 118
  • 6