0

The problem: the content div does not show the image string when i run it in chrome, i guess it's null altrough i set it's value in the applicationContext class. The itemList model attribute is not null, i can see the id of the objects.

The ItemGroup class has a list of Items and Receipt is a Subclass of the abstract class Item

this is my code in netbeans:

applicationContext.xml:

 <bean id="receipt1" class="domain.receipts.Receipt" >
        <property name="id" value="1"/>
        <property name="image" value="Images/receipt.png"/>
 </bean>

 <bean id="receipts" class="domain.ItemGroup">
        <property name="items">
            <list>
                <ref bean="receipt1"/>        
            </list>
        </property>
        <property name="image" value="/Images/klantenkaart.png"/>
 </bean>

HomeController:

@Controller
public class HomeController 
{
private ItemGroupService itemGroupService;

@Autowired
private ItemGroup receipts;
@Autowired
private ItemGroup shoppinglists;
@Autowired
private ItemGroup cards;

@Autowired
public HomeController(ItemGroupService ItemGroupServiceImpl)
{
this.itemGroupService=ItemGroupServiceImpl;
}


public List<Item> getReceipts()
{
    return receipts.getItems();
}

@RequestMapping(value = {"/index"},method = RequestMethod.GET)
public String showHomePage(Model model) 
{
model.addAttribute("itemGroup", new ItemGroup());
return "index";
}

@RequestMapping(value = {"/index"},method = RequestMethod.POST)
public String onSubmit(@ModelAttribute("itemGroup") ItemGroup itemGroup, Model model)
{

    if(itemGroup.getName().equals("receipts"))
    {
       model.addAttribute("itemList",receipts.getItems());
    }
    else if(itemGroup.getName().equals("cards"))
    {
       model.addAttribute("itemList",cards.getItems());
    }
    return "index";
    }
 }

index.jsp

<div id="header">
  <table>
      <tr>
   <form:form method="POST" action="index.htm" modelAttribute="itemGroup">
     <form:input path="name" type="hidden" value="receipts" /> 
     <input type="image" src="Images/receipt.png" height="150px" width="180px" alt="Submit" value="receipts">    
   </form:form>
   <form:form method="POST" action="index.htm" modelAttribute="itemGroup">     
     <form:input path="name" type="hidden" value="shoppinglists" /> 
     <input type="image" src="Images/shoppinglist.png" height="150px" width="180px" alt="Submit" value="shoppinglists">
   </form:form> 
   <form:form method="POST" action="index.htm" modelAttribute="itemGroup">     
     <form:input path="name" type="hidden" value="cards" /> 
     <input type="image" src="Images/loyalitycard.png" height="150px" width="180px" alt="Submit" value="cards">
  </form:form> 
   <form:form method="POST" action="index.htm" modelAttribute="itemGroup">     
     <form:input path="name" type="hidden" value="vouchers" /> 
     <input type="image" src="Images/voucher.png" height="150px" width="180px" alt="Submit" value="vouchers">
  </form:form> 
     </tr>
  </table>

</div>

<div id="leftcol">
    </br>
</div>

<div id="content">
      </br>
      <h1> ${itemList}</h1>     
           <c:forEach items="${itemList}" var="prod" >
                <h1>${prod.image}<h1>            
           </c:forEach>   
</div>

Item class:

public abstract class Item 
{
    private int id;
    private String barcode;
    private Date creationDate;
    protected String image;


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getBarcode() {
        return barcode;
    }

    public void setBarcode(String barcode) {
        this.barcode = barcode;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }
}
DennisVA
  • 2,068
  • 1
  • 25
  • 35
  • Post your item class. Make sure the `get/setImage` methods are implemented correctly. – M. Deinum Dec 05 '13 at 12:48
  • Done, I've posted it under index.jsp – DennisVA Dec 05 '13 at 12:52
  • Why is image protected? And you don't have other `get/setImage` methods which break the abstract implementation? – M. Deinum Dec 05 '13 at 12:57
  • Yeah indeed image has to be private (not that it matters) but what do you mean other get/setImage methods which break the abstract implementation? – DennisVA Dec 05 '13 at 13:01
  • Just as it states. Make sure you don't override `get/setImage` as that might break things. – M. Deinum Dec 05 '13 at 13:02
  • i reqlly don't get it :s why would i want to break the abstraction here, all the subclasses need to have an image.. do you mean getters and setters in receipt like this? public String getImage() { return super.getImage(); } public void setImage(String image) { super.setImage(image); } – DennisVA Dec 05 '13 at 13:51
  • gosh i feel so stupid right now :/ – DennisVA Dec 05 '13 at 13:53
  • Those are the methods exactly. Why would you need to override them in subclasses? That would beat the purpose of a super class and common methods wouldn't it? – M. Deinum Dec 05 '13 at 13:58
  • nothing changes after adding the getter and setter to receipts :/ – DennisVA Dec 05 '13 at 14:50
  • Ehrm no I wasn't mentioning adding them, I assumed you had them and that those weren't delegating to the superclass. – M. Deinum Dec 05 '13 at 14:55

0 Answers0