Link to home
Start Free TrialLog in
Avatar of chrysler7
chrysler7

asked on

Dynamically generate JSF components.

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.
ASKER CERTIFIED SOLUTION
Avatar of ldbkutty
ldbkutty
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chrysler7
chrysler7

ASKER

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.
SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can see in that example ldbkutty posted that each row is called "txtRow" plus the line number...
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.
> 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)
Yes, im looking to use a JSF approach and realize that it will result in a post back. How to do this?
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)...
I was hoping for a cleaner .NET like approach but it doesnt look like there is one... Thanks though guys!