Solved

Dynamically generate JSF components.

Posted on 2004-08-31
9
644 Views
Last Modified: 2011-07-26
There doesnt seem to be a JSF category, so I guess heres the best place to ask.

Ill try to use an example to illustrate my problem. Say you want to manage a company contact list and you have many companies. Basically you have many companies and each company has a list of contacts. Each company screen has a dynamic contact list. The display is like.

Add Contact

Contact 1:<input box>Bugs Bunny</input box>
Contact 2:<input box>Daffy Duck</input box>

If the user clicks on Add Contact, I want to create a new contact info line with associated input. All the JSF examples I have seen thus far "hard code" these input boxes. How do I do this dynamically? Im assuming there will be something like an array of inputText's in the backing bean. But how can I dynamically show this?

I would imagine I would need to put some sort of place holder in the JSF page and then somehow ask it to render 1 to many of these controls that I am generating in the backing bean.

Im new to JSF/JSP, so forgive me if my question is confusing.
0
Comment
Question by:chrysler7
  • 4
  • 4
9 Comments
 
LVL 32

Accepted Solution

by:
ldbkutty earned 200 total points
Comment Utility
If i understand correctly, JS is enough for dynamically adding rows. Something like:
http://www.mredkj.com/tutorials/tableaddrow.html

I am sorry if this is not what you want.
0
 

Author Comment

by:chrysler7
Comment Utility
This is true from a UI perspective, and perhaps JSF has a way of rendering controls as the javascript you have shown.

However, I dont want to manually implement this javascript(if at all possible). I also know that relying on server side code to generate this will more than likely require a post back.

The reason I dont want to use this exact approachs is because I also want the ability to add logic to oeprate against these contact "objects" in the code behind. I may want to make sure that a contact name is unique across all companies, or ensure that a contact name is less than 5 characters long. I know this is all technically possible using javascript but I want to be able to access these objects from the backing bean. I also dont want to expose any business logic via javascript.
0
 
LVL 35

Assisted Solution

by:TimYates
TimYates earned 300 total points
Comment Utility
> How do I do this dynamically?

as ldbkutty says, you have to do this via javascript :-/

> I also know that relying on server side code to generate this will more than likely require a post back.

Yeah, and you will have to store all the values that have already been entered/changed, and set them again each time a row is added or removed

> I know this is all technically possible using javascript but I want to be able to access these objects from the backing bean.

That's fine, you can just do all of the row adding/deleting in javascript, then when the form is finally submitted to the server, you can dynamically check all of the values sent to the server for duplicates, etc...

You can give each row a unique name -- "name1.1" for example, then loop through all of these names on the server side to work out how many rows were submitted, and check them all off against the known list of values...
0
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
You can see in that example ldbkutty posted that each row is called "txtRow" plus the line number...
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:chrysler7
Comment Utility
A javascript solution will be sort of my last resort... Is it impossible to achieve this effect using JSF? I figure there *has to* be a way to do this, but I just havent found an example.
0
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
> Is it impossible to achieve this effect using JSF?

Not without resubmitting the form...

There are 2 places this can happen...

On the server (needs a submittal), or on the client (needs javascript)
0
 

Author Comment

by:chrysler7
Comment Utility
Yes, im looking to use a JSF approach and realize that it will result in a post back. How to do this?
0
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
you will have to submit all of the current form...it's values, etc, and a couple of hidden properties saying that you want to add or delete a row back to the server, which will then spit outthe modified html (dpending on the flags)...
0
 

Author Comment

by:chrysler7
Comment Utility
I was hoping for a cleaner .NET like approach but it doesnt look like there is one... Thanks though guys!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this step by step tutorial with screenshots, we will show you HOW TO: Enable SSH Remote Access on a VMware vSphere Hypervisor 6.5 (ESXi 6.5). This is important if you need to enable SSH remote access for additional troubleshooting of the ESXi hos…
A safe way to clean winsxs folder from your windows server 2008 R2 editions
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now