John Tannel

Greenhorn
+ Follow
since Dec 17, 2010
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
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by John Tannel

Sathya,

As far as I know there is no good way to accomplish this without third party libraries. In my old project, we ended up using multiple select many checkboxes, each with their own setters and getters. When a setter was called, it would simply set the list for it's own data field. When we needed a master list, we had a method that would concatenate the two lists and return it. We only needed 2 columns so it was easy to hardcode two selectMany's and use layout="pageDirection" . If you need a dynamic number of rows/columns then I'm not sure what you could do. I hope this helps some.
10 years ago
JSF
I've thought about doing that, but I want to avoid it for several reasons. First and foremost, it's unprofessional. If I visited a website that purposely disabled my back button just because they didn't want to make their site work well with a browser, I would likely leave and never come back. Secondly, from what I've read it's extremely problematic trying to get it to work correctly in firefox.

This is more of a general question than a project specific one. I always seem to run into this same type of issue with JSF. In my previous projects, it was for internal systems that we could train users to not use browser navigation but for a public site this is by no means an option.

I was hoping there would have been a way to get the button to submit with like an ItemID field so I can check to make sure it's the item I have in the list (and fetch it from db otherwise) instead of just picking the corresponding row from the data and crossing my fingers.
10 years ago
JSF
Let me clarify. Say I have a list of products displayed depending on which category a user selects. Now say the user selects a different category, the list is repopulated with the new data and the user is happy. Now say the customer clicks the back button instead of using page navigation to go back to the first list. Although the page is displaying the old list, the bean where the list resides (and where the data for h:dataTable is bound) has the new list/data. Now, the customer clicks 'add to cart' on an item from the old list. As expected, the respective item in the new list is added to cart even though the customer wanted the one from the old list.

Let me try to illustrate to make this more clear.

<products.jsf>


<products.jsf> after the customer clicks on a different category (which i currently have shown on a sidebar)


After the user clicks his browser's back button, the page displays the first list but the bean contains the second list. If he tries to add Item 1 to cart from that page, it actually adds Item 4.


Now, this is about what I expected, but I was wondering if there is any way around this? Even if I can't make it add the correct item, I was hoping that it would recognize that something was wrong and maybe error out. JSF seems to handle multiple windows/tabs from the same session very poorly and also does not seem to work well with browser navigation.

So, any ideas? Am I setting it up completely wrong to begin with? Thanks in advance!

John
10 years ago
JSF
Andi,

Can you translate the error message to english? It may allow more people to try to help troubleshoot the error.
10 years ago
JSF
Edit: It seems to be working fine, I'm thinking because of the change to the data binding. I'll report back if it breaks again.

For some reason, my controls on two different pages seem to be getting mixed up by JSF. On one page, it's an input text, and on the next page it's an outputText (for my confirmation page).

Sometimes on the second page it shows up as an inputText instead an outputText and vice versa. They should hold the same value but as one is the input page, and one is the confirmation page it's somewhat important that the control types don't get mixed up.

I've never seen this and have done multiple sets of pages like this before. It's really strange. Both the form and the controls on each page have ids. The form id is unique, and the control ids are shared, since they are basically the same value in a different type of control.

Does anyone have any ideas?

edit, here is the code


<cart.jsp>


<confirm.jsp>

I changed the id here to see if that will help as well.




I noticed I had the dataTable's data for the confirmation page bound as well, and wonder if that might have something to do with it. I deleted it, and will play around for a while and see what happens. As the problem only happens intermittently it's hard to say for sure when a solution works.
10 years ago
JSF
Jvh,

Try cleaning up your post. Put code inside code tags for readability. Also please post the actual error.

You might try making the list of the appropriate type. I'm not sure if this will help, but it can't hurt.

John
10 years ago
JSF
Tim,

I ended up just filtering newlines and carriage returns to <br/> and then turning off escape on the outputText. It's not perfect, but it looks pretty darn good. It accomplishes what we want - allowing the user to have paragraphs and create crude lists in the textbox.

John
10 years ago
JSF
Cesar,

I'm sorry. I gave you wrong info and didn't realize it until I saw your code. data should NOT be a managed property, I'm sorry. The data property is bound to the data in the h:dataTable from the code there. You can remove that managed property from faces-config.

As for what is not working, I'm not sure at the moment. I'm in the middle of something right now but in an hour I'll look over again and see if I can find the error. Do you get any errors printed at all, even in the tomcat logs? Or does it just hang on that page and do nothing? Try adding in some print statements to debug to make sure all the code executes.

John

Also, do you have Skype, MSN or AIM. It might be easier to discuss on there. Please PM me that info if you do.


10 years ago
JSF
Cesar,

You are very close. There are some things that I do not see though. In your picture, there is a modificar button but in your code I see no button. Since you are using a commandLink on the ID, that will work fine and you do not need to have a button.


Checklist:

Inside of your faces-config.xml do you have a navigation rule from index-pers.xhtml to modificar.xhtml for the action 'modificar'?
Inside the bean, change private UIData data =new UIData(); to private UIData data; (I don't think this is a problem, but I know 100% that it works the second way).
MAKE SURE that data is a managed property of PersonalBean. I think this may be your problem.

Here is some managed property info: http://mkblog.exadel.com/2009/08/learning-jsf2-managed-beans/
Read the part about "Dependency Injection"

Try to fix all these. If it still doesn't work, report back and tell me exactly what you are doing to cause it to hang. Also can you show the code in PersonalBean that returns the list?

John

10 years ago
JSF
Cesar,

It really depends what the data is, and where it is coming from. In one application, where we got data from the database and that data would only very rarely change (say a list of states, or items) for a list we used a lazy evaluation. On construction and a clear method call we would set the list to null. On the get method for the list, we would check if it was null. If it IS null we would populate the list. If not, we would return the list.

On my current project, where the list might change a bit more often at least for the user I use a a different method. The website owners have a dynamic content management system I built where they can add/edit/delete items that are displayed. The lists update the first time they are needed, and afterwards are updated whenever a change is made. For any arbitrary list, the list is updated via the lazy evaluation I explained earlier. They are further updated whenever we do an add/edit/delete to the database for that particular list.

The getter methods just return the list which is kept in memory, but I make sure the lists update immediately whenever a change is made. Although this may cause updates that are not needed(for example, if the user updates a list and then immediately logs off), it ends up with less updates overall.

You may want to use something simpler. For example, the action that navigates to the page in question may, as a side affect, call something like 'updateMyList' and then return the navigation action to move to the page that uses the list. Then on the page itself, just return the list that is now updated, don't update at that step. Try putting in some debugging print statements. Find out where the work is being done (for example where you actually connect to the database) and put System.out.println("Calling database to retrieve data for list"); Watch how many times it is actually called on page load. In my database connection code, I print a simple statement: Db connection established. Then as I navigate I can watch how many times i connect to the database. Once the project is ready for production I go back through and clean out these statements.

Best of luck

John
10 years ago
JSF
You could download the source code and look through it. Perhaps you could explain why you need to see the source code? There may be an easier solution to whatever you are trying to do.
10 years ago
JSF
I can't speak as to why the commandButtons are slow to load, except maybe you are doing too much work with them. For any displayed value, the getter should retrieve a cached value because sometimes during the lifecycle they can be called many times. For example if you are retrieving a list from a db and displaying it, make sure you are returning a cache value of the list, and updating only once or when needed. Otherwise you may go to the database 5 times or more.

Also remember that an h:dataTable is used to display some type of list. The value attribute should point to some kind of list of objects. var is the name of the variable to represent each item from the list in the "loop".

Then within the datatable, your columns should be using values like p.propertyName

It is possible to allow these values to be editable straight from the dataTable but unless this is an important part of the project it may be much easier for you to simply add an 'edit' command button and allow the editing to be done to only a single item at a time on a different page.

As far as I know, to capture data within a dataTable you must use a binding for each field and bind them to a UIInput in the bean that has the Data binding. Then you can iterate through the UIData by selecting each row and it will change which control that each UIInput in the bean points to. To clarify, you have a set of UIInputs in the bean, one for each field. When you have UIData on the first row, the UIInputs will all point to the appropriate fields for the first item from the list. When you change UIData to the second row, they will then point to the ones for the second item on the list. When we did it, we were forced to validate and update values ourselves and could not find a way to make the lifecycle handle this for us. I may be wrong on this account, but I don't know a better way to do it so unless it's critical I always leave editing to another page (which I find to be less error prone on the user's behalf anyways).

To edit on another page, follow my previous instructions and return an appropriate action to forward you to a page that will allow you to edit the selected row.

I hope this helps.

John
10 years ago
JSF
Naveen,

Does the action listener NEVER get invoked or only when the control does not get rendered? I believe if it does not get rendered, then the listener should not be invoked. I'm not quite sure as to behavior when it is rendered. I would assume it should get invoked.

Also, can you show your code for your action listener? It may help more with debugging.

John
10 years ago
JSF
Right now, if a user enters text into a text box and saves that information, when it is redisplayed to them or another user the formatting is, as expected, wrong.

Newlines, spaces, etc all get jumbled into a single space as per the html standard.

For example if they type:




it comes out as:



Is there an easy way to remedy this? My first thought it to pass the text through a filter that replaces all newlines with an html break element but I feel JSF must provide some easier solution. My second thought may be to just display the text using another textArea but leave it disabled so as to only display the information, but this seems quite backwards.

Does anyone have any better ideas for me?
10 years ago
JSF
Cesar,

I'm not sure as to whether or not you can pass a whole bean as a param, but there may be a much easier way to do what you are trying to do using a data binding on the h:dataTable.


Try something like this:



in PersonalBean:




Now, a couple of clarifications. managedItem needs to be a managed property of PersonalBean, and point towards the actual managed bean of whatever type it is. You are using the newer style declarations, but with the old faces-config style it would look like this:



Please let me know if this helps or if you get stuck at all.

John
10 years ago
JSF