You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Simon Kitching (JIRA)" <de...@myfaces.apache.org> on 2008/08/05 21:38:44 UTC

[jira] Commented: (ORCHESTRA-28) Conversation (Access) is lost when jsf validation fails

    [ https://issues.apache.org/jira/browse/ORCHESTRA-28?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12620015#action_12620015 ] 

Simon Kitching commented on ORCHESTRA-28:
-----------------------------------------

Ok, looks like the issue is reasonably simple. But not one that had occurred to me before!

An access-scoped bean is discarded unless it is referenced from a page. But in this particular page, the only reference to the bean is from the "value" property of a component, or the "action" property of a command component. And when validation fails, the "value" property never gets accessed (update model does not occur), and the action does not get invoked, so the bean is not accessed.

If you had any component in this page whose "rendered" attribute pointed at the controller bean, or any output component whose value was fetched from the controller bean then there would be no problem. However when only input and command components reference the controller, then validation failure will indeed cause this unexpected behaviour.

My initial thought is that if validation fails (and no navigation occurs), then orchestra should probably skip the checks of access-scoped beans.
Or maybe orchestra should only check access-scoped beans after the first render of a new view.
I'll try to find time to think about that in more detail tomorrow.

As a workaround for now, I suggest adding this somewhere in your page:
  <h:outputText value="whatever" rendered="#{categoryController.class == null}"/>
The EL expression always evaluates to false, so there is no effect on the page. However the side-effect of evaluating that expression is to cause the bean to be marked as "accessed".

Thanks for reporting this

> Conversation (Access) is lost when jsf validation fails
> -------------------------------------------------------
>
>                 Key: ORCHESTRA-28
>                 URL: https://issues.apache.org/jira/browse/ORCHESTRA-28
>             Project: MyFaces Orchestra
>          Issue Type: Bug
>          Components: Conversation
>    Affects Versions: 1.1
>            Reporter: Stefan Glase
>            Priority: Critical
>
> I am loosing my conversation the bean CategoryController is in, when required-validation in the view fails. 
> Without further investigation it looks like it can be explained in the following way: Orchestra uses a proxy-class to notice calls to bean-methods,-getters or -setters while in the conversation and when there is no direct access to the bean from the view, the access scope will be lost. 
> That is fine in standard cases but when calls only go to the extending class this behaviour should be considered wrong.
> My ugly workaround can be seen in the bottom of the CategoryController implementation and the view, where I fetch this fake-property just to have a call to a bean-method.
> ***************************************************************************************************************************
> Class: CategoryController
> ***************************************************************************************************************************
> @Controller
> @Scope("conversation.access")
> public class CategoryController extends AbstractCrudController<Category> {
>     private CategoryService categoryService;
>     @Resource
>     public void setCategoryService(CategoryService categoryService) {
>         this.categoryService = categoryService;
>     }
>     @Override
>     protected CategoryService getService() {
>         return this.categoryService;
>     }
>     /**
>      * Bug: Orchestra invalidiert eine Klasse X, welche eine Klasse Y erweitert, wenn in einem
>      * Request-Zyklus lediglich Zugriffe auf Methoden und Properties von Y erfolgt sind.
>      * 
>      * @return Leerer String
>      */
>     public String getBug() {
>         return "";
>     }
> }
> ***************************************************************************************************************************
> Class: AbstractCrudController
> ***************************************************************************************************************************
> public abstract class AbstractCrudController<T extends PersistentEntity> {
>     private T entity;
>     public T getEntity() {
>         return entity;
>     }
> }
> ***************************************************************************************************************************
> View: categoryEditForm.xhtml
> ***************************************************************************************************************************
>        <h:form>
>             <h:panelGrid columns="3">
>                 <h:outputLabel value="#{msg.category_name}" for="name" />
>                 <h:inputText size="40" id="name" value="#{categoryController.entity.name}"
>                     required="true" />
>                 <h:message for="name" />
>                 <h:outputLabel value="#{msg.category_description}" for="description" />
>                 <h:inputTextarea rows="3" cols="40" id="description"
>                     value="#{categoryController.entity.description}" required="true" />
>                 <h:message for="description" />
>             </h:panelGrid>
>             <h:panelGrid columns="2">
>                 <h:commandButton action="#{categoryController.doSaveEntity}"
>                     value="#{msg.category_save}" />
>             </h:panelGrid>
>             <!-- === Bug === -->
>             <h:outputText value="#{categoryController.bug}" />
>             <!-- === End of Bug === -->
>         </h:form>

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.