• 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

<h:selectOneMenu problem. Please, Gurus, I need Your help.

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, guys. Please, could someone help me?
I have following problem: I need to retreive projectNames from DataBase into<h:selectOneMenu ...><f:selectItems ...></f:selectItems></h:selectOneMenu>. I do it this way(part of .jsp page as I think the problem is in it):

----------------------------------------------------------------------------
<h:selectOneMenu value="#{SubmitReport.projectName}"
styleClass="common-dropdown" required="true" >
<f:selectItems value="#{SubmitReport.loggedUserProjects}"/>
</h:selectOneMenu>
----------------------------------------------------------------------------

I succeed in retreiving projectNames from DataBase and displaying on the page. But when I press submit in browser:

----------------------------------------------------------------------------
<h:commandButton value="Submit" id="SubmitCommand" action="#{SubmitReport.submitReport}"
immediate="true">
----------------------------------------------------------------------------

projectName variable of backingBean appears to be null, when it must already have been initialized(there is setter/getter for projectName in backingBean). If I remove immediate="true" in <h:commandButton ...> the page just refreshes, but the submitReport() method of the backingBean is not invoked at all...

In backingBean(SubmitReport) the 2 variables - projectName & loggedUserProjects are:

-----------------------------------------------------------------
private String projectName;
private ArrayList<SelectItem> loggedUserProjects;

public String getProjectName() {
return this.projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}

public void setLoggedUserProjects(ArrayList<SelectItem> loggedUserProjects) {
this.loggedUserProjects = loggedUserProjects;
}
public ArrayList<SelectItem> getLoggedUserProjects() {
return loggedUserProjects = extractUserProjectsFromDB();
}
-----------------------------------------------------------------

And I tried to change the type of projectName to SelectItem - didn't help.

And one more detail:
I debugged the application, when I press submit in submitReport() of backingBean I tracked the contained values in request like this:

------------------------------------------------------------------
public String submitReport() {
...
Map allParams;
if (this.projectName == null) {
allParams = ((HttpServletRequest)FacesContext.getCurrentInstance().
getExternalContext().getRequest()).getParameterMap();
System.out.println(allParams.size());
}
------------------------------------------------------------------

So in principle if projectName == null, I can retreive it from request "by hands" - but it's wrong, JSF MUST DO THIS. Seems like I configured smt. wrong or misunderstood.

What is the problem in? I have already been fighting this for 2 days - but no luck. So, Gurus, please I need Your help...
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know how hard you are trying it from Yeterday.. So I couldn't stop myself giving you few hints to findout the problem.. But this is my last try.. and I suggest you to do following..

Include <h:messages /> in your jsf page. This will give you exact error message happening while setter method is being called.
Also remove immediate="true" on commandbutton. Otherwise you will never come to know about the problem.

Good Luck.

Thanks
Smitha




 
Andriy Burachinskiy
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Smitha, thanks for your patience and help. I did as you adviced:
----------------------------------------------------
...
<h:commandButton value="Submit" id="SubmitCommand" action="#{SubmitReport.submitReport}">
<h:messages infoStyle="info"/>
</h:commandButton>


<h:messages infoStyle="info"/>
</h:form>
...
----------------------------------------------------

This is what I can see on the page in browser, when I type "Submit":
_________________________________________________________
Conversion Error setting value 'on track' for 'null Converter'.
Conversion Error setting value 'text of report' for 'null Converter'.
_________________________________________________________

But my submitReport() method of the backingBean is not invoked at all in this case!!! How can I make it get invoked without specifying immediate="true" in submit tag ???
One more thanks for helping me..
 
Smitha H Rao
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is in the h:inputTextarea .

you have

<h:inputTextarea id="repContent" value="#{SubmitReport.repContent}" required="true"
styleClass="input" rows="22" cols="75"/>

in you jsf and 'repContent' is a Clob!!

The JSF can do automatic conversion only for wrapper classes.You have to supply a converted for it.
When you submit a JSf page
first all setter methods are called. If there is any problem, action method will not be called. So your action method is not called unless you have immediate="true"
But if you have immediate="true" on commandButton, then no setter method is called.

Right now I think remove this h:inputTextarea from your JSF page and give a try.. It should work properly.
Then write a converter to convert a String to Clob and specify it in the h:inputTextarea tag.

Best Of Luck.

Thanks
Smitha





 
Andriy Burachinskiy
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Smitha. You were right. Now my problem is resolved. I'm thankful to you. I was preparing to SCJP1.6 about half year ago, so I've got full study guide by Katty Sierra for SCJP1.6 & exam simulator for SCJP1.6. If You are interested, I can send it to your e-mail. P.s.: the certificate itself is of minor importance, but personally I got to known some interesting things from studyGuide.
 
Smitha H Rao
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Andriy,
Could you please send it to smitha.h.rao@gmail.com.
 
Ranch Hand
Posts: 101
Spring Flex Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you please send the scjp material to shasimitra@gmail.com also.
 
I don't like that guy. The tiny ad agrees with me.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic