• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

collection getting appended on refresh of page

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

I am iterating a arraylist which is returned from a bean. But when everytime i refresh the page it arraylist gets duplicated with existing values.
I am using spring webflow 2.1.

what could be the problem.
[<CODE>]
c:forEach var="alist" items="${results}">


<tr>

<td><cut value='${alist.moduleID}'/></td>
<td><cut value='${alist.name}'/></td>
<td><cut value='${alist.createdbyID}'/></td>
<td></td>


</tr>

</c:forEach>

[</CODE>]


The flow XML contains these entries.
view-state id="listCriteria" view="listModule">
<render-actions>
<bean-action bean="custommod" method="customModLists">
<method-result name="results"/>
</bean-action>
</render-actions>
<transition on="add" to="addModule" />
</view-state>

The method returns a arraylist containing objects . But after refreshing the page the $results gets added again i see, all entries in the database are getting added again. How do i stop this unwanted behaviour from happening.



Can anyone help
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see any problem in the code you posted:

The page code just iterates over the list - no adding there.

The webflow config just calls "custommod.customModLists()" and puts the list into a variable named "results".

I'd think the problem would probably be in "custommod.customModLists()", or maybe in some other place in the jsp that uses the "result" variable...

A "quick fix" would be to change the List to a Set - which doesn't allow duplicate values.
 
Felix Thomas
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

got the problem it was in the class which was implementing the method, it has a class memeber aaraylist. But i have a different problem,

i am executing a flow i.e.e adding a module after which it goes back to the list of modules.

exactly the flow is
list of mod ->add module ->list of modules.

the problem is after adding a module which i come back to list of modules and select the add button there

the text box shows the previous added values , it does not show blank.

[<code>]
module flow beans.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<!-- Search form action that setups the form and processes form submissions -->
<bean id="formAction" class="org.springframework.webflow.action.FormActi on">

<property name="formObjectClass" value="com.mastek.sb.common.to.CustomModTO"/>
<property name="formObjectName" value="customModTO"/>
<property name="formObjectScope" value="FLOW"/>
<!--
<property name="validator">
<bean class="org.springframework.webflow.samples.phonebo ok.SearchCriteriaValidator"/>
</property>
-->
</bean>

</beans>


module-flow.xml

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-1.0.xsd">

<start-state idref="listCriteria"/>

<view-state id="listCriteria" view="listModule">
<render-actions>

<bean-action bean="custommod" method="customModLists">
<!--
<method-arguments>
<argument expression="requestParameters.userid" parameter-type="int"/>
</method-arguments>
-->
<method-result name="results"/>
</bean-action>
</render-actions>
<transition on="add" to="addModule"/>
</view-state>

<view-state id="addModule" view="moduleadd1">
<render-actions>
<action bean="formAction" method="setupForm"/>
</render-actions>
<!--
<render-actions>
<bean-action bean="phonebook" method="search">
<method-arguments>
<argument expression="flowScope.searchCriteria"/>
</method-arguments>
<method-result name="results"/>
</bean-action>
</render-actions>
-->

<transition on="save" to="savemod">
<action bean="formAction" method="bindAndValidate"/>
</transition>
</view-state>

<action-state id="savemod">
<bean-action bean="custommod" method="insertCustomMod">
<method-arguments>
<argument expression="flowScope.customModTO"/>
</method-arguments>
</bean-action>
<transition on="*" to="listCriteria" />
</action-state>



<!--
<subflow-state id="browseDetails" flow="detail-flow">
<attribute-mapper>
<input-mapper>
<mapping source="requestParameters.id" target="id" from="string" to="long"/>
</input-mapper>
</attribute-mapper>
<transition on="finish" to="displayResults"/>
</subflow-state>
-->
<import resource="module-flow-beans.xml"/>

</flow>

moduleadd.jsp

<%@ page contentType="text/html" %>
<%@ page session="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

<html>
<head>
<title>Add Module</title>
</head>

<body>


<div id="content">
<h2>Add a new Module</h2>
<hr>
<!-- Tell webflow what executing flow we are participating in -->
<form action="sbdemo.htm" method="post" id="moduleForm">
<fieldset>

<table>
<tr>
<tr>
<spring:bind path="customModTO.label">
<td>Label</td>
<td>
<input type="text" name="${status.expression}" value="${status.value}">
</td>
</spring:bind>
</tr>
<spring:bind path="customModTO.name">
<tr>
<td>Name</td>
<td>
<input type="text" name="${status.expression}" value="${status.value}">
</td>
</tr>
</spring:bind>
</tr>
<tr>
<td colspan="2" class="buttonBar">


<input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}">

<input type="submit" class="button" name="_eventId_save" value="Save">
</td>
</tr>
</table>
</form>
</div>
</body>
</html>

weblow-config.xml

?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:flow="http://www.springframework.org/schema/webflow-config"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schem...-beans-2.0.xsd
http://www.springframework.org/schema/webflow-config
http://www.springframework.org/schema/webflow-config/spring-webflow-config-1.0.xsd">

<!-- Launches new flow executions and resumes existing executions. -->
<flow:executor id="flowExecutor" registry-ref="flowRegistry"/>

<!-- Creates the registry of flow definitions for this application -->
<flow:registry id="flowRegistry">
<flow:location path="/WEB-INF/flows/**-flow.xml"/>
</flow:registry>

</beans>

servlet-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<!--
Exposes web flows for execution at a single request URL.
The id of a flow to launch should be passed in by clients using
the "_flowId" request parameter:
e.g. /phonebook.htm?_flowId=search
-->
<bean name="/sbdemo.htm" class="org.springframework.webflow.executor.mvc.Fl owController">
<property name="flowExecutor" ref="flowExecutor"/>
</bean>

<!-- Resolves flow view names to .jsp templates -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>

</beans>




[</code>]

hope you ppl are getting my problem
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that by:


the text box shows the previous added values , it does not show blank.



You mean that when the add page comes up the first time it has empty text boxes, but when you go back to the page, it has text boxes filled with the last value that you entered on the page?

This is happening because you are re-using "flowScope.customModTO" - you either need to add a new state to replace "flowScope.customModTO" with a brand new instance before you go into the add page, or you can re-use the instance and just display blanks on the page every time by changing things like:


To:
 
Greenhorn
Posts: 1
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may have 2 inputs with same name or same id.

I've had this issue recently and following topic helped me to solve:
http://forum.springsource.org/showthread.php?t=14736
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic