Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dynamically generate JSF components.

Posted on 2004-08-31
9
Medium Priority
?
653 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 600 total points
ID: 11947404
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
ID: 11947632
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 900 total points
ID: 11949925
> 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 35

Expert Comment

by:TimYates
ID: 11949939
You can see in that example ldbkutty posted that each row is called "txtRow" plus the line number...
0
 

Author Comment

by:chrysler7
ID: 11954992
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
ID: 11955441
> 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
ID: 11965728
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
ID: 11965757
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
ID: 11976811
I was hoping for a cleaner .NET like approach but it doesnt look like there is one... Thanks though guys!
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know there are services out there that can turn an Instagram feed into an RSS feed? I found some interesting exclusive Instagram content which I wanted to follow without signing up for yet another social media account. RSS to the rescue!
Transferring FSMO roles is done when an admin wants to split roles between certain Domain Controllers or the Domain Controller holding the Roles has been forcefully demoted using dcpromo / forceremoval
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

916 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