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
Solved

Dynamically generate JSF components.

Posted on 2004-08-31
9
647 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
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
method inner class 6 83
JSP How to use numberFormat to display a negative number without parenthesis? 1 177
maven webservice example issue 2 144
equalIsNot  challenge 43 167
IT certifications are a concrete representation of continual learning on the part of the candidate.  Continual learning is necessary for the long term success of an IT professional, but are IT certifications the right path for you?
The business world is becoming increasingly integrated with tech. It’s not just for a select few anymore — but what about if you have a small business? It may be easier than you think to integrate technology into your small business, and it’s likely…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

808 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