• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Losing part of my page.

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, so I am doing what I thought should be a simple binding of a bean property to an HtmlPanelGrid on a faces page, however whenever I postback to that page I lose the HtmlPanelGrid. Here are the details:

I make a managed bean GridBean at the request scope level.

In the .xhtml file I have:
<h:panelGrid id="questions" binding="#{GridBean.questions}"></h:panelGrid>

In the GridBean.java file I have a getQuestions which creates the panel grid and configures it with data from an xml file and a setQuestions which just sets the questions HtmlPanelGrid to the passed in value.

What happens is on the first page load getQuestions is called and the HtmlPanelGrid shows up as I expect. When I click submit on my form and the page gets reloaded I see that setQuestons is called and passes is the same HtmlPanelGrid that was gotten out of the bean on the first page load. Fine. Then I see getter called, also fine. Thirdly, and problematically I see the setter called one more time, but this time with a HtmlPanelGrid that has obviously just been instantiated and has no children. Right after this happens the page is displayed and I naturally don't see my nicely configured panel grid. The source just shows and empty panel grid.

Any thoughts on why this is happening? The newly created HtmlPanelGrid suggests to me that the binding is getting lost or screwed up somehow, but I don't understand how that is possible. This seems like it should be one of the more simple cases using this tech. Anyway hopefully someone has some better ideas than myself!
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Eric Lastname",


There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Eric Masbroma
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So it 'works now' though not exactly as I expected it would/should.

I discovered that if in the GridBean I have a setter, then I lose all my carefully configured HtmlGridPanel on the postback. If I get rid of the setter then it continues to show up on the post back which is good. However without the setter than it can't restore view so when I ask for that bean while processing the page in a different bean (via: application.getVariableResolver().resolveVariable(context, "GridBean")) then the gridBean that I get back has a null questions member, which is annoying since I then don't have a handle on what people actually put into my htmlInputFields. The solution to that is that you can valueBind the input fields when you dynamically create them to a hash in the gridBean object, which has a setter and a getter and thus gets set with the correct data in restore view and you can access it while processing the page. For example when I am configuring my HtmlGridPanel in code and making the HtmlInputText objects for it, I can do something like:

HtmlInputText input = (HtmlInputText)application.createComponent(HtmlInputText.COMPONENT_TYPE);
input.setId(QUESTION_PREFIX + questionNumber);
literalQuestions.add(input);
input.setValueBinding("value", // param to bind to
application.createValueBinding("#{GridBean.answers[" + questionNumber + "]}"));

and then when processing the request I get access to the gridBean object, which will have a HashMap<Long,String> answers member populated with the answers to the questions, keyed by questionNumber.

Big pain in the ass to figure out as a newbie to JSF (if not to java, heh) but hopefully this helps someone else.

--
As an aside I'm not real convinced that making people put up fake last names (since privacy on the web is an issue) is really the best solution for avoiding 'l33t' names. You could just exclude everything but alpha and not allow more than 2 of the same char in a row and things would probably look fairly reasonable. I suppose if you have a different goal than anti-leet then whatever, but it certainly seems like very odd requirement to this netizen.
 
reply
    Bookmark Topic Watch Topic
  • New Topic