-1

I am making a Java/HTML program using Seam. I am trying to get an <h:selectOneMenu> to show up when a <h:selectBooleanCheckbox> is checked. I got it to do it by using "onclick="form.submit()" in the checkbox and putting the drop-down in an <s:div rendered>, but whenever the page reloads, the variable that is being used by the dropdown is reset to the top choice. I'm pretty sure it is because of the <s:div>. Does anyone know how I can make it keep the correct choice in the drop-down? Thank you.

Here is the code for the checkbox and the drop-down:

<h:selectBooleanCheckbox id="checkbox" value="#{printLabel.code}" label="barcode" onclick="changeDropdowns()"/>
<br />
<s:div rendered="#{printLabel.code}">
    <h:outputLabel id="locationLabel" value="&#160;&#160;&#160;Location"/>
    <h:selectOneMenu id="locationDrop" value="#{printLabel.codeLoc}">
        <f:selectItems value="#{printLabel.getBarcodeTypes()}" />
    </h:selectOneMenu> 
</s:div>
user1423793
  • 279
  • 2
  • 6
  • 16

1 Answers1

1

if you want todo it with ajax you can do it like this: might be some other event then onclick

<h:selectBooleanCheckbox id="checkbox" value="#{printLabel.code}" label="barcode" >
        <a4j:support event="onclick" reRender="parentdiv" />

</<h:selectBooleanCheckbox>
<br />
<s:div id="parentdiv">
<s:div rendered="#{printLabel.code}">
    <h:outputLabel id="locationLabel" value="&#160;&#160;&#160;Location"/>
    <h:selectOneMenu id="locationDrop" value="#{printLabel.codeLoc}">
        <f:selectItems value="#{printLabel.getBarcodeTypes()}" />
    </h:selectOneMenu> 
</s:div>
</s:div>

add tag libary

xmlns:a4j="http://richfaces.org/a4j"
Trind
  • 1,583
  • 4
  • 18
  • 38
  • I've never used ajax before. when i use it says its an unknown tag. do i need to download a library or anything – user1423793 Aug 09 '12 at 21:13
  • nah you need to add gthe tag libary among the others at top of page edited my post about it, it is a part of richfaces – Trind Aug 09 '12 at 21:18
  • ya i figured that out right after i posted my comment lol. But it is still doing the same thing – user1423793 Aug 10 '12 at 13:06
  • What scope do you haev on your printLabel ? You need to have Page or higher if you want to save the value after the page is reloaded. – Trind Aug 10 '12 at 13:43
  • In my printLabel bean i have @Scope(ScopeType.CONVERSATION) – user1423793 Aug 10 '12 at 13:51
  • I changed the ScopeType to PAGE and it works now. Thank you so much for your help – user1423793 Aug 10 '12 at 13:57
  • No problem, conversation could be used but then you need to create it to a long running conversation and that is a bit more hassle if you don't need it as a long running. – Trind Aug 10 '12 at 14:06