我有这个表单,有170个单独的文本框,在会话范围的bean中有值.需要仅在组件具有特定CSS类时提交值.
我最初接近这个的方法是在UPDATE_MODEL_VALUES创建一个PhaseListener并在那里测试CSS类.如果该类是受影响的类,我将组件的值设置为null.然后在前端,我使用通用JavaScript方法切换焦点类.这意味着每个组件的更改我只需要添加:
... styleClass="examfieldgrey" onfocus="whiteField(this);"
Run Code Online (Sandbox Code Playgroud)
鉴于我需要改变多少组件,这是一种很好的方式.
这工作正常,直到我重新考虑我的电子表格以使用多个h表格标签.现在CSSclass正在切换前端,但是没有保存此更改.阶段监听器正在获得旧班级.
我认为这显然与我在jQuery/javascript中切换类有关.我想知道的是:
很抱歉,如果这是一个显而易见的问题,我对JSF生命周期仍然有点青睐.
我正在使用JSF 2.0 MyFaces
这里的参考是我的表单上需要过滤的组件的示例:
<h:inputTextarea
id="inputVal"
styleClass="midTextArea examfieldgrey"
onfocus="whiteField(this);"
value="#{bean.form.val}"/>
Run Code Online (Sandbox Code Playgroud)
其中"examfieldgrey"是我在确定是否要阻止组件时测试的类.
和whiteField方法:
function whiteField(field){
if(! jQuery(field).hasClass("examfieldgrey")){
return;
}
jQuery(field).removeClass("examfieldgrey");
jQuery(field).addClass("examfieldwhite");
}
Run Code Online (Sandbox Code Playgroud)
我的阶段监听器在阶段方法之前我过滤:
// TODO: make whatever mode allows ghosting to be configurable outside of
// the system (perhaps in the config file)
/**
* Before the model is updated, test each component's CSS on the form. If the
* CSS style is 'examfieldgrey' set the value to null so …Run Code Online (Sandbox Code Playgroud)