Vladislav Simovic

Ranch Hand
+ Follow
since Feb 03, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
13
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vladislav Simovic

I have main page that looks like this:

What i want to do is have a bean like this and change dinamically which page is included. This is how bean looks like:

When i click button Push i want this page to be included:

Problem is that i have to press the button twice for page to be included. How can this be done so when i press the button the first time page is included.
11 years ago
JSF

Stefan Evans wrote:Right so you have multiple pages returned and included in your project.
How do you decide which JSP page (out of the numerous available) to invoke?

How is this different from knowing which module to invoke?




First question I have answered. Module gets template page, modifies it, saves and returns to intarface. Because every page has its own unique bean (by unique, i mean unique named in session), everything works fine.

To second question - bean is created automatically by using default constuctor with no args. You cant pass parameters to it. So how is the bean aware which module is his? Module - bean is not billateral communication. I create a new instance of module, but bean is created by JSF servlet. If there is way to pass parameters to backing bean it would solve all my problems.
11 years ago
JSF

Stefan Evans wrote:Ok then. Lets assume that you would generate a new jsp page. You now have a page for each module.
How would you then decide which page to invoke?



Ok the module puts manually bean into session via session.setAttribute("modulInstance123", modul); Because i made the bean i can pass some parameters to it, like resources. Then module retrieves the page that needs including as a text file. Then everywhere on the page replaces <h:outputText value="{StubBeanName.variable}"/> with <h:outputText value="{modulInstance123.variable}"/> This is saved into new page that is returned to interface and then included into project. In theory it solves my problem.

Tricky part is getting JSF page and reading it like txt file.
11 years ago
JSF

Stefan Evans wrote:I still maintain that editing JSP pages at runtime is a bad idea.
In the example you gave, the only customisation you wanted to make was the name of the bean in session to access the data for.

And you don't need to do it at all.

You asked the question: "How does the bean know which data to take from session?"'
Your answer was: "He doesn't."
My answer to that question would be: You tell it.

Presumably your backing bean should only reference/work with one specific module at a time.
You say you can have multiple instances of module, so I would keep a Collection of them in session - probably as a map in fact.

You then retrieve the correct module you want to work with from the session map, set it on your backing bean, and display the page.

By decoupling the page from your data storage, you can reuse that same JSP template page for all of your module data, and avoid having to generate files at runtime.



When bean is created he would have to access session, and retrieve that collection of bean instances. Problem with that solution is - which instance does bean take, they are all same to him, and there can be any number of them. Based solely on contents of module he can not make desicion if that is the right module for him. You must have in mind that i am not buliding whole system, just the module, so i cant change main interface.
11 years ago
JSF
I opened another topic, but it seems from answers that i got there dependency injection cant solve my problem. So back to my original problem:

How can you access a page during runtime open it like some common text file and modify contents? From what i have seen pages are stored into .war and i have no clues how to acees them let alone, create new page with modified content.
11 years ago
JSF

Tim Holloway wrote:Dependency Injection is nothing more than a process where beans are wired together from outside rather than requiring the beans to reach out and find stuff (which requires them to have explicit logic coded into them).

For actual database testing, you might want to look at dbUnit. You can create a JSF webapp, and you can definitely inject objects to be tested into it, but that may be overkill for you.



Tnx for the info, I really dont time now to look into whole matter of dependency injection, only to find out that it doesnt solve my problem.
11 years ago
JSF
I have posted a little while ago topic with my problem and it was suggested that DI can solve it. I have been reading about DI since then and from first look it doesnt seem like it can. Here is my problem:

My project is to build a module for testing databases. That module needs to be integrated into larger interface. My module doesnt have any resources of his own, every resource he needs he gets form server.

What my module does? When server makes new instance of my module it passes him some resources. Then module returns a proper JSF page that will be included into main interface page. Backend JSF mechanism creates a bean for that page. That bean is created automatically. So how can that bean take the needed resources from module?
One way is to put those resources into session, and than bean takes them from there. Problem is there can be multiple database testing and at same time multiple instances of module can exist in users session. How does the bean know which data to take from session? He doesnt.

So my question is this, how can you inject already made instance of a module(this object exists before creating of a bean) into field of a bean?
11 years ago
JSF

Guy deLyonesse wrote:

Vladislav Simovic wrote:
Can you elaborate more on this, I am not familiar with this tehnique?



Prettymuch any decent JSF book explains it.



Since i havent been using any JSF books (just internet knowledge), it would be really helpful for me i f you can reccomend a couple of books, that deal with this issue.
11 years ago
JSF

Dieter Quickfend wrote:Why not use Dependency Injection in the backing bean? That's pretty much what they mean by Inversion of Control, you know.



Can you elaborate more on this, I am not familiar with this tehnique?
11 years ago
JSF
Let me try to explain how i got to idea to modify pages during runtime.

My masters project is to build a module for testing databases. That module needs to be integrated into larger interface. My module doesnt have any resources of his own, every resource he needs he gets form server.

What my module does? When server makes new instance of my module it passes him some resources. Then module returns a proper JSF page that will be included into main interface page. Backend JSF mechanism creates a bean for that page. That bean is created automatically. So how can that bean take the needed resources from module?
One way is to put those resources into session, and than bean takes them from there. Problem is there can be multiple database testing and at same time multiple instances of module can exist in users session. How does the bean know which data to take from session? He doesnt.

So one way is for module to have some id. Then module manually creates bean and pusts it into session with name of his id. Then he takes template JSF page, and every occurence of template bean name changes with new bean name. SO its something like this:

session.setAttribute("modul12", new DataBaseBean());

and then change every <h: outputText value="TemplateBean.name"/> with <h: outputText value="modul12.name"/>
11 years ago
JSF
I have made web server project in NetBeans, and created a few .xhtml pages and beans for them. Now I want to able to modify these pages during runtime and show the modified version in browser.

So lets say I am on index.xhtml page. And I want to go to start.xhtml page. In index page bean i have a method that needs to read the index page file and change some components on it. Then save those changes, and show that modified page to user.

Problem is i dont know where these pages are kept and how to get them. I have seen that they are in war/web-inf but i cant access them. Does anyone know how can this be done?

If some more info is needed I am happy to provide it.
11 years ago
JSF

Dieter Quickfend wrote:
where certainI18nString is a property in your backing bean containing your internationalized string.



I want all my strings to be in .propeties file - the ones i hardcoded in .java files, and the ones i use on jsf pages. I dont want to have something in .properties file(for static jsf values) and something in other txt file (for values that bean returns that are shown on the page).

its like this:



First is static value user that is same for all users. Second is country of origin of user which can be different for every user. If we have user named Bob, from England, following would be written for him:

User: England

If we switch language to Italian it sholud write:

Utente: Inghilterra

And both of these words should be in .properties file.
11 years ago
JSF
Let me be more clear - I have JSF page and a bean behind it. Some of the content of the page is adjusted dynamically by methods of the bean, eg i wite some text to the page. I also want that text to be language dependent.

How do i pick that text from properties file?
11 years ago
JSF
I have made a server application and now i want it to support multiple languages. I have looked over the net and found that solution is properties file.

Now i have the next problem, while i can change jsf pages via messages, i want also to change the language of my hardcoded strings in source file also using this same properties file. Can this be accomplished?
11 years ago
JSF