0

请你帮助我好吗。我提出了这个请求范围的托管 bean,但是当我单击 sayHello 时,在日志的控制台中它只显示 hello,即使我在字段“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 代码如下:

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

4

2 回答 2

2

提交表单时,只会提交表单中包含的数据。但是,您的输入组件在表单之外,因此不会在表单提交中获取其值。如果您还想将其值发送到服务器,则输入组件应采用与命令按钮/链接相同的形式。

<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?

于 2013-02-25T19:42:52.307 回答
1

your inputText needs to be in the form.

于 2013-02-25T19:43:55.417 回答