[JBoss Seam] - problems with refreshing view after entity change
by przadka
Hello,
I am a seam beginner and after 3 weeks of evaluation I am totally impressed by it. Right now I am developing a test application and I came across a problem which seems very easy but I coudnt find any solution on the forum.
What I have is a view with a form which displays entity beans (the view file was generated by seam-gen and modified). In the form I have a link which is binded to a session bean action. In the session bean I change the currently displayed entity and than redirect back to the same view page.
And now the problem: althought the entity is correctly changed (which can be seen in the database) the change cannot be seen in the view after we are done with the session bean.
When I navigate to some other page and back to the view I can see changes so it has definately something do to with page refreshing.
Can anyone help?
And here is my code, if anyone is interested
entity bean Research.java:
| @Entity
| public class Research implements Serializable {
|
| private static final long serialVersionUID = 7974073555607550091L;
| private Long id;
| private String name;
| private Client client;
|
| private String researcherDescription;
| private String dataTableName;
| private String description;
| private boolean active;
|
| private Date dateCreated;
|
| private ResearchConfiguration researchConfiguration;
|
| private String dataFileName;
| private InputStream dataFileData;
|
| public Research() {
| researchConfiguration = new ResearchConfiguration();
| this.dateCreated = new Date(System.currentTimeMillis());
| }
|
| @Id
| @GeneratedValue
| public Long getId() {
| return id;
| }
|
| public void setId(Long id) {
| this.id = id;
| }
|
| @Length(max = 20)
| @Column(unique=true)
| public String getName() {
| return name;
| }
|
| public void setName(String name) {
| this.name = name;
| }
|
| @ManyToOne
| public Client getClient() {
| return client;
| }
|
| public void setClient(Client client) {
| this.client = client;
| }
|
| public String getResearcherDescription() {
| return researcherDescription;
| }
|
| public void setResearcherDescription(String researcherDescription) {
| this.researcherDescription = researcherDescription;
| }
|
| @Column(unique=true)
| public String getDataTableName() {
| return dataTableName;
| }
|
| public void setDataTableName(String dataTableName) {
| this.dataTableName = dataTableName;
| }
|
| public String getDescription() {
| return description;
| }
|
| public void setDescription(String description) {
| this.description = description;
| }
|
| @NotNull
| public boolean isActive() {
| return active;
| }
|
| public void setActive(boolean active) {
| this.active = active;
| }
|
| public Date getDateCreated() {
| return dateCreated;
| }
|
| public void setDateCreated(Date dateCreated) {
| this.dateCreated = dateCreated;
| }
|
| @OneToOne(cascade = CascadeType.ALL)
| public ResearchConfiguration getResearchConfiguration() {
| if (researchConfiguration == null) {
| researchConfiguration = new ResearchConfiguration();
| }
| return researchConfiguration;
| }
|
| public void setResearchConfiguration(
| ResearchConfiguration researchConfiguration) {
| this.researchConfiguration = researchConfiguration;
| }
|
|
| public String getDataFileName() {
| return dataFileName;
| }
|
| public void setDataFileName(String dataFileName) {
| this.dataFileName = dataFileName;
| }
|
| @Transient
| public InputStream getDataFileData() {
| return dataFileData;
| }
|
| public void setDataFileData(InputStream dataFileData) {
| this.dataFileData = dataFileData;
| }
|
|
| public boolean isDataFileSet(){
| return dataFileName!=null;
| }
| public void setDataFileSet(boolean dataFileSet){
|
| }
|
| }
|
|
|
the session bean ResearchManagerBean.java:
| @Stateful
| @Name("researchManager")
| public class ResearchManagerBean implements ResearchManager {
|
| @Logger
| private Log log;
|
| @In
| FacesMessages facesMessages;
|
| @In(required = false) @Out
| Research research;
|
| @PersistenceContext
| private EntityManager em;
|
| @Destroy
| @Remove
| public void destroy() {
| }
|
| @Override
| @Begin(join = true)
| public String selectResearch(Research research) {
| if (research == null){
| log.info("Research object is null! Cannot select!");
| return null;
| }
| else
| research = em.merge(research);
| return "research";
| }
|
| @Override
| @End
| public String removeData(Research research) {
| if (research == null){
| log.info("Research object is null! Cannot remove!");
| return null;
| }
| else {
| research = em.merge(research);
| em.createNativeQuery("DROP TABLE `"+research.getDataTableName()+"`").executeUpdate();
| log.info("Table "+research.getDataTableName()+" dropped");
| log.info("Removing data from research!");
| research.setDataFileData(null);
| research.setDataFileName(null);
| research.setDataFileSet(false);
| research.setDataTableName(null);
| facesMessages
| .add("Data removed");
| em.persist(research);
| em.flush();
| return "removed";
| }
| }
|
| @End
| public String addDataFile() {
|
| if (research == null){
| log.info("Research null! Something bad happened...");
| return null;
| }
| else {
| em.merge(research);
| log
| .info("New data set for #{research.name} : #{research.dataFileName}");
| facesMessages
| .add("New data set for #{research.name} : #{research.dataFileName}");
| return "dataadded";
|
| }
| }
|
| public Research getResearch() {
| return research;
| }
|
| public void setResearch(Research research) {
| this.research = research;
| }
|
| }
|
the view research.xhtml:
| <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
| "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
| <ui:composition xmlns="http://www.w3.org/1999/xhtml"
| xmlns:s="http://jboss.com/products/seam/taglib"
| xmlns:ui="http://java.sun.com/jsf/facelets"
| xmlns:f="http://java.sun.com/jsf/core"
| xmlns:h="http://java.sun.com/jsf/html"
| xmlns:rich="http://richfaces.ajax4jsf.org/rich"
| template="layout/template.xhtml">
|
| <ui:define name="body">
|
| <h:messages globalOnly="true" styleClass="message" />
|
| <h:form id="researchForm">
|
| <rich:panel>
| <f:facet name="header">research</f:facet>
|
| <s:decorate id="nameDecoration" template="layout/edit.xhtml">
| <ui:define name="label">Name</ui:define>
| <h:inputText id="name" required="true"
| value="#{research.name}" />
| </s:decorate>
|
| <s:decorate id="clientDecoration" template="layout/edit.xhtml">
| <ui:define name="label">Client:</ui:define>
| <h:selectOneMenu value="#{research.client}"
| required="true" id="client">
| <s:selectItems value="#{clientList.resultList}" var="client"
| label="#{client.name}" noSelectionLabel="Please Select..." />
| <s:convertEntity />
| </h:selectOneMenu>
| </s:decorate>
|
| <s:decorate id="descriptionDecoration" template="layout/edit.xhtml">
| <ui:define name="label">Description:</ui:define>
| <h:inputTextarea id="description" rows="5" cols="65"
| value="#{research.description}" />
| </s:decorate>
|
| <s:decorate id="activeDecoration" template="layout/edit.xhtml">
| <ui:define name="label">Is active:</ui:define>
| <h:selectBooleanCheckbox id="active" required="true"
| value="#{research.active}" />
| </s:decorate>
|
| <s:decorate id="researcherDescriptionDecoration"
| template="layout/edit.xhtml">
| <ui:define name="label">Researcher description:</ui:define>
| <h:inputTextarea id="researcherDescription" rows="5" cols="65"
| value="#{research.researcherDescription}" />
| </s:decorate>
|
| <s:decorate id="dataFileNameDecoration" template="layout/edit.xhtml">
| <ui:define name="label">Used data file name:</ui:define>
| <h:inputText id="dataFileName" immediate="true" enabled="false"
| value="#{research.dataFileName}" disbled="true" readonly="true"/>
| <h:commandLink id="addDataFile" value="Add data >>"
| action="#{researchManager.selectResearch(research)}"
| immediate="true" rendered="#{!research.dataFileSet}"/>
| <h:commandLink id="removeDataFile" value="Remove data >>"
| action="#{researchManager.removeData(research)}"
| immediate="true" rendered="#{research.dataFileSet}" />
| </s:decorate>
|
| <div style="clear: both" />
|
| </rich:panel>
|
| <div class="actionButtons"><h:commandButton id="save"
| value="Save" action="#{researchHome.persist}"
| rendered="#{!researchHome.managed}" /> <h:commandButton id="update"
| value="Save" action="#{researchHome.update}"
| rendered="#{researchHome.managed}" /> <h:commandButton id="delete"
| value="Delete" action="#{researchHome.remove}"
| rendered="#{researchHome.managed}" /> <s:button propagation="end"
| id="done" value="Done" view="/researchList.xhtml" /></div>
|
| </h:form>
|
| </ui:define>
|
| </ui:composition>
|
|
and the pages.xml
| <!DOCTYPE pages PUBLIC
| "-//JBoss/Seam Pages Configuration DTD 1.2//EN"
| "http://jboss.com/products/seam/pages-1.2.dtd">
|
| <pages no-conversation-view-id="/home.xhtml"
| login-view-id="/login.xhtml">
|
| <page view-id="*">
| <navigation>
| <rule if-outcome="home">
| <redirect view-id="/home.xhtml" />
| </rule>
| </navigation>
| </page>
|
| <page view-id="/addData.xhtml">
|
| <navigation from-action="#{researchManager.addDataFile}">
| <rule if-outcome="dataadded">
| <end-conversation />
| <redirect view-id="/research.xhtml">
| <param name="researchId"
| value="#{researchManager.research.id}" />
| </redirect>
| </rule>
| </navigation>
|
| </page>
|
|
| <page view-id="/research.xhtml">
|
| <navigation
| from-action="#{researchManager.removeData(research)}">
| <end-conversation />
| <redirect view-id="/research.xhtml">
| <param name="researchId"
| value="#{researchManager.research.id}" />
| </redirect>
| </navigation>
|
| <navigation
| from-action="#{researchManager.selectResearch(research)}">
| <redirect view-id="/addData.xhtml" />
| </navigation>
|
| </page>
|
|
| <exception
| class="org.jboss.seam.framework.EntityNotFoundException">
| <redirect view-id="/error.xhtml">
| <message>Not found</message>
| </redirect>
| </exception>
|
| <exception class="javax.persistence.EntityNotFoundException">
| <redirect view-id="/error.xhtml">
| <message>Not found</message>
| </redirect>
| </exception>
|
| <exception class="javax.persistence.OptimisticLockException">
| <end-conversation />
| <redirect view-id="/error.xhtml">
| <message>
| Another user changed the same data, please try again
| </message>
| </redirect>
| </exception>
|
| <exception class="org.jboss.seam.security.AuthorizationException">
| <redirect>
| <message>You don't have permission to do this</message>
| </redirect>
| </exception>
|
| <exception class="org.jboss.seam.security.NotLoggedInException">
| <redirect view-id="/login.xhtml">
| <message>Please log in first</message>
| </redirect>
| </exception>
|
| <exception>
| <redirect view-id="/error.xhtml">
| <message>Unexpected error, please try again</message>
| </redirect>
| </exception>
|
| </pages>
|
best regards!
michal przadka
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4079506#4079506
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4079506
17Â years, 2Â months
[JBoss Seam] - @In-jection fails on randomly applicaion scoped components w
by gothmog
Hi,
I have two seam application scoped components, one holds an internal list which is added to by the other. So..
| @Name("entryGate")
| @Scope(ScopeType.APPLICATION)
| public class EXAccessPoint {
|
| @Logger Log log;
| @In EntityManager em;
| List<EntryExit> exs = new ArrayList<EntryExit>();
| ...
| public void add(String pid, Date time, boolean isExit) {
| log.info("add():pid=" + pid + ";time=" + time + ";em=" + em);
| EntryExit ex = null;
| ...
| exs.add(0, ex);
| }
|
and the other uses this component (via @In) to add to the list
| @Name("entrySimulation")
| @Scope(ScopeType.APPLICATION)
| public class EXSimulation {
|
| @Logger Log log;
| @In(create=true) EXAccessPoint entryGate;
| ...
| public void simulate() {
| ...
| entryGate.addEntry("PID" + (int)((Math.random() * 5) + 1), current.getTime());
| }
|
|
Now here comes the tricky bit. Two web pages are operating using <a:poll>. the first polls EXSimulation every ten seconds to simulate another series of additions to the list held by EXAccessPoint. The other polls every 1 sec to read the contents of the list from EXAccessPoint and renders them to the UI. What I'm trying to do is simulate people arriving at an EXAccessPoint and have the UI in 'near' real time display them in a security booth (hence all the Ajax)
In this scenario, every so often (but predictable) em is NOT @In-jected into EXAccessPoint when EXAccessPoint is itself injected into EXSimulation. I get a NullPointerException and my logs show:
| 20:53:16,533 INFO [EXAccessPoint] add():pid=PID1;time=Thu Aug 30 20:53:25 NZST 2007;em=org.jboss.seam.persistence.EntityManagerProxy@9fa638
| 20:53:16,533 INFO [EXAccessPoint] add():pid=PID1;time=Thu Aug 30 20:53:20 NZST 2007;em=org.jboss.seam.persistence.EntityManagerProxy@9fa638
| ...
| 20:53:17,023 INFO [EXAccessPoint] add():pid=PID5;time=Thu Aug 30 20:53:26 NZST 2007;em=org.jboss.seam.persistence.EntityManagerProxy@9fa638
| ...
| 20:53:39,749 INFO [EXAccessPoint] add():pid=PID2;time=Thu Aug 30 20:53:46 NZST 2007;em=null
| 20:53:39,751 FATAL [application] /cgsimulateentry.xhtml @61,102 action="#{entrySimulation.simulate}": java.lang.NullPointerException
|
There is concurrency and @In-jection going on here with an application scoped component, this is probably not the right design as the two threads are potentially @In-jecting a different em proxy and changing the reference to the em while the other thread is midway through using the component.
What is the design pattern that should be used here to avoid the changing of an @In-jected em on an application scoped component across multiple threads?
Thanks
Troy
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4079500#4079500
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4079500
17Â years, 2Â months
[JBoss Portal] - how to enable drag and drop on a new portal
by tellarsrinivasprabhu
hi
I am using jboss portal 2.6.1 . i created new portal from management portal available for admin user. Then i created a new page called portfolio. Later i added some portlets to this page. Now how do i enable drag and drop for these portlets.
I added following entry to my default.xml
<deployment>
| <if-exists>overwrite</if-exists>
| <context>
| <context-name>myportal</context-name>
| <properties>
| <!--
| | Set the dnd property
| --> <property>
| <name>theme.dyna.dnd_enabled</name>
| <value>true</value>
| </property>
| <!--
| | Set the partial refresh property
| --> <property>
| <name>theme.dyna.partial_refresh_enabled</name>
| <value>true</value>
| </property>
|
| <!-- Control policy config -->
| <property>
| <name>control.portal.access_denied</name>
| <value>ignore</value>
| </property>
| </properties>
| </context>
| </deployment>
|
thanks,
tellarsrinivasprabhu
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4079497#4079497
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4079497
17Â years, 2Â months
[JBoss jBPM] - [JBPM 3.2.1] Updating Deployed Version of Process
by dleerob
Hi,
When deploying, for example, the websale process definition, along with all it's files:
forms.xml, form.create.xhtml, form.fix.xhtml etc...
It will initially deploy the process as "version 1". If users now start this process, and you then realise there is a problem with the websale process, and you need to change one of the forms, lets say "form.fix.xhtml". You then deploy the changes, which will create a "version 2" of the process. The current processes in action will still be using "version 1" files etc, as expected, and any NEW process instances will use the "version 2" files. My question is: what if I need to make changes to the original "version 1" files? Perhaps there is an error which doesn't allow users to go any further in the flow, and you need to make a change to the current version files. How would one do that?
If anyone has some ideas, or knows how this is done, I would appreciate it.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4079496#4079496
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4079496
17Â years, 2Â months