Ajax没有设置bean值并且达到了监听器

时间:2018-01-22 22:17:57

标签: jsf primefaces jsf-2.2

我在从SelectOneListbox更新图形图像时遇到问题。我想做的是,当用户在SelectOneListbox中选择一个项目时,我想在不同组件的页面上更新图像。

我正在尝试使用Ajax,但即使ajax请求离开Web浏览器,它也不会更新组件。它遍历所有阶段进入JSF阶段:RESTORE_VIEW 1 ... RENDER_RESPONSE 6 不幸的是,它并没有停留在监听器上,也没有将组件的值设置为实际值。 它正确到达转换器并进行转换,但就是这样。然后没有设置'editor'bean的属性。

这是更好想象的图像:)

enter image description here

当我在网络浏览器中收到回复时,它说:

<partial-response id="j_id1">
    <changes>
        <update id="j_id1:javax.faces.ViewState:0">2751554428361535891:1425762350197262148</update>
        <extension ln="primefaces" type="args">{"validationFailed":true}</extension>
    </changes>
</partial-response>

托管Bean

@ViewScoped
@ManagedBean(name = "editor")
public class EditorView {

    @ManagedProperty(value = "#{localizationService}")
    private LocalizationService localizationService;
    private LangFlag selectedLanguage;

    public void languageUpdated(AjaxBehaviorEvent event){
        System.out.println(event);
    }

    public void setSelectedLanguage(LangFlag selectedLanguage) {}
    public String getSelectedLanguage{};
}

转换器(正确实施,请跳过此处)

@FacesConverter
public class LanguageConverter implements Converter, Serializable {

    @Override
    public Object getAsObject(FacesContext fc, UIComponent uic, String value) {}

    @Override
    public String getAsString(FacesContext fc, UIComponent uic, Object object) {}

}

edit.xhtml

<h:panelGroup id="countrySelectFlagPanel">
    <h:form id="translation_editor">
        <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
        <p:graphicImage id="chooseLangBtn" width="22px" height="22px"
    alt="#{t.lang.englishName}" 
    library="main" name="/images/flags/var/#{editor.selectedLanguage.country.alpha2}.svg"/>
        <p:overlayPanel id="langPanel" for="chooseLangBtn" 
    showCloseIcon="true" dismissable="true"
    widgetVar="langOverlayPanel">
            <p:selectOneListbox id="langSelect" value="#{editor.selectedLanguage}" converter="#{languageConverter}" 
            var="t" filter="true" filterMatchMode="startsWith" 
            onclick="PF('langOverlayPanel').hide(); alert($('#translation_editor\\:langSelect_input').val())"
            valueChangeListener="#{editor.languageUpdated}">
                <f:selectItems value="#{editor.langFlagMappings}" var="l10n" 
           itemLabel="#{l10n.lang.englishName} (#{l10n.lang.nativeName})" 
           itemValue="#{l10n}"/>
                <p:ajax process="@this" listener="#{editor.languageUpdated}"  />
                <p:column><h:graphicImage width="22px" alt="#{t.lang.englishName}" 
                      library="main" name="/images/flags/var/#{t.country.alpha2}.svg"/></p:column>
                <p:column><h:outputText value="#{t.lang.englishName}" /></p:column>
            </p:selectOneListbox>
        </p:overlayPanel>
    </h:form>
</h:panelGroup>

Tomcat日志:

2018-01-23 20:25:40 DEBUG FilterChainProxy:328 - /editor.xhtml at position 1 of 13 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
2018-01-23 20:25:40 DEBUG FilterChainProxy:328 - /editor.xhtml at position 2 of 13 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
2018-01-23 20:25:40 DEBUG FilterChainProxy:328 - /editor.xhtml at position 3 of 13 in additional filter chain; firing Filter: 'HeaderWriterFilter'
2018-01-23 20:25:40 DEBUG HstsHeaderWriter:130 - Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@14218bd6
2018-01-23 20:25:40 DEBUG FilterChainProxy:328 - /editor.xhtml at position 4 of 13 in additional filter chain; firing Filter: 'CsrfFilter'
2018-01-23 20:25:40 DEBUG FilterChainProxy:328 - /editor.xhtml at position 5 of 13 in additional filter chain; firing Filter: 'LogoutFilter'
2018-01-23 20:25:40 DEBUG AntPathRequestMatcher:157 - Checking match of request : '/editor.xhtml'; against '/logout'
2018-01-23 20:25:40 DEBUG FilterChainProxy:328 - /editor.xhtml at position 6 of 13 in additional filter chain; firing Filter: 'UsernamePasswordAuthenticationFilter'
2018-01-23 20:25:40 DEBUG AntPathRequestMatcher:157 - Checking match of request : '/editor.xhtml'; against '/login'
2018-01-23 20:25:40 DEBUG FilterChainProxy:328 - /editor.xhtml at position 7 of 13 in additional filter chain; firing Filter: 'BasicAuthenticationFilter'
2018-01-23 20:25:40 DEBUG FilterChainProxy:328 - /editor.xhtml at position 8 of 13 in additional filter chain; firing Filter: 'RequestCacheAwareFilter'
2018-01-23 20:25:40 DEBUG FilterChainProxy:328 - /editor.xhtml at position 9 of 13 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
2018-01-23 20:25:40 DEBUG FilterChainProxy:328 - /editor.xhtml at position 10 of 13 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
2018-01-23 20:25:40 DEBUG FilterChainProxy:328 - /editor.xhtml at position 11 of 13 in additional filter chain; firing Filter: 'SessionManagementFilter'
2018-01-23 20:25:40 DEBUG FilterChainProxy:328 - /editor.xhtml at position 12 of 13 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
2018-01-23 20:25:40 DEBUG FilterChainProxy:328 - /editor.xhtml at position 13 of 13 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
2018-01-23 20:25:40 DEBUG AntPathRequestMatcher:157 - Checking match of request : '/editor.xhtml'; against '/javax.faces.resource/**'
2018-01-23 20:25:40 DEBUG AntPathRequestMatcher:157 - Checking match of request : '/editor.xhtml'; against '/pages/secure/**'
2018-01-23 20:25:40 DEBUG AntPathRequestMatcher:157 - Checking match of request : '/editor.xhtml'; against '/pages/unsecure/**'
2018-01-23 20:25:40 DEBUG FilterSecurityInterceptor:219 - Secure object: FilterInvocation: URL: /editor.xhtml; Attributes: [permitAll]
2018-01-23 20:25:40 DEBUG AffirmativeBased:66 - Voter: org.springframework.security.web.access.expression.WebExpressionVoter@b29fd57, returned: 1
2018-01-23 20:25:40 DEBUG FilterSecurityInterceptor:243 - Authorization successful
2018-01-23 20:25:40 DEBUG FilterSecurityInterceptor:256 - RunAsManager did not change Authentication object
2018-01-23 20:25:40 DEBUG FilterChainProxy:313 - /editor.xhtml reached end of additional filter chain; proceeding with original chain
2018-01-23 20:25:40 DEBUG RequestLoggingPhaseListener:43 - Entering JSF Phase: RESTORE_VIEW 1
2018-01-23 20:25:40 DEBUG RequestLoggingPhaseListener:43 - Entering JSF Phase: RESTORE_VIEW 1
2018-01-23 20:25:40 DEBUG RequestLoggingPhaseListener:43 - Entering JSF Phase: APPLY_REQUEST_VALUES 2
2018-01-23 20:25:40 DEBUG RequestLoggingPhaseListener:43 - Entering JSF Phase: APPLY_REQUEST_VALUES 2
2018-01-23 20:25:40 DEBUG RequestLoggingPhaseListener:43 - Entering JSF Phase: PROCESS_VALIDATIONS 3
2018-01-23 20:25:40 DEBUG RequestLoggingPhaseListener:43 - Entering JSF Phase: PROCESS_VALIDATIONS 3
2018-01-23 20:25:40 DEBUG DefaultListableBeanFactory:255 - Returning cached instance of singleton bean 'localizationService'
2018-01-23 20:25:40 DEBUG RequestLoggingPhaseListener:43 - Entering JSF Phase: RENDER_RESPONSE 6
2018-01-23 20:25:40 DEBUG RequestLoggingPhaseListener:43 - Entering JSF Phase: RENDER_RESPONSE 6
2018-01-23 20:25:40 DEBUG ExceptionTranslationFilter:121 - Chain processed normally
2018-01-23 20:25:40 DEBUG SecurityContextPersistenceFilter:119 - SecurityContextHolder now cleared, as request processing completed

我正在使用:

  • spring.security.version:5.0.0.RELEASE
  • spring.version:5.0.2
  • spring.binding.version:1.0.6
  • spring.webflow.version:2.5.0.BUILD-SNAPSHOT
  • primefaces.version:6.1
  • primefaces.themes.version:1.0.10
  • jsf.version:2.2.15
  • servlet.api.version:2.5
  • jstl.version:1.2
  • javax-faces.version:2.3.3
  • jsp-api.version:2.2

非常感谢!

0 个答案:

没有答案