<a4j:actionparam send value alway null
I have such code
<a4j:region>
<h:inputText label="User" id="user" size="30" value="#{bean2.val1}" required="true" >
<a4j:support event="onblur" action="#{bean.action}" reRender="outputName" bypassUpdates="true">
<a4j:actionparam name="user" assignTo="#{bean.user}" value="#{user}" />
</a4j:support>
</h:inputText>
</a4j:region>
<h:message for="user"/>
And my bean class like this :
private String user;
public String getUser() {
System.out.println("user=="+user);
return user;
}
public void setUser(String user) {
this.user = user;
}
public void action(){
getUser();
}
But every time onblur event occurs, the value of user alway null.
I just want to the valu开发者_JAVA百科e of user send to the bean when onblur event occur. So I can get value of user. Anyone can help me ? (I'm sorry for my English)
Well, the value of #{user}
is null always - there is no such thing in the request attributes. You can remove the <a4j:actionparam
whatsoever and just leave the <a4j:support
, and preferably put ajaxSignle=true
. This will first submit the value of the text input and then execute the action (at least it should). Also put immediate=true
to bypass validation.
After you comment, I think you could also try:
<a4j:actionparam name="user" assignTo="#{bean.user}" value="#{bean2.val1}" />
Or do the assignment in the action
method manually. Just inject the second bean into the first one (assuming you use a DI framework)
As already pointed out, the value will be always null since it is never se. If you want the value you can inject the managed property val1 from bean2 to bean.
Using ManagedProperty:
class Bean {
@ManagedProperty{value="#{bean2.val}"
private user;
}
The value will be automatically injected.
精彩评论