views:

285

answers:

2

Hi guys, I have just started to learn seam framework. I decided to code two drop down menus. One listing categories and other listing subcategory. The idea is that user will first select a category and depending on that a subcategory will be populated.

<h:selectOneMenu value="#{manager.category}" required="true">
          <a:support event="onfocus" ajaxSingle="true" action="#{manager.dothis()}"/>
          <s:selectItems value="#{manager.categories}" var="cat" label="#{cat.categoryDescription}" noSelectionLabel="Select a Category"/>
          <s:convertEntity />

Above, I am trying to call dothis() method on event focus but its not working.

What am I doing wrong here?

Thanks.

+1  A: 
  1. Is your #{manager.categories} already populated?
  2. What does #{manager.dothis()} do?

You probably don't want to do anything onfocus() ...unless maybe you're lazy loading the initial values (which I don't think you are). You should also be reRendering something in the <a:support> tag otherwise your action won't affect anything on your page.

Here's my approach to these (assumes #{manager.categories} is populated):

<h:selectOneMenu id="category" value="#{manager.category}" required="true">
          <a:support event="onchange" ajaxSingle="true" action="#{manager.populateSubCategories()}" reRender="subcategory"/>
          <s:selectItems value="#{manager.categories}" var="cat" label="#{cat.categoryDescription}" noSelectionLabel="Select a Category"/>
          <s:convertEntity />
</h:selectOneMenu>

<h:selectOneMenu id="subcategory" value="#{manager.subcategory}" required="true">
          <s:selectItems value="#{manager.subcategories}" var="subcat" label="#{subcat.categoryDescription}" noSelectionLabel="Select a Sub-Category"/>
          <s:convertEntity />
</h:selectOneMenu>
Damo
+1  A: 
Nishant
@alkesh Use @Factory It is evaluated once, and just once. Advice: Do not use post an answer when you want to post a comment. See link add comment
Arthur Ronald F D Garcia
What is the difference between @Factory and @Create. And, I tried code above for some reason manager.populateCategories() is not being called. Also, I do I debug it. I am using log.debug() but where are those logs stored?Thanks guys, I appreciate you taking time helping me out.
Nishant
alright, so i figured out the diff between Factory and Create.Now, only the problem is that action is not working onchange.
Nishant
i get the following error:20:03:03,999 INFO [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.sourceId=managerForm:j_id13[severity=(ERROR 2), summary=(value is not valid), detail=(value is not valid)]What am I doing wrong? BTW, both selectOneMenus are enclosed in rich:panel.
alkesh
I think, i have it right now. But why is my method "callme" not being called on change event.
Nishant
You should not post questions/updates as **answers**. They will get lost into noise. This isn't a forum. Use the `edit` link below your question to add updates. Use the `add comment` link to add comments. Finally delete this "answer".
BalusC
@BalusC, I am sorry about that. I cleared my history on my pc, so it didn't recognize me. So, I couldn't modify my earlier post. Thanks for clearing it out though.
Nishant
Ah yes, I see. I'd suggest to register yourself then :)
BalusC