Solved

Dynamically generate JSF components.

Posted on 2004-08-31
9
649 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 32

Accepted Solution

by:
ldbkutty earned 200 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 300 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
How many times a day do you open, acknowledge, or close an IT incident? What’s your process? Do you have a process depending on the incident, systems involved, and other factors? New Relic Alerts gives you options for how you interact with notifica…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

710 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