In general DeltaSpike needs to verify, depending on the ClientWindowMode,
if the windowId is valid and sends a redirect.

Please come back if you know exactly where the redirect will be triggered -
AND - check the DS docs.

Am Fr., 5. Feb. 2021 um 15:07 Uhr schrieb DevNews <devn...@safir-wid.de>:

> Hallo,
>
> in our web-application (JSF2.2 with DaltaSpike) we listen in a
> PhaseListener during RESTORE_VIEW on a special url. According to the
> HTTP-Post data we initialize a ViewAccessScoped bean and then redirect to a
> target url using ExternalContext.redirect(targeturl).
>
> This redirect results in two requests to the target url. Both requests
> have different instances of the ViewAccessScoped bean. For this reason the
> initialization data gets lost.
>
>
> How can a redirect be done without having two following requests?
>
>
> Before migrating from JSF1.2 to JSF2.2 and without using DeltaSpike there
> was only one request after redirecting. Threrefore we suppose that this
> effect results from deltaspike and the dswid parameter.
> For this reason we tried to extend the target url like:
>             targeturl + „?dswid=“ + viewaccesscopedbean.getDswid()
> reading the dswid from deltaspike – WindowContext
>
> With this extension of the targeturl the behaviour is no more predictable.
> The redirect sometimes results in two sometimes it results in one request.
>
>
> Here our java-code:
>
>
> public class MyTestPhaseListener implements PhaseListener
> {
> /**
> * ViewAccessScoped Bean
> */
>     @Inject
>     MyVAccBean myVAccBean;
>
>     @Override
>     public void afterPhase(PhaseEvent event)
>     {
>     }
>
>     @Override
>     public void beforePhase(PhaseEvent event)
>     {
> if (event.getPhaseId() == PhaseId.RESTORE_VIEW)
> {
>     ExternalContext extCtx = event.getFacesContext().getExternalContext();
>     HttpServletRequest request = (HttpServletRequest) extCtx.getRequest();
>     String currReqUri = request.getRequestURI();
>     if (currReqUri.indexOf("/initialPage.jsf") > 0)
>     {
> myVAccBean.setValue("some value");
> redirectToTargetUrl(event, "targetPage.jsf");
>     }
> }
>     }
>
>     private void redirectToTargetUrl(PhaseEvent event, String tagretUrl)
>     {
> try
> {
>     String encodedUrl = tagretUrl + "?dswid=" + myVAccBean.geDsWindowId();
>     event.getFacesContext().getExternalContext().redirect(encodedUrl);
> }
> catch (Throwable e)
> {
>     e.printStackTrace();
> }
>     }
>
>     @Override
>     public PhaseId getPhaseId()
>     {
> return PhaseId.ANY_PHASE;
>     }
> }
>
>
>
> Tel:
> E-Mail: devn...@safir-wid.de
> Internet: https://www.safir-wid.de
>
> safir Wirtschaftsinformationsdienst GmbH
> Sitz der Gesellschaft: Möllendorffstr.49, 10367 Berlin
> Geschäftsführer: Thilo Kind
> Registergericht: Amtsgericht Berlin Charlottenburg, HRB 66681
> USt-ID: DE 193584747
>
>
>
>
> --
> This email was Malware checked by UTM 9. http://www.sophos.com
>

Reply via email to