Jsf 2 使用Ajax的HtmlInputText(在支持bean中创建inputtext)
由于非常动态的需求,需要在支持bean中创建一个表。我这样做是成功的 这就是我试图将Ajax添加到输入文本的方式:Jsf 2 使用Ajax的HtmlInputText(在支持bean中创建inputtext),jsf-2,Jsf 2,由于非常动态的需求,需要在支持bean中创建一个表。我这样做是成功的 这就是我试图将Ajax添加到输入文本的方式: HtmlInputText inputText = new HtmlInputText(); // add value and other ValueExpressions AjaxBehavior ajaxBehavior = new AjaxBehavior(); ajaxBehavior.addAjaxBehaviorListener( new AjaxBehaviorLis
HtmlInputText inputText = new HtmlInputText();
// add value and other ValueExpressions
AjaxBehavior ajaxBehavior = new AjaxBehavior();
ajaxBehavior.addAjaxBehaviorListener( new AjaxBehaviorListenerImpl());
inputText.addClientBehavior("focus", ajaxBehavior);
column.getChildren().add(inputText);
public class AjaxBehaviorListenerImpl implements AjaxBehaviorListener {
public void processAjaxBehavior(AjaxBehaviorEvent event) throws AbortProcessingException {
System.out.println("It works");
}
}
侦听器的我的实现:
HtmlInputText inputText = new HtmlInputText();
// add value and other ValueExpressions
AjaxBehavior ajaxBehavior = new AjaxBehavior();
ajaxBehavior.addAjaxBehaviorListener( new AjaxBehaviorListenerImpl());
inputText.addClientBehavior("focus", ajaxBehavior);
column.getChildren().add(inputText);
public class AjaxBehaviorListenerImpl implements AjaxBehaviorListener {
public void processAjaxBehavior(AjaxBehaviorEvent event) throws AbortProcessingException {
System.out.println("It works");
}
}
我遇到的问题是没有触发ajax事件。古老的“什么事也不会发生”。我试着用“聚焦”来代替,同样的结果,也尝试了其他的事件,比如模糊
当我调试源代码时,它看起来好像没有包括在内:
<HtmlInputText disabled="false" id="j_id1" immediate="false" inView="true" localValueSet="false" maxlength="-2147483648" readonly="false" rendered="true" required="false" size="-2147483648" transient="false" valid="true" value=""/>
我也试过这个要点,但都是一样的
使用JSF-2、Tomcat 7、Servlet 3.0和Mojarra 2.1.9
感谢帮助
干杯我的问题是,为什么要通过代码创建自定义组件?只要将
f:ajax
添加到视图的h:inputText
中,JSF就会在您想要的事件发生时设法调用侦听器。您可以创建该表,只要在触发事件时用适当的值填充它即可。在inputText.setId(“foo”)
中为它指定一个固定ID,然后重试。至少,对于非异步(好的,同步)回发,输入/命令组件需要有一个固定的ID,否则JSF无法根据请求参数映射正确地decode()。我并没有把这篇文章作为一个答案,因为我从来没有使用过像这样的ajax行为,因此不能从经验中说话,您的代码可能过于简单。另请参见此相关问题:@XtremeBiker它是动态创建表的一部分。最大的原因是:RichFaces4和JSTL中不支持动态的列数,这导致其他内部错误components@BalusC谢谢你的建议。不起作用,在html源代码中看起来是这样的:我没有使用Rich 4,但自从版本3支持它以来,听起来有些多余。。无论如何,祝你好运,伙计。