Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
编码JSF、commandButton和x27;按代码列出的导航操作结果_Jsf_Facelets_Ajax4jsf - Fatal编程技术网

编码JSF、commandButton和x27;按代码列出的导航操作结果

编码JSF、commandButton和x27;按代码列出的导航操作结果,jsf,facelets,ajax4jsf,Jsf,Facelets,Ajax4jsf,我尝试修复如下无法管理的代码: <a4j:commandButton action="dia_ok" actionListener="#{...}" ajaxSingle="true" .../> 我通过将按钮绑定到ManagedBean并将所有属性交换到Java代码来修复它,因此我只有: <a4j:commandButton binding="#{...}"/> 我成功地编码了setAjaxSingle(true)和actionListener属性,但编码a

我尝试修复如下无法管理的代码:

<a4j:commandButton action="dia_ok" actionListener="#{...}" ajaxSingle="true" .../>

我通过将按钮绑定到ManagedBean并将所有属性交换到Java代码来修复它,因此我只有:

<a4j:commandButton binding="#{...}"/>

我成功地编码了setAjaxSingle(true)和actionListener属性,但编码action属性失败


我的问题是:如何在method按钮处指定操作结果。setActionExpression()只允许MethodExpression的参数,而不允许String?

您只需创建一个
MethodExpression
,其值为
“dia_ok”
,返回类型为
String
。表达式不一定引用
“#{bean.action}”
或其他内容

例如

private静态方法表达式createMethodExpression(字符串表达式,类returnType){
FacesContext FacesContext=FacesContext.getCurrentInstance();
返回facesContext.getApplication().getExpressionFactory().createMethodExpression(
facesContext.getELContext(),表达式,返回类型,新类[0]);
}

我只是看不到,当您以这种方式将视图混合到模型中时,它如何使代码更易于管理。也许您需要编写一些通用的约定,如何对属性进行排序/组织,以便更好地进行管理?例如,首先是
id
,然后是
value
,等等,然后与此约定保持一致。

您只需创建一个
MethodExpression
,其值为
“dia_ok”
,返回类型为
String
。表达式不一定引用
“#{bean.action}”
或其他内容

例如

private静态方法表达式createMethodExpression(字符串表达式,类returnType){
FacesContext FacesContext=FacesContext.getCurrentInstance();
返回facesContext.getApplication().getExpressionFactory().createMethodExpression(
facesContext.getELContext(),表达式,返回类型,新类[0]);
}

我只是看不到,当您以这种方式将视图混合到模型中时,它如何使代码更易于管理。也许您需要编写一些通用的约定,如何对属性进行排序/组织,以便更好地进行管理?例如,代码> ID 第一,然后<代码>值>代码>等,然后与此约定一致。

为什么你认为你的修复是一个改进?(我听到的关于组件绑定的最常见的建议是不惜一切代价避免它们……)敏捷编程的一个目标不是一个基于架构的代码审查吗?命令按钮使用8-12个属性,它的IMO不管理。为什么你认为你的修正是一个改进?(我听到的关于组件绑定的最常见的建议是不惜一切代价避免它们……)敏捷编程的一个目标不是一个基于架构的代码审查吗?commandButton使用了8-12个以上的属性,它的imo不可管理。我不使用mvc模式,我编写了一个通用的CRUD curator类,我的hibernate entitybeans(事务性长寿命hibernatesession)继承了jsf selectitem。这是一个复杂的原型,抛弃了所有重要的经典oop设计。我不使用mvc模式,我编写了一个通用的CRUD curator类,我的hibernate entitybeans(事务性长寿命hibernatesession)继承了jsf selectitem。这是一个复杂的原型,抛弃了所有重要的经典oop设计。
button.setActionExpression(createMethodExpression("dia_ok", String.class));
private static MethodExpression createMethodExpression(String expression, Class<?> returnType) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    return facesContext.getApplication().getExpressionFactory().createMethodExpression(
        facesContext.getELContext(), expression, returnType, new Class[0]);
}