aspose file tools*
The moose likes Struts and the fly likes Dynamic Textboxes. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Dynamic Textboxes." Watch "Dynamic Textboxes." New topic
Author

Dynamic Textboxes.

Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 212
Hello Merrill / Other Ranchers around,

This time i am in a confusion as to how to generate Dynamic Textboxes based on the values coming from the database.

For instance , There are four fields called jobType,ItemCode,Quantity and Rate which would be coming from the Database. Based on the size of the Collection i.e ArrayList , on the JSP corresponding number of Textboxes should get generated automatically with all the details populated.

Can you shred some light on how this can be achieved ?

Thanks in Advance.

Yogendra N Joshi


Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You will need to used indexed properties for this. Please carefully read the following two articles:

http://struts.apache.org/1.2.9/faqs/indexedprops.html
http://wiki.apache.org/struts/StrutsCatalogLazyList

You can also search this forum for the topic "indexed properties" and find a lot of discussion regarding this topic.

Let us know if you have specific problems implementing these techniques for your situation.


Merrill
Consultant, Sima Solutions
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 212
Hello Merrill ,

Thanks for the reply. Let me check out the links and try out. If there is a problem implementing it, Would get back to you.

Thanks again.

Yogendra N Joshi.
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 212
Hi Merill ,

According to what you helped , I tried doing it but facing a problem called "No Collection Found" and sometimes i get "Cannot create iterator for..".
These are my all files , Appreciate if you can help me out.

JSP File :

-------------------------------------------

<html:form action="/login">
<logic:iterate id="yogendra" name="loginform" property="txtList">
<html:text property="name" name="yogendra" size="30" indexed="true"/>
</logic:iterate>
<html:submit>Submit</html:submit>
</html:form>

--------------------------------------------

Action Class :

---------------------------------------------



ActionForm :

-------------------------------------------



struts-config.xml file :

-------------------------------------------

<!-- Start of Struts Config File -->
<struts-config>

<!-- Standard Form Beans for TestStruts Application -->

<form-beans>
<form-bean name="loginform" type="orgy.yogendra.LoginForm"/>
</form-beans>

<!-- Standard Action Mappings for thew TestStruts Application -->

<action-mappings>
<action path="/login"
name="loginform"
validate="false"
type="LoginAction"
scope="request">
<forward name="page" path="/loginForm.jsp"/>
</action>
</action-mappings>

<!-- End of Struts Config File -->

</struts-config>

-------------------------------------------

for the Action , ActionForm and JSP files , I have included only those relavent parts , I have omitted imports and taglib declarations in this post. But they do exist in my all files

Hope , I will again be helped by you as always

Thanks in Advance.
Yogendra.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Action Class: Looks pretty good though you can probably remove the call request.setAttribute..and in any case you would not want to call this every time through the loop.

Action Form: For indexed properties you need methods that take an index as a parameter. Like the following. It has been a little while since I have written index properties for simple types like String, so this might not be exactly right. The method getTxtItem might not be needed.


JSP File: You then need to hook your JSP code up to use the txtItem indexed methods in your form. The following might be correct. Again, I am not sure of the syntax for simple types like Strings.


For the longest time I did not understand how to get indexed properties working (mostly because I did not know that the id attribute of the logic:iterate tag should match up with the property name in the form) so I would hand roll the index code like this (in which case the method getTxtItem is needed in the form):


- Brent
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 212
Hello Brent ,

Thanks for the help.. Not being successful..

Can you please elaborate more. Also i would wish Merrill to help in this case...

Thanks in Advance.
Yogendra Joshi.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You will need to be more specific than "not being successful". Give us the specific error message and tell us at what point it occurs (When the page submits? when it is displayed for the first time?).

I assume you modified your code according to Brent's suggestions. Can you show us the modified code?
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I put together a simple example of a page that had a list of phone numbers. I tried a couple things, but I could not get the html:text tag working with indexed="true". I was able to get it working using some JavaScript to build the indexes. Here is my code:


- Brent
Satish Kumar
Ranch Hand

Joined: Oct 16, 2006
Posts: 84
This can be easily done using the display tag...

See the following format for help

here...requestURI="/disputeOrValidate.do?method=DISPUTEORVALIDATE"
is the action to be called for displayin the values and
name="sessionScope.ChargeAnalysisListVO.chargeAnalysisList"
is the Object and its arraylist in session or request scope

<display:table requestURI="/disputeOrValidate.do?method=DISPUTEORVALIDATE"
requestURIcontext="false"
name="sessionScope.ChargeAnalysisListVO.chargeAnalysisList"
pagesize="5" class="data sortable" excludedParams="method" id="row"
style="width: 725px;" size="20">

<display:column property="strProductDescription" titleKey="title.Description" />

<display:column property="strCircuitId" titleKey="title.CircuitId" />

<display:column property="dateChargeFromDate" titleKey="title.ChargeFrom" />

<display:column property="dateChargeToDate" titleKey="title.ChargeTo" />

<display:column property="douOneOffChargeOut"
titleKey="title.One-OffCharge£" />

<display:column property="douAnnualCharge"
titleKey="title.AnnualCharge£" />

<display:column property="douTotalChargeOut" titleKey="title.Charge£" />
<display:column titleKey="title.Ticktodispute">
<c:if
test='${row.strBillingStatus eq "Ready for Customer Validation"}'>
<html-el:checkbox name="disputeForm"
property="intDisputeOrValidateCheck"
value="${row.intUnbilledChargeId}" tabindex="9" />

</c:if>
<c:if
test='${row.strBillingStatus ne "Ready for Customer Validation"}'>

<c ut value="${row.strBillingStatus}" />

</c:if>


</display:column>

</display:table>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic Textboxes.
 
Similar Threads
Managing dynamic form elements in Struts
Dynamically adding textboxes
Jsp and html elements
Submitting a lot of textbox in a jsp page
Framework evaluation: Does JSF support dynamic form?