I have a problem with updating graphical image from the SelectOneListbox. What I would like to do is, when user selects an item in SelectOneListbox I would like to update image on the page in different component.
I'm trying to use Ajax for this, however even the ajax request is leaving web browser, it doesn't update the component. It passes through all phases Entering JSF Phase: RESTORE_VIEW 1 ... RENDER_RESPONSE 6 Unfortunately it doesn't stop at listener or it doesn't set value of the component to actual value. It reaches converter correctly and do conversion of the value, but that's it. Then no setting of attribute of 'editor' bean.
Here is image for better imagination :)
When I get response in my web browser it says:
<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>
Managed 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{};
}
Converter (with correct implementation, skipped here)
@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 log:
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
I'm using:
- 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
Thanks a lot!