English 中文(简体)
如果项目清单在复读之间有所变化,则不使用EL 2.2来通过项目参数吗?
原标题:Can t use EL 2.2 to pass item parameter to bean if list of items changes between refreshes?

I m using EL 2.2 s functionality (with Tomcat 7) to pass parameters (in this case, entire items) from a JSF page to a backing bean. It s proving to be very handy, but I m running into a gigantic problem when the list of items is changed by another user between page refreshes. Here s some example code to help show what I mean:

JSF page:

<ui:repeat var="item" value="#{myBackingBean.listOfItems}">
    <h:panelGrid columns="3">
        <h:outputText value="#{item.name}" />
        <p:commandLink value="(Change name to foo)" action="#{myBackingBean.changeNameToFoo(item)}" />
        <p:commandLink value="(Delete this item)" action="#{myBackingBean.deleteThisItem(item)}" />
    </h:panelGrid>
</ui:repeat>

MyBackingBean.java:

public void changeNameToFoo(Item i) {
    i.setName("foo");
}

public void deleteThisItem(Item i) {
    i.remove();
}

My situation is this: Say the listOfItems returns a list of five Items with the names [1, 2, 3, 4, 5]. Two different users load up this page at the same time. User A immediately deletes item 2, and now sees [1, 3, 4, 5]. User B, who still sees all five items, then tries to change item 3 s name to foo. When his page refreshes, he now sees [1, 3, foo, 5]. Because a user he wasn t even aware of removed the second item in the list, a completely different item than the one he clicked was changed.

我丢失了东西,或者在多个用户进入图像时,这真的是一个显示问题吗?

感谢!

问题回答

If you are allowing multiple users share some resources you have to make sure you handle the situations accordingly. And this applies not only to JSF but for any situations that might have threading issues. I dont know how big your application is but if it is small enough to not create a problem, then i would synchronize the methods that set and get the information from the listOfItems.

正如我说过的那样,你可能会对业绩进行打击,这取决于你是否与业绩相符(当然是你们的用户)。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签