JSF + Seam + a4j Triggering one component ajax fro

2019-09-02 13:08发布

问题:

I wanted to ask just what title says: say we have a inputtext and a button. Well, I wanted to submit an ajax request in the inputtext when button is clicked.

for example, from the inputtext perspective, I want to achive something like this:

<h:inputtext>
   <a4j:support event="button.onclick"/>
<h:inputtext>
<h:button id="button">

or, from the button perspective:

<h:inputtext id="input"/> 
<h:button id="button">
   <a4j:support event="onclick" action="input.submit"/>
</h:button>

Don't know if there exist an easy way to get this done.

thanks in advance!!

回答1:

If you just want a simple form submit, I think both approach are wrong, as long as you put your inputtext and button properly in a form, the form will automatically submit whatever you have in this form including user's input in inputtext when you click the button. There is no need to do something like input.submit yourself. (and it's not correct, either)

For the following case, you will see the setInputValue() of managed bean being invoked when you click your button.

<h:inputtext id="input" value=#{bean.inputValue}/>

public void setInputValue(String inputValue){
    this.inputValue = inputValue;
}


回答2:

Try using

Richfaces Region component to limit your request to diffrent regions.

http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/a4j_region.html



回答3:

I finally get this done by means of <a4j:jsFunction> a4j:jsFunction



标签: ajax jsf seam